]> granicus.if.org Git - python/commitdiff
WindowsError.str should display the windows error code,
authorThomas Heller <theller@ctypes.org>
Fri, 27 Oct 2006 18:31:36 +0000 (18:31 +0000)
committerThomas Heller <theller@ctypes.org>
Fri, 27 Oct 2006 18:31:36 +0000 (18:31 +0000)
not the posix error code; with test.
Fixes #1576174.

Will backport to release25-maint.

Lib/test/test_exceptions.py
Misc/NEWS
Objects/exceptions.c

index 585d6fe6cffc47ebd7f746f12e2f322a2db58534..79fcee36cc7b14b781d072400342be8ecd99b009 100644 (file)
@@ -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
 
index ab3bf3f8dbcf615de7c6a11cd75c6bf44d28694d..b9b9883f013e06f44557a98687bca4d7d3a187e8 100644 (file)
--- 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.
 
index c0b813d4a2203eacd474f4713cdcbd28fc31d4ac..0cd819c5a1559396d9aa43ce64615d22578fffbc 100644 (file)
@@ -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);