]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-133711: Log Windows OEM code page in test.pythoninfo (#134840)
authorVictor Stinner <vstinner@python.org>
Wed, 28 May 2025 15:41:11 +0000 (17:41 +0200)
committerGitHub <noreply@github.com>
Wed, 28 May 2025 15:41:11 +0000 (17:41 +0200)
Add _winapi.GetOEMCP() function.

Lib/test/pythoninfo.py
Modules/_winapi.c
Modules/clinic/_winapi.c.h

index e1830f2e6eba977e53ebbfc5e9600b9f0a95e32f..80a262c18a5ad22c27ff458accb4404d3eadf5ab 100644 (file)
@@ -920,10 +920,17 @@ def collect_windows(info_add):
 
     try:
         import _winapi
-        dll_path = _winapi.GetModuleFileName(sys.dllhandle)
-        info_add('windows.dll_path', dll_path)
-    except (ImportError, AttributeError):
+    except ImportError:
         pass
+    else:
+        try:
+            dll_path = _winapi.GetModuleFileName(sys.dllhandle)
+            info_add('windows.dll_path', dll_path)
+        except AttributeError:
+            pass
+
+        call_func(info_add, 'windows.ansi_code_page', _winapi, 'GetACP')
+        call_func(info_add, 'windows.oem_code_page', _winapi, 'GetOEMCP')
 
     # windows.version_caption: "wmic os get Caption,Version /value" command
     import subprocess
index 044505fab6216ca53cf492b0cfcb7a4a028e2a15..b4cfbebcb1bb5e2573a89eedf8346eefdf23ff27 100644 (file)
@@ -2747,6 +2747,19 @@ _winapi_GetACP_impl(PyObject *module)
     return PyLong_FromUnsignedLong(GetACP());
 }
 
+/*[clinic input]
+_winapi.GetOEMCP
+
+Get the current Windows ANSI code page identifier.
+[clinic start generated code]*/
+
+static PyObject *
+_winapi_GetOEMCP_impl(PyObject *module)
+/*[clinic end generated code: output=4def5b07a8be1b3b input=e8caf4353a28e28e]*/
+{
+    return PyLong_FromUnsignedLong(GetOEMCP());
+}
+
 /*[clinic input]
 _winapi.GetFileType -> DWORD
 
@@ -3007,6 +3020,7 @@ static PyMethodDef winapi_functions[] = {
     _WINAPI_WAITFORSINGLEOBJECT_METHODDEF
     _WINAPI_WRITEFILE_METHODDEF
     _WINAPI_GETACP_METHODDEF
+    _WINAPI_GETOEMCP_METHODDEF
     _WINAPI_GETFILETYPE_METHODDEF
     _WINAPI__MIMETYPES_READ_WINDOWS_REGISTRY_METHODDEF
     _WINAPI_NEEDCURRENTDIRECTORYFOREXEPATH_METHODDEF
index b0fc1f1a89b7600434ae09d01963bdaa073f2bbd..bd685e75d9344fe47d1bae8b88b3d35b1ce29111 100644 (file)
@@ -1933,6 +1933,24 @@ _winapi_GetACP(PyObject *module, PyObject *Py_UNUSED(ignored))
     return _winapi_GetACP_impl(module);
 }
 
+PyDoc_STRVAR(_winapi_GetOEMCP__doc__,
+"GetOEMCP($module, /)\n"
+"--\n"
+"\n"
+"Get the current Windows ANSI code page identifier.");
+
+#define _WINAPI_GETOEMCP_METHODDEF    \
+    {"GetOEMCP", (PyCFunction)_winapi_GetOEMCP, METH_NOARGS, _winapi_GetOEMCP__doc__},
+
+static PyObject *
+_winapi_GetOEMCP_impl(PyObject *module);
+
+static PyObject *
+_winapi_GetOEMCP(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+    return _winapi_GetOEMCP_impl(module);
+}
+
 PyDoc_STRVAR(_winapi_GetFileType__doc__,
 "GetFileType($module, /, handle)\n"
 "--\n"
@@ -2169,4 +2187,4 @@ exit:
 #ifndef _WINAPI_GETSHORTPATHNAME_METHODDEF
     #define _WINAPI_GETSHORTPATHNAME_METHODDEF
 #endif /* !defined(_WINAPI_GETSHORTPATHNAME_METHODDEF) */
-/*[clinic end generated code: output=ede63eaaf63aa7e6 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=4581fd481c3c6293 input=a9049054013a1b77]*/