Index: Objects/exceptions.c =================================================================== --- Objects/exceptions.c (revision 63471) +++ Objects/exceptions.c (working copy) @@ -604,13 +604,42 @@ EnvironmentError_str(PyEnvironmentErrorObject *self) { PyObject *rtnval = NULL; + PyObject *errnomod = NULL; + PyObject *errorcode_dict = NULL; + PyObject *errno_str = NULL; + /* Extract the symbolic value for errno and use it if it is available. + Ex: use 'ENOTDIR' instead of 20 */ + if (self->myerrno) { + errnomod = PyImport_ImportModule("errno"); + if (errnomod == NULL) + goto error; + + errorcode_dict = PyObject_GetAttrString(errnomod, "errorcode"); + if (errorcode_dict == NULL) + goto error; + + errno_str = PyDict_GetItem(errorcode_dict, self->myerrno); + Py_DECREF(errorcode_dict); + Py_DECREF(errnomod); + if (errno_str == NULL) + goto error; + Py_INCREF(errno_str); + + /* Gracefully fallback to the errno numeric value. */ + if (0) { + error: + PyErr_Clear(); + errno_str = PyObject_Str(self->myerrno); + } + } + if (self->filename) { PyObject *fmt; PyObject *repr; PyObject *tuple; - fmt = PyString_FromString("[Errno %s] %s: %s"); + fmt = PyString_FromString("[Errno=%s] %s: %s"); if (!fmt) return NULL; @@ -627,8 +656,7 @@ } if (self->myerrno) { - Py_INCREF(self->myerrno); - PyTuple_SET_ITEM(tuple, 0, self->myerrno); + PyTuple_SET_ITEM(tuple, 0, errno_str); } else { Py_INCREF(Py_None); @@ -654,7 +682,7 @@ PyObject *fmt; PyObject *tuple; - fmt = PyString_FromString("[Errno %s] %s"); + fmt = PyString_FromString("[Errno=%s] %s"); if (!fmt) return NULL; @@ -665,8 +693,7 @@ } if (self->myerrno) { - Py_INCREF(self->myerrno); - PyTuple_SET_ITEM(tuple, 0, self->myerrno); + PyTuple_SET_ITEM(tuple, 0, errno_str); } else { Py_INCREF(Py_None);