summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2006-10-27 18:31:36 (GMT)
committerThomas Heller <theller@ctypes.org>2006-10-27 18:31:36 (GMT)
commitdf08f0b9a0a3de196336b6b4f158fa2325d08479 (patch)
tree5a8ec68d0f1bb633c58939c64e51381d991f66f5
parent9627ce116f36ee3d68adcc2cbb8450693198212b (diff)
downloadcpython-df08f0b9a0a3de196336b6b4f158fa2325d08479.zip
cpython-df08f0b9a0a3de196336b6b4f158fa2325d08479.tar.gz
cpython-df08f0b9a0a3de196336b6b4f158fa2325d08479.tar.bz2
WindowsError.str should display the windows error code,
not the posix error code; with test. Fixes #1576174. Will backport to release25-maint.
-rw-r--r--Lib/test/test_exceptions.py13
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/exceptions.c14
3 files changed, 23 insertions, 7 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 585d6fe..79fcee3 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -183,6 +183,19 @@ class ExceptionTests(unittest.TestCase):
test_capi1()
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):
# test that exception attributes are happy
diff --git a/Misc/NEWS b/Misc/NEWS
index ab3bf3f..b9b9883 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 1?
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, issue warnings
if the assigned value for structmember fields gets truncated.
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index c0b813d..0cd819c 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -828,9 +828,9 @@ WindowsError_str(PyWindowsErrorObject *self)
return NULL;
}
- if (self->myerrno) {
- Py_INCREF(self->myerrno);
- PyTuple_SET_ITEM(tuple, 0, self->myerrno);
+ if (self->winerror) {
+ Py_INCREF(self->winerror);
+ PyTuple_SET_ITEM(tuple, 0, self->winerror);
}
else {
Py_INCREF(Py_None);
@@ -852,7 +852,7 @@ WindowsError_str(PyWindowsErrorObject *self)
Py_DECREF(fmt);
Py_DECREF(tuple);
}
- else if (self->myerrno && self->strerror) {
+ else if (self->winerror && self->strerror) {
PyObject *fmt;
PyObject *tuple;
@@ -866,9 +866,9 @@ WindowsError_str(PyWindowsErrorObject *self)
return NULL;
}
- if (self->myerrno) {
- Py_INCREF(self->myerrno);
- PyTuple_SET_ITEM(tuple, 0, self->myerrno);
+ if (self->winerror) {
+ Py_INCREF(self->winerror);
+ PyTuple_SET_ITEM(tuple, 0, self->winerror);
}
else {
Py_INCREF(Py_None);