Rev 6423: (gz) Simplify wrapping of os.urandom done by osutils (Martin Packman) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Jan 4 17:32:02 UTC 2012
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6423 [merge]
revision-id: pqm at pqm.ubuntu.com-20120104173202-fcnu1ngi4nm3yqj5
parent: pqm at pqm.ubuntu.com-20120104170602-ut82c4nbvn63nj3m
parent: martin.packman at canonical.com-20120103171156-avx6c0yz8g37cd77
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2012-01-04 17:32:02 +0000
message:
(gz) Simplify wrapping of os.urandom done by osutils (Martin Packman)
modified:
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2012-01-02 08:22:01 +0000
+++ b/bzrlib/osutils.py 2012-01-03 17:11:56 +0000
@@ -945,19 +945,16 @@
return os.fstat(f.fileno())[stat.ST_SIZE]
-# Define rand_bytes based on platform.
-try:
- # Python 2.4 and later have os.urandom,
- # but it doesn't work on some arches
- os.urandom(1)
- rand_bytes = os.urandom
-except (NotImplementedError, AttributeError):
- # If python doesn't have os.urandom, or it doesn't work,
- # then try to first pull random data from /dev/urandom
+# Alias os.urandom to support platforms (which?) without /dev/urandom and
+# override if it doesn't work. Avoid checking on windows where there is
+# significant initialisation cost that can be avoided for some bzr calls.
+
+rand_bytes = os.urandom
+
+if rand_bytes.__module__ != "nt":
try:
- rand_bytes = file('/dev/urandom', 'rb').read
- # Otherwise, use this hack as a last resort
- except (IOError, OSError):
+ rand_bytes(1)
+ except NotImplementedError:
# not well seeded, but better than nothing
def rand_bytes(n):
import random
More information about the bazaar-commits
mailing list