|
13 | 13 | # Filename used for testing |
14 | 14 | if os.name == 'java': |
15 | 15 | # Jython disallows @ in module names |
16 | | - TESTFN = '$test' |
| 16 | + TESTFN_ASCII = '$test' |
17 | 17 | else: |
18 | | - TESTFN = '@test' |
| 18 | + TESTFN_ASCII = '@test' |
19 | 19 |
|
20 | 20 | # Disambiguate TESTFN for parallel testing, while letting it remain a valid |
21 | 21 | # module name. |
22 | | -TESTFN = "{}_{}_tmp".format(TESTFN, os.getpid()) |
| 22 | +TESTFN_ASCII = "{}_{}_tmp".format(TESTFN_ASCII, os.getpid()) |
23 | 23 |
|
24 | 24 | # TESTFN_UNICODE is a non-ascii filename |
25 | | -TESTFN_UNICODE = TESTFN + "-\xe0\xf2\u0258\u0141\u011f" |
| 25 | +TESTFN_UNICODE = TESTFN_ASCII + "-\xe0\xf2\u0258\u0141\u011f" |
26 | 26 | if sys.platform == 'darwin': |
27 | 27 | # In Mac OS X's VFS API file names are, by definition, canonically |
28 | 28 | # decomposed Unicode, encoded using UTF-8. See QA1173: |
|
39 | 39 | if sys.getwindowsversion().platform >= 2: |
40 | 40 | # Different kinds of characters from various languages to minimize the |
41 | 41 | # probability that the whole name is encodable to MBCS (issue #9819) |
42 | | - TESTFN_UNENCODABLE = TESTFN + "-\u5171\u0141\u2661\u0363\uDC80" |
| 42 | + TESTFN_UNENCODABLE = TESTFN_ASCII + "-\u5171\u0141\u2661\u0363\uDC80" |
43 | 43 | try: |
44 | 44 | TESTFN_UNENCODABLE.encode(sys.getfilesystemencoding()) |
45 | 45 | except UnicodeEncodeError: |
|
56 | 56 | b'\xff'.decode(sys.getfilesystemencoding()) |
57 | 57 | except UnicodeDecodeError: |
58 | 58 | # 0xff will be encoded using the surrogate character u+DCFF |
59 | | - TESTFN_UNENCODABLE = TESTFN \ |
| 59 | + TESTFN_UNENCODABLE = TESTFN_ASCII \ |
60 | 60 | + b'-\xff'.decode(sys.getfilesystemencoding(), 'surrogateescape') |
61 | 61 | else: |
62 | 62 | # File system encoding (eg. ISO-8859-* encodings) can encode |
63 | 63 | # the byte 0xff. Skip some unicode filename tests. |
64 | 64 | pass |
65 | 65 |
|
66 | 66 | # FS_NONASCII: non-ASCII character encodable by os.fsencode(), |
67 | | -# or None if there is no such character. |
68 | | -FS_NONASCII = None |
| 67 | +# or an empty string if there is no such character. |
| 68 | +FS_NONASCII = '' |
69 | 69 | for character in ( |
70 | 70 | # First try printable and common characters to have a readable filename. |
71 | 71 | # For each character, the encoding list are just example of encodings able |
|
141 | 141 | try: |
142 | 142 | name.decode(sys.getfilesystemencoding()) |
143 | 143 | except UnicodeDecodeError: |
144 | | - TESTFN_UNDECODABLE = os.fsencode(TESTFN) + name |
| 144 | + TESTFN_UNDECODABLE = os.fsencode(TESTFN_ASCII) + name |
145 | 145 | break |
146 | 146 |
|
147 | 147 | if FS_NONASCII: |
148 | | - TESTFN_NONASCII = TESTFN + '-' + FS_NONASCII |
| 148 | + TESTFN_NONASCII = TESTFN_ASCII + FS_NONASCII |
149 | 149 | else: |
150 | 150 | TESTFN_NONASCII = None |
| 151 | +TESTFN = TESTFN_NONASCII or TESTFN_ASCII |
151 | 152 |
|
152 | 153 |
|
153 | 154 | def make_bad_fd(): |
|
0 commit comments