Message165340
Hi,
Lib/random.py has a fallback if os.urandom() returns NotImplementedError
---
from os import urandom as _urandom
...
def seed(self, a=None):
if a is None:
try:
a = long(_hexlify(_urandom(16)), 16)
except NotImplementedError:
import time
a = long(time.time() * 256) # use fractional seconds
---
In 2.6, this is indeed what happens in Lib/os.py where "import urandom from os" gets [2]:
---
if not _exists("urandom"):
def urandom(n):
...
try:
_urandomfd = open("/dev/urandom", O_RDONLY)
except (OSError, IOError):
raise NotImplementedError("/dev/urandom (or equivalent) not found")
---
however, in 2.7, things have shuffled around as a result of issue Issue #13703 and now _PyOS_URandom will return an OSError if it can't find /dev/urandom [3].
This means if you "import random" without "/dev/urandom" available it crashes trying to seed
I'm not sure if this is intentional? One easy solution would be to catch OSError in random.py and fall back then too
[1] http://hg.python.org/cpython/file/70274d53c1dd/Python/random.c#l227
[2] http://hg.python.org/cpython/file/9f8771e09052/Lib/os.py#l746
[3] http://hg.python.org/cpython/file/70274d53c1dd/Lib/random.py#l111 |
|
Date |
User |
Action |
Args |
2012-07-12 22:30:29 | iwienand | set | recipients:
+ iwienand |
2012-07-12 22:30:29 | iwienand | set | messageid: <1342132229.15.0.69254682318.issue15340@psf.upfronthosting.co.za> |
2012-07-12 22:30:28 | iwienand | link | issue15340 messages |
2012-07-12 22:30:28 | iwienand | create | |
|