Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1399a01

Browse files
Issue #22977: Fixed formatting Windows error messages on Wine.
Patch by Martin Panter.
2 parents 4b9df0d + f41f8f9 commit 1399a01

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

Lib/test/test_exceptions.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
import pickle
77
import weakref
88
import errno
9+
import ctypes
910

1011
from test.support import (TESTFN, captured_output, check_impl_detail,
1112
check_warnings, cpython_only, gc_collect, run_unittest,
12-
no_tracing, unlink)
13+
no_tracing, unlink, get_attribute)
1314

1415
class NaiveException(Exception):
1516
def __init__(self, x):
@@ -245,6 +246,13 @@ def test_WindowsError(self):
245246
self.assertEqual(w.strerror, 'foo')
246247
self.assertEqual(w.filename, None)
247248

249+
def test_windows_message(self):
250+
"""Should fill in unknown error code in Windows error message"""
251+
windll = get_attribute(ctypes, "windll")
252+
code = int.from_bytes(b"\xE0msc", "big")
253+
with self.assertRaisesRegex(OSError, hex(code)):
254+
windll.kernel32.RaiseException(code, 0, 0, None)
255+
248256
def testAttributes(self):
249257
# test that exception attributes are happy
250258

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: XXX
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #22977: Fixed formatting Windows error messages on Wine.
14+
Patch by Martin Panter.
15+
1316
Library
1417
-------
1518

Python/errors.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ PyErr_SetFromErrnoWithFilenameObjects(PyObject *exc, PyObject *filenameObject, P
491491
/* Only ever seen this in out-of-mem
492492
situations */
493493
s_buf = NULL;
494-
message = PyUnicode_FromFormat("Windows Error 0x%X", i);
494+
message = PyUnicode_FromFormat("Windows Error 0x%x", i);
495495
} else {
496496
/* remove trailing cr/lf and dots */
497497
while (len > 0 && (s_buf[len-1] <= L' ' || s_buf[len-1] == L'.'))
@@ -600,7 +600,7 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilenameObjects(
600600
NULL); /* no args */
601601
if (len==0) {
602602
/* Only seen this in out of mem situations */
603-
message = PyUnicode_FromFormat("Windows Error 0x%X", err);
603+
message = PyUnicode_FromFormat("Windows Error 0x%x", err);
604604
s_buf = NULL;
605605
} else {
606606
/* remove trailing cr/lf and dots */

0 commit comments

Comments
 (0)