[Pkg-bazaar-commits] ./bzr/unstable r444: - cope on platforms with no urandom feature
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 08:19:37 UTC 2009
------------------------------------------------------------
revno: 444
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Tue 2005-05-10 18:22:18 +1000
message:
- cope on platforms with no urandom feature
including win32 python2.3
modified:
NEWS
bzrlib/osutils.py
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2005-05-10 08:15:58 +0000
+++ b/NEWS 2005-05-10 08:22:18 +0000
@@ -82,6 +82,13 @@
* New developer commands ``added``, ``modified``.
+
+ PORTABILITY:
+
+ * Cope on Windows on python2.3 by using the weaker random seed.
+ 2.4 is now only recommended.
+
+
bzr-0.0.4 2005-04-22
ENHANCEMENTS:
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2005-05-02 04:41:03 +0000
+++ b/bzrlib/osutils.py 2005-05-10 08:22:18 +0000
@@ -16,7 +16,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-import os, types, re, time, errno
+import os, types, re, time, errno, sys
from stat import S_ISREG, S_ISDIR, S_ISLNK, ST_MODE, ST_SIZE
from errors import bailout, BzrError
@@ -285,10 +285,17 @@
if hasattr(os, 'urandom'): # python 2.4 and later
rand_bytes = os.urandom
+elif sys.platform == 'linux2':
+ rand_bytes = file('/dev/urandom', 'rb').read
else:
- # FIXME: No good on non-Linux
- _rand_file = file('/dev/urandom', 'rb')
- rand_bytes = _rand_file.read
+ # not well seeded, but better than nothing
+ def rand_bytes(n):
+ import random
+ s = ''
+ while n:
+ s += chr(random.randint(0, 255))
+ n -= 1
+ return s
## TODO: We could later have path objects that remember their list
More information about the Pkg-bazaar-commits
mailing list