[Python-checkins] cpython (merge 3.4 -> default): Issue #22977: Fixed formatting Windows error messages on Wine.

serhiy.storchaka python-checkins at python.org
Thu Apr 2 08:50:31 CEST 2015


https://hg.python.org/cpython/rev/cf0cac11813d
changeset:   95368:cf0cac11813d
parent:      95366:c27585e43e50
parent:      95367:7907746baa0d
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Thu Apr 02 09:50:06 2015 +0300
summary:
  Issue #22977: Fixed formatting Windows error messages on Wine.
Patch by Martin Panter.

files:
  Lib/test/test_exceptions.py |  10 +++++++++-
  Misc/NEWS                   |   3 +++
  Python/errors.c             |   4 ++--
  3 files changed, 14 insertions(+), 3 deletions(-)


diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -6,10 +6,11 @@
 import pickle
 import weakref
 import errno
+import ctypes
 
 from test.support import (TESTFN, captured_output, check_impl_detail,
                           check_warnings, cpython_only, gc_collect, run_unittest,
-                          no_tracing, unlink)
+                          no_tracing, unlink, get_attribute)
 
 class NaiveException(Exception):
     def __init__(self, x):
@@ -245,6 +246,13 @@
             self.assertEqual(w.strerror, 'foo')
             self.assertEqual(w.filename, None)
 
+    def test_windows_message(self):
+        """Should fill in unknown error code in Windows error message"""
+        windll = get_attribute(ctypes, "windll")
+        code = int.from_bytes(b"\xE0msc", "big")
+        with self.assertRaisesRegex(OSError, hex(code)):
+            windll.kernel32.RaiseException(code, 0, 0, None)
+
     def testAttributes(self):
         # test that exception attributes are happy
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #22977: Fixed formatting Windows error messages on Wine.
+  Patch by Martin Panter.
+
 Library
 -------
 
diff --git a/Python/errors.c b/Python/errors.c
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -491,7 +491,7 @@
                 /* Only ever seen this in out-of-mem
                    situations */
                 s_buf = NULL;
-                message = PyUnicode_FromFormat("Windows Error 0x%X", i);
+                message = PyUnicode_FromFormat("Windows Error 0x%x", i);
             } else {
                 /* remove trailing cr/lf and dots */
                 while (len > 0 && (s_buf[len-1] <= L' ' || s_buf[len-1] == L'.'))
@@ -600,7 +600,7 @@
         NULL);          /* no args */
     if (len==0) {
         /* Only seen this in out of mem situations */
-        message = PyUnicode_FromFormat("Windows Error 0x%X", err);
+        message = PyUnicode_FromFormat("Windows Error 0x%x", err);
         s_buf = NULL;
     } else {
         /* remove trailing cr/lf and dots */

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list