[Python-checkins] python/dist/src/Lib os.py,1.86,1.87

birkenfeld@users.sourceforge.net birkenfeld at users.sourceforge.net
Mon Jul 4 19:16:10 CEST 2005


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27391/Lib

Modified Files:
	os.py 
Log Message:
bug #1177468: don't cache /dev/urandom file descriptor in os.urandom



Index: os.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/os.py,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -d -r1.86 -r1.87
--- os.py	17 Feb 2005 21:23:20 -0000	1.86
+++ os.py	4 Jul 2005 17:16:07 -0000	1.87
@@ -715,22 +715,18 @@
     pass
 
 if not _exists("urandom"):
-    _urandomfd = None
     def urandom(n):
         """urandom(n) -> str
 
         Return a string of n random bytes suitable for cryptographic use.
 
         """
-        global _urandomfd
-        if _urandomfd is None:
-            try:
-                _urandomfd = open("/dev/urandom", O_RDONLY)
-            except:
-                _urandomfd = NotImplementedError
-        if _urandomfd is NotImplementedError:
+        try:
+            _urandomfd = open("/dev/urandom", O_RDONLY)
+        except:
             raise NotImplementedError("/dev/urandom (or equivalent) not found")
         bytes = ""
         while len(bytes) < n:
             bytes += read(_urandomfd, n - len(bytes))
+        close(_urandomfd)
         return bytes



More information about the Python-checkins mailing list