]> granicus.if.org Git - python/commitdiff
Issue #22977: Fixed formatting Windows error messages on Wine.
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 2 Apr 2015 06:47:27 +0000 (09:47 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 2 Apr 2015 06:47:27 +0000 (09:47 +0300)
Patch by Martin Panter.

Lib/test/test_exceptions.py
Misc/NEWS
Python/errors.c

index b35a5e4a57ace234fdda4a138468526a828ff401..493cd2f83e3d94a9ca0b84b686686adcb115645d 100644 (file)
@@ -6,10 +6,11 @@ import unittest
 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 @@ class ExceptionTests(unittest.TestCase):
             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
 
index 58cdebdee26731d5c19ba69475a618037fd255c4..fd3856393b903486e329f1ea6c29fc87b97a5306 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: tba
 Core and Builtins
 -----------------
 
+- Issue #22977: Fixed formatting Windows error messages on Wine.
+  Patch by Martin Panter.
+
 - Issue #23803: Fixed str.partition() and str.rpartition() when a separator
   is wider then partitioned string.
 
index a980481110b7d88dc8789feaf45d72efaec3c48e..b0ad9aa58b824b40c224524329ff4f43f25dd6d1 100644 (file)
@@ -491,7 +491,7 @@ PyErr_SetFromErrnoWithFilenameObjects(PyObject *exc, PyObject *filenameObject, P
                 /* 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 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilenameObjects(
         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 */