@@ -27,6 +27,26 @@ def check(input, expect):
2727        self .assertEqual (coder (input ), (expect , len (input )))
2828    return  check 
2929
30+ # On small versions of Windows like Windows IoT or Windows Nano Server not all codepages are present 
31+ def  is_code_page_present (cp ):
32+     from  ctypes  import  POINTER , WINFUNCTYPE , windll , WinError , Structure , WinDLL 
33+     from  ctypes .wintypes  import  BOOL , UINT , BYTE , WCHAR , UINT , DWORD 
34+ 
35+     MAX_LEADBYTES  =  12   # 5 ranges, 2 bytes ea., 0 term. 
36+     MAX_DEFAULTCHAR  =  2  # single or double byte 
37+     MAX_PATH  =  260 
38+     class  CPINFOEXW (ctypes .Structure ):
39+         _fields_  =  [("MaxCharSize" , UINT ),
40+                     ("DefaultChar" , BYTE * MAX_DEFAULTCHAR ),
41+                     ("LeadByte" , BYTE * MAX_LEADBYTES ),
42+                     ("UnicodeDefaultChar" , WCHAR ),
43+                     ("CodePage" , UINT ),
44+                     ("CodePageName" , WCHAR * MAX_PATH )]
45+ 
46+     prototype  =  WINFUNCTYPE (BOOL , UINT , DWORD , POINTER (CPINFOEXW ))
47+     GetCPInfoEx  =  prototype (("GetCPInfoExW" , WinDLL ("kernel32" )))
48+     info  =  CPINFOEXW ()
49+     return  GetCPInfoEx (cp , 0 , info )
3050
3151class  Queue (object ):
3252    """ 
@@ -3078,9 +3098,19 @@ def test_multibyte_encoding(self):
30783098    def  test_code_page_decode_flags (self ):
30793099        # Issue #36312: For some code pages (e.g. UTF-7) flags for 
30803100        # MultiByteToWideChar() must be set to 0. 
3101+         if  support .verbose :
3102+             sys .stdout .write ('\n ' )
30813103        for  cp  in  (50220 , 50221 , 50222 , 50225 , 50227 , 50229 ,
30823104                   * range (57002 , 57011 + 1 ), 65000 ):
3083-             self .assertEqual (codecs .code_page_decode (cp , b'abc' ), ('abc' , 3 ))
3105+             # On small versions of Windows like Windows IoT 
3106+             # not all codepages are present. 
3107+             # A missing codepage causes an OSError exception 
3108+             # so check for the codepage before decoding 
3109+             if  is_code_page_present (cp ):
3110+                 self .assertEqual (codecs .code_page_decode (cp , b'abc' ), ('abc' , 3 ), f'cp{ cp }  ' )
3111+             else :
3112+                 if  support .verbose :
3113+                     print (f"  skipping cp={ cp }  " )
30843114        self .assertEqual (codecs .code_page_decode (42 , b'abc' ),
30853115                         ('\uf061 \uf062 \uf063 ' , 3 ))
30863116
0 commit comments