[pypy-commit] pypy py3k: Raise NotImplementedError only when /dev/urandom is not present. Fixes app-level test.

mjacob pypy.commits at gmail.com
Thu Apr 21 11:23:07 EDT 2016


Author: Manuel Jacob <me at manueljacob.de>
Branch: py3k
Changeset: r83805:b2a4ce692ef4
Date: 2016-04-21 17:24 +0200
http://bitbucket.org/pypy/pypy/changeset/b2a4ce692ef4/

Log:	Raise NotImplementedError only when /dev/urandom is not present.
	Fixes app-level test.

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
@@ -3,6 +3,7 @@
 from __pypy__ import validate_fd
 
 # XXX we need a way to access the current module's globals more directly...
+import errno
 import sys
 if 'posix' in sys.builtin_module_names:
     import posix
@@ -135,5 +136,7 @@
         try:
             with open('/dev/urandom', 'rb', buffering=0) as fd:
                 return fd.read(n)
-        except (OSError, IOError):
-            raise NotImplementedError("/dev/urandom (or equivalent) not found")
+        except OSError as e:
+            if e.errno in (errno.ENOENT, errno.ENXIO, errno.ENODEV, errno.EACCES):
+                raise NotImplementedError("/dev/urandom (or equivalent) not found")
+            raise


More information about the pypy-commit mailing list