88
99from test import support
1010
11- if sys .platform == 'win32' :
12- VISTA_OR_LATER = (sys .getwindowsversion ().major >= 6 )
13- else :
14- VISTA_OR_LATER = False
15-
1611try :
1712 import ctypes
1813except ImportError :
@@ -841,18 +836,13 @@ def test_encode(self):
841836 ('abc' , 'strict' , b'abc' ),
842837 ('\xe9 \u20ac ' , 'strict' , b'\xc3 \xa9 \xe2 \x82 \xac ' ),
843838 ('\U0010ffff ' , 'strict' , b'\xf4 \x8f \xbf \xbf ' ),
839+ ('\udc80 ' , 'strict' , None ),
840+ ('\udc80 ' , 'ignore' , b'' ),
841+ ('\udc80 ' , 'replace' , b'?' ),
842+ ('\udc80 ' , 'backslashreplace' , b'\\ udc80' ),
843+ ('\udc80 ' , 'namereplace' , b'\\ udc80' ),
844+ ('\udc80 ' , 'surrogatepass' , b'\xed \xb2 \x80 ' ),
844845 ]
845- if VISTA_OR_LATER :
846- tests .extend ((
847- ('\udc80 ' , 'strict' , None ),
848- ('\udc80 ' , 'ignore' , b'' ),
849- ('\udc80 ' , 'replace' , b'?' ),
850- ('\udc80 ' , 'backslashreplace' , b'\\ udc80' ),
851- ('\udc80 ' , 'namereplace' , b'\\ udc80' ),
852- ('\udc80 ' , 'surrogatepass' , b'\xed \xb2 \x80 ' ),
853- ))
854- else :
855- tests .append (('\udc80 ' , 'strict' , b'\xed \xb2 \x80 ' ))
856846 for text , errors , expected in tests :
857847 if expected is not None :
858848 try :
@@ -879,17 +869,10 @@ def test_decode(self):
879869 (b'[\xff ]' , 'ignore' , '[]' ),
880870 (b'[\xff ]' , 'replace' , '[\ufffd ]' ),
881871 (b'[\xff ]' , 'surrogateescape' , '[\udcff ]' ),
872+ (b'[\xed \xb2 \x80 ]' , 'strict' , None ),
873+ (b'[\xed \xb2 \x80 ]' , 'ignore' , '[]' ),
874+ (b'[\xed \xb2 \x80 ]' , 'replace' , '[\ufffd \ufffd \ufffd ]' ),
882875 ]
883- if VISTA_OR_LATER :
884- tests .extend ((
885- (b'[\xed \xb2 \x80 ]' , 'strict' , None ),
886- (b'[\xed \xb2 \x80 ]' , 'ignore' , '[]' ),
887- (b'[\xed \xb2 \x80 ]' , 'replace' , '[\ufffd \ufffd \ufffd ]' ),
888- ))
889- else :
890- tests .extend ((
891- (b'[\xed \xb2 \x80 ]' , 'strict' , '[\udc80 ]' ),
892- ))
893876 for raw , errors , expected in tests :
894877 if expected is not None :
895878 try :
@@ -904,7 +887,6 @@ def test_decode(self):
904887 self .assertRaises (UnicodeDecodeError ,
905888 raw .decode , 'cp65001' , errors )
906889
907- @unittest .skipUnless (VISTA_OR_LATER , 'require Windows Vista or later' )
908890 def test_lone_surrogates (self ):
909891 self .assertRaises (UnicodeEncodeError , "\ud800 " .encode , "cp65001" )
910892 self .assertRaises (UnicodeDecodeError , b"\xed \xa0 \x80 " .decode , "cp65001" )
@@ -921,7 +903,6 @@ def test_lone_surrogates(self):
921903 self .assertEqual ("[\uDC80 ]" .encode ("cp65001" , "replace" ),
922904 b'[?]' )
923905
924- @unittest .skipUnless (VISTA_OR_LATER , 'require Windows Vista or later' )
925906 def test_surrogatepass_handler (self ):
926907 self .assertEqual ("abc\ud800 def" .encode ("cp65001" , "surrogatepass" ),
927908 b"abc\xed \xa0 \x80 def" )
@@ -1951,6 +1932,8 @@ def test_basic(self):
19511932
19521933if hasattr (codecs , "mbcs_encode" ):
19531934 all_unicode_encodings .append ("mbcs" )
1935+ if hasattr (codecs , "oem_encode" ):
1936+ all_unicode_encodings .append ("oem" )
19541937
19551938# The following encoding is not tested, because it's not supposed
19561939# to work:
@@ -3119,11 +3102,10 @@ def test_multibyte_encoding(self):
31193102 (b'\xff \xf4 \x8f \xbf \xbf ' , 'ignore' , '\U0010ffff ' ),
31203103 (b'\xff \xf4 \x8f \xbf \xbf ' , 'replace' , '\ufffd \U0010ffff ' ),
31213104 ))
3122- if VISTA_OR_LATER :
3123- self .check_encode (self .CP_UTF8 , (
3124- ('[\U0010ffff \uDC80 ]' , 'ignore' , b'[\xf4 \x8f \xbf \xbf ]' ),
3125- ('[\U0010ffff \uDC80 ]' , 'replace' , b'[\xf4 \x8f \xbf \xbf ?]' ),
3126- ))
3105+ self .check_encode (self .CP_UTF8 , (
3106+ ('[\U0010ffff \uDC80 ]' , 'ignore' , b'[\xf4 \x8f \xbf \xbf ]' ),
3107+ ('[\U0010ffff \uDC80 ]' , 'replace' , b'[\xf4 \x8f \xbf \xbf ?]' ),
3108+ ))
31273109
31283110 def test_incremental (self ):
31293111 decoded = codecs .code_page_decode (932 , b'\x82 ' , 'strict' , False )
@@ -3144,6 +3126,20 @@ def test_incremental(self):
31443126 False )
31453127 self .assertEqual (decoded , ('abc' , 3 ))
31463128
3129+ def test_mbcs_alias (self ):
3130+ # Check that looking up our 'default' codepage will return
3131+ # mbcs when we don't have a more specific one available
3132+ import _bootlocale
3133+ def _get_fake_codepage (* a ):
3134+ return 'cp123'
3135+ old_getpreferredencoding = _bootlocale .getpreferredencoding
3136+ _bootlocale .getpreferredencoding = _get_fake_codepage
3137+ try :
3138+ codec = codecs .lookup ('cp123' )
3139+ self .assertEqual (codec .name , 'mbcs' )
3140+ finally :
3141+ _bootlocale .getpreferredencoding = old_getpreferredencoding
3142+
31473143
31483144class ASCIITest (unittest .TestCase ):
31493145 def test_encode (self ):
0 commit comments