WindowsError.str should display the windows error code,

not the posix error code; with test.
Fixes #1576174.

Backported from trunk, revision 52485.
This commit is contained in:
Thomas Heller 2006-10-27 18:47:29 +00:00
parent ff9e7abac8
commit a0a50feea8
3 changed files with 23 additions and 7 deletions

View File

@ -183,6 +183,19 @@ class ExceptionTests(unittest.TestCase):
test_capi1() test_capi1()
test_capi2() test_capi2()
def test_WindowsError(self):
try:
WindowsError
except NameError:
pass
else:
self.failUnlessEqual(str(WindowsError(1001)),
"1001")
self.failUnlessEqual(str(WindowsError(1001, "message")),
"[Error 1001] message")
self.failUnlessEqual(WindowsError(1001, "message").errno, 22)
self.failUnlessEqual(WindowsError(1001, "message").winerror, 1001)
def testAttributes(self): def testAttributes(self):
# test that exception attributes are happy # test that exception attributes are happy

View File

@ -12,6 +12,9 @@ What's New in Python 2.5.1c1?
Core and builtins Core and builtins
----------------- -----------------
- Bug #1576174: WindowsError now displays the windows error code
again, no longer the posix error code.
- Patch #1549049: Support long values in structmember. - Patch #1549049: Support long values in structmember.
- Bug #1542016: make sys.callstats() match its docstring and return an - Bug #1542016: make sys.callstats() match its docstring and return an

View File

@ -828,9 +828,9 @@ WindowsError_str(PyWindowsErrorObject *self)
return NULL; return NULL;
} }
if (self->myerrno) { if (self->winerror) {
Py_INCREF(self->myerrno); Py_INCREF(self->winerror);
PyTuple_SET_ITEM(tuple, 0, self->myerrno); PyTuple_SET_ITEM(tuple, 0, self->winerror);
} }
else { else {
Py_INCREF(Py_None); Py_INCREF(Py_None);
@ -852,7 +852,7 @@ WindowsError_str(PyWindowsErrorObject *self)
Py_DECREF(fmt); Py_DECREF(fmt);
Py_DECREF(tuple); Py_DECREF(tuple);
} }
else if (self->myerrno && self->strerror) { else if (self->winerror && self->strerror) {
PyObject *fmt; PyObject *fmt;
PyObject *tuple; PyObject *tuple;
@ -866,9 +866,9 @@ WindowsError_str(PyWindowsErrorObject *self)
return NULL; return NULL;
} }
if (self->myerrno) { if (self->winerror) {
Py_INCREF(self->myerrno); Py_INCREF(self->winerror);
PyTuple_SET_ITEM(tuple, 0, self->myerrno); PyTuple_SET_ITEM(tuple, 0, self->winerror);
} }
else { else {
Py_INCREF(Py_None); Py_INCREF(Py_None);