[Python-checkins] python/dist/src/Lib os.py,1.77,1.78

loewis at users.sourceforge.net loewis at users.sourceforge.net
Sun Aug 29 17:46:36 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13928/Lib
Modified Files:
	os.py 
Log Message:
Patch #934711: Expose platform-specific entropy.
Index: os.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/os.py,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- os.py	8 Jun 2004 08:29:32 -0000	1.77
+++ os.py	29 Aug 2004 15:46:34 -0000	1.78
@@ -656,3 +656,24 @@
 _make_statvfs_result)
 except NameError: # statvfs_result may not exist
 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 not _urandomfd:
+ try:
+ _urandomfd = open("/dev/urandom", O_RDONLY) 
+ except:
+ _urandomfd = NotImplementedError
+ if _urandomfd is NotImplementedError:
+ raise NotImplementedError("/dev/urandom (or equivalent) not found")
+ bytes = ""
+ while len(bytes) < n:
+ bytes += read(_urandomfd, n - len(bytes))
+ return bytes


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /