# HG changeset patch # Parent 8b3c609f3f73c90c4e1dd5a5b46b9a9df9d1dbcd diff -r 8b3c609f3f73 Lib/test/test_exceptions.py --- a/Lib/test/test_exceptions.py Sun Jan 11 15:53:02 2015 -0500 +++ b/Lib/test/test_exceptions.py Tue Jan 13 01:42:47 2015 +0000 @@ -6,6 +6,7 @@ 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, @@ -245,6 +246,16 @@ 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""" + try: + windll = ctypes.windll + except AttributeError as err: + self.skipTest(err) + code = int.from_bytes(b"\xE0msc", "big") + self.assertRaisesRegex(OSError, format(code, "x"), + windll.kernel32.RaiseException, code, 0, 0, None) + def testAttributes(self): # test that exception attributes are happy diff -r 8b3c609f3f73 Python/errors.c --- a/Python/errors.c Sun Jan 11 15:53:02 2015 -0500 +++ b/Python/errors.c Tue Jan 13 01:42:47 2015 +0000 @@ -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 */