diff Python/random.c @ 85199:fe949918616c

Issue #18756: Improve error reporting in os.urandom() when the failure is due to something else than /dev/urandom not existing.
author Antoine Pitrou <solipsis@pitrou.net>
date Fri, 16 Aug 2013 20:49:32 +0200
parents e52df05b496a 193bcc12575d
children ef889c3d5dc6
line wrap: on
line diff
--- a/Python/random.c	Fri Aug 16 21:33:27 2013 +0300
+++ b/Python/random.c	Fri Aug 16 20:49:32 2013 +0200
@@ -138,8 +138,12 @@
     Py_END_ALLOW_THREADS
     if (fd < 0)
     {
-        PyErr_SetString(PyExc_NotImplementedError,
-                        "/dev/urandom (or equivalent) not found");
+        if (errno == ENOENT || errno == ENXIO ||
+            errno == ENODEV || errno == EACCES)
+            PyErr_SetString(PyExc_NotImplementedError,
+                            "/dev/urandom (or equivalent) not found");
+        else
+            PyErr_SetFromErrno(PyExc_OSError);
         return -1;
     }