@@ -36,21 +36,25 @@ def check(input, expect):
3636 self .assertEqual (coder (input ), (expect , len (input )))
3737 return check
3838
39- # On small versions of Windows like Windows IoT or Windows Nano Server not all codepages are present
39+ # On small versions of Windows like Windows IoT or Windows Nano Server,
40+ # not all codepages are present
4041def is_code_page_present (cp ):
41- from ctypes import POINTER , WINFUNCTYPE , WinDLL , Structure
42+ from ctypes import POINTER , WINFUNCTYPE , WinDLL
43+ from ctypes .util import struct
4244 from ctypes .wintypes import BOOL , BYTE , WCHAR , UINT , DWORD
4345
4446 MAX_LEADBYTES = 12 # 5 ranges, 2 bytes ea., 0 term.
4547 MAX_DEFAULTCHAR = 2 # single or double byte
4648 MAX_PATH = 260
47- class CPINFOEXW (Structure ):
48- _fields_ = [("MaxCharSize" , UINT ),
49- ("DefaultChar" , BYTE * MAX_DEFAULTCHAR ),
50- ("LeadByte" , BYTE * MAX_LEADBYTES ),
51- ("UnicodeDefaultChar" , WCHAR ),
52- ("CodePage" , UINT ),
53- ("CodePageName" , WCHAR * MAX_PATH )]
49+
50+ @struct
51+ class CPINFOEXW :
52+ MaxCharSize : UINT
53+ DefaultChar : BYTE * MAX_DEFAULTCHAR
54+ LeadByte : BYTE * MAX_LEADBYTES
55+ UnicodeDefaultChar : WCHAR
56+ CodePage : UINT
57+ CodePageName : WCHAR * MAX_PATH
5458
5559 prototype = WINFUNCTYPE (BOOL , UINT , DWORD , POINTER (CPINFOEXW ))
5660 GetCPInfoEx = prototype (("GetCPInfoExW" , WinDLL ("kernel32" )))
0 commit comments