Issue #18756: Improve error reporting in os.urandom() when the failure is due to something else than /dev/urandom not existing.

This commit is contained in:
Antoine Pitrou 2013-08-16 20:44:38 +02:00
parent 802bf8aea1
commit ec34ab5010
3 changed files with 30 additions and 2 deletions

View file

@ -165,8 +165,12 @@ dev_urandom_python(char *buffer, Py_ssize_t size)
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;
}