Index: Objects/exceptions.c =================================================================== --- Objects/exceptions.c (revision 63365) +++ Objects/exceptions.c (working copy) @@ -604,13 +604,35 @@ EnvironmentError_str(PyEnvironmentErrorObject *self) { PyObject *rtnval = NULL; + PyObject *errnomod = NULL; + PyObject *errorcode_dict = NULL; + PyObject *errno_str = NULL; + PyObject *printed_errno = NULL; + /* Extract the symbolic value for errno. + Ex: use 'ENOTDIR' instead of 20 */ + if (self->myerrno) { + errnomod = PyImport_ImportModule("errno"); + if (errnomod == NULL) + Py_FatalError("Can't import errno module."); + + errorcode_dict = PyObject_GetAttrString(errnomod, "errorcode"); + if (errorcode_dict == NULL) + Py_FatalError("Can't access errorcode dict."); + + errno_str = PyDict_GetItem(errorcode_dict, self->myerrno); + + /* gracefully fall back to numeric if no symbolic expansion is + available */ + printed_errno = errno_str ? errno_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 +649,8 @@ } if (self->myerrno) { - Py_INCREF(self->myerrno); - PyTuple_SET_ITEM(tuple, 0, self->myerrno); + Py_INCREF(printed_errno); + PyTuple_SET_ITEM(tuple, 0, printed_errno); } else { Py_INCREF(Py_None); @@ -654,7 +676,7 @@ PyObject *fmt; PyObject *tuple; - fmt = PyString_FromString("[Errno %s] %s"); + fmt = PyString_FromString("[Errno=%s] %s"); if (!fmt) return NULL; @@ -665,8 +687,8 @@ } if (self->myerrno) { - Py_INCREF(self->myerrno); - PyTuple_SET_ITEM(tuple, 0, self->myerrno); + Py_INCREF(printed_errno); + PyTuple_SET_ITEM(tuple, 0, printed_errno); } else { Py_INCREF(Py_None); @@ -688,7 +710,9 @@ } else rtnval = BaseException_str((PyBaseExceptionObject *)self); - + + Py_XDECREF(errnomod); + Py_XDECREF(errorcode_dict); return rtnval; }