[pypy-commit] pypy default: CPython raises NotImplementedError if /dev/urandom cannot be found.

arigo pypy.commits at gmail.com
Mon Aug 26 16:32:09 EDT 2019


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r97285:a6c1ae01424e
Date: 2019-08-26 22:31 +0200
http://bitbucket.org/pypy/pypy/changeset/a6c1ae01424e/

Log:	CPython raises NotImplementedError if /dev/urandom cannot be found.
	To maximize compatibility, we should also raise NotImplementedError
	and not OSError (although CPython also raises OSError in case it
	could open /dev/urandom but there are further problems).

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
@@ -1351,7 +1351,12 @@
         _sigcheck.space = space
         return space.newbytes(rurandom.urandom(context, n, _signal_checker))
     except OSError as e:
-        raise wrap_oserror(space, e)
+        # CPython raises NotImplementedError if /dev/urandom cannot be found.
+        # To maximize compatibility, we should also raise NotImplementedError
+        # and not OSError (although CPython also raises OSError in case it
+        # could open /dev/urandom but there are further problems).
+        raise wrap_oserror(space, e,
+            w_exception_class=space.w_NotImplementedError)
 
 def ctermid(space):
     """ctermid() -> string


More information about the pypy-commit mailing list