Author: Armin Rigo <[email protected]>
Branch: py3.6-sandbox-2
Changeset: r97301:3a1756763860
Date: 2019-08-27 11:56 +0200
http://bitbucket.org/pypy/pypy/changeset/3a1756763860/
Log: Found out there are two versions of os.urandom() around, and figured
out when one is shadowed by the other
diff --git a/pypy/module/_random/interp_random.py
b/pypy/module/_random/interp_random.py
--- a/pypy/module/_random/interp_random.py
+++ b/pypy/module/_random/interp_random.py
@@ -30,7 +30,8 @@
try:
w_n = interp_posix.urandom(space, 8)
except OperationError as e:
- if not e.match(space, space.w_OSError):
+ if not (e.match(space, space.w_NotImplementedError) or
+ e.match(space, space.w_OSError)):
raise
w_n = space.newint(int(time.time() * 256))
if space.isinstance_w(w_n, space.w_int):
diff --git a/pypy/module/posix/app_posix.py b/pypy/module/posix/app_posix.py
--- a/pypy/module/posix/app_posix.py
+++ b/pypy/module/posix/app_posix.py
@@ -156,6 +156,9 @@
Return a string of n random bytes suitable for cryptographic use.
"""
+ # NOTE: we also have interp_posix.urandom(), which we use on Windows.
+ # XXX unsure we shouldn't be removing the code below, though, because
+ # the interp version seems more complete
try:
with open('/dev/urandom', 'rb', buffering=0) as fd:
return fd.read(n)
diff --git a/pypy/module/posix/interp_posix.py
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -2217,6 +2217,10 @@
Return a string of 'size' random bytes suitable for cryptographic use.
"""
+ # NOTE: this is not used for 'os.urandom' on POSIX; instead,
+ # app_posix.urandom() is. However, module/_random/ actually
+ # calls this code directly. XXX Unsure the version in app_posix
+ # is needed (or complete enough) nowadays.
context = get(space).random_context
try:
# urandom() takes a final argument that should be a regular function,
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit