@@ -382,29 +382,38 @@ def fcmp(x, y): # fuzzy comparison function
382382# file system encoding, but *not* with the default (ascii) encoding
383383TESTFN_UNICODE = TESTFN + "-\xe0 \xf2 "
384384TESTFN_ENCODING = sys .getfilesystemencoding ()
385- # TESTFN_UNICODE_UNENCODEABLE is a filename that should *not* be
386- # able to be encoded by *either* the default or filesystem encoding.
387- # This test really only makes sense on Windows NT platforms
388- # which have special Unicode support in posixmodule.
389- if (not hasattr (sys , "getwindowsversion" ) or
390- sys .getwindowsversion ()[3 ] < 2 ): # 0=win32s or 1=9x/ME
391- TESTFN_UNICODE_UNENCODEABLE = None
385+
386+ # TESTFN_UNENCODEABLE is a filename (str type) that should *not* be able to be
387+ # encoded by the filesystem encoding (in strict mode). It can be None if we
388+ # cannot generate such filename.
389+ if os .name in ('nt' , 'ce' ):
390+ if sys .getwindowsversion ().platform < 2 :
391+ # win32s (0) or Windows 9x/ME (1)
392+ TESTFN_UNENCODEABLE = None
393+ else :
394+ # Japanese characters (I think - from bug 846133)
395+ TESTFN_UNENCODEABLE = TESTFN + "-\u5171 \u6709 \u3055 \u308c \u308b "
396+ try :
397+ TESTFN_UNENCODEABLE .encode (TESTFN_ENCODING )
398+ except UnicodeEncodeError :
399+ pass
400+ else :
401+ print ('WARNING: The filename %r CAN be encoded by the filesystem encoding (%s). '
402+ 'Unicode filename tests may not be effective'
403+ % (TESTFN_UNENCODEABLE , TESTFN_ENCODING ))
404+ TESTFN_UNENCODEABLE = None
392405else :
393- # Japanese characters (I think - from bug 846133)
394- TESTFN_UNICODE_UNENCODEABLE = TESTFN + "-\u5171 \u6709 \u3055 \u308c \u308b "
395406 try :
396- # XXX - Note - should be using TESTFN_ENCODING here - but for
397- # Windows, "mbcs" currently always operates as if in
398- # errors=ignore' mode - hence we get '?' characters rather than
399- # the exception. 'Latin1' operates as we expect - ie, fails.
400- # See [ 850997 ] mbcs encoding ignores errors
401- TESTFN_UNICODE_UNENCODEABLE .encode ("Latin1" )
402- except UnicodeEncodeError :
403- pass
407+ # ascii and utf-8 cannot encode the byte 0xff
408+ b'\xff ' .decode (TESTFN_ENCODING )
409+ except UnicodeDecodeError :
410+ # 0xff will be encoded using the surrogate character u+DCFF
411+ TESTFN_UNENCODEABLE = TESTFN_UNICODE \
412+ + b'-\xff ' .decode (TESTFN_ENCODING , 'surrogateescape' )
404413 else :
405- print ( 'WARNING: The filename %r CAN be encoded by the filesystem. '
406- 'Unicode filename tests may not be effective'
407- % TESTFN_UNICODE_UNENCODEABLE )
414+ # File system encoding (eg. ISO-8859-* encodings) can encode
415+ # the byte 0xff. Skip some unicode filename tests.
416+ TESTFN_UNENCODEABLE = None
408417
409418# Save the initial cwd
410419SAVEDCWD = os .getcwd ()
0 commit comments