12
12
from test .support .script_helper import run_python_until_end
13
13
14
14
15
- # Set the list of ways we expect to be able to ask for the "C" locale
15
+ # Set the list of ways we expect to be able to ask for the "C" locale.
16
+ # 'invalid.ascii' is an invalid LOCALE name and so should get turned in to the
17
+ # default locale, which is traditionally C.
16
18
EXPECTED_C_LOCALE_EQUIVALENTS = ["C" , "invalid.ascii" ]
17
19
18
20
# Set our expectation for the default encoding used in the C locale
21
23
EXPECTED_C_LOCALE_FS_ENCODING = "ascii"
22
24
23
25
# Set our expectation for the default locale used when none is specified
26
+ DEFAULT_LOCALE_IS_C = True
24
27
EXPECT_COERCION_IN_DEFAULT_LOCALE = True
25
28
26
29
TARGET_LOCALES = ["C.UTF-8" , "C.utf8" , "UTF-8" ]
30
33
# Android defaults to using UTF-8 for all system interfaces
31
34
EXPECTED_C_LOCALE_STREAM_ENCODING = "utf-8"
32
35
EXPECTED_C_LOCALE_FS_ENCODING = "utf-8"
33
- elif sys . platform . startswith ( "linux" ):
34
- # Linux distros typically alias the POSIX locale directly to the C
35
- # locale.
36
- # TODO: Once https://bugs.python.org/issue30672 is addressed, we'll be
37
- # able to check this case unconditionally
38
- EXPECTED_C_LOCALE_EQUIVALENTS . append ( "POSIX" )
36
+ elif support . linked_to_musl ( ):
37
+ # MUSL defaults to utf-8 unless the C locale is set explicitly.
38
+ EXPECTED_C_LOCALE_EQUIVALENTS = [ "C" ]
39
+ DEFAULT_LOCALE_IS_C = False
40
+ DEFAULT_ENCODING = 'utf-8'
41
+ EXPECT_COERCION_IN_DEFAULT_LOCALE = False
39
42
elif sys .platform .startswith ("aix" ):
40
43
# AIX uses iso8859-1 in the C locale, other *nix platforms use ASCII
41
44
EXPECTED_C_LOCALE_STREAM_ENCODING = "iso8859-1"
52
55
# VxWorks defaults to using UTF-8 for all system interfaces
53
56
EXPECTED_C_LOCALE_STREAM_ENCODING = "utf-8"
54
57
EXPECTED_C_LOCALE_FS_ENCODING = "utf-8"
58
+ if sys .platform .startswith ("linux" ):
59
+ # Linux recognizes POSIX as a synonym for C. Python will always coerce
60
+ # if the locale is set to POSIX, but not all platforms will use the
61
+ # C locale encodings if POSIX is set, so we'll only test it on linux.
62
+ EXPECTED_C_LOCALE_EQUIVALENTS .append ("POSIX" )
55
63
56
64
# Note that the above expectations are still wrong in some cases, such as:
57
65
# * Windows when PYTHONLEGACYWINDOWSFSENCODING is set
@@ -362,9 +370,14 @@ def _check_c_locale_coercion(self,
362
370
base_var_dict ["PYTHONCOERCECLOCALE" ] = coerce_c_locale
363
371
364
372
# Check behaviour for the default locale
373
+ _fs_encoding = fs_encoding
374
+ _stream_encoding = stream_encoding
375
+ if not DEFAULT_LOCALE_IS_C and 'LC_ALL' not in extra_vars :
376
+ _fs_encoding = _stream_encoding = DEFAULT_ENCODING
365
377
with self .subTest (default_locale = True ,
366
378
PYTHONCOERCECLOCALE = coerce_c_locale ):
367
- if EXPECT_COERCION_IN_DEFAULT_LOCALE :
379
+ if (EXPECT_COERCION_IN_DEFAULT_LOCALE
380
+ or (not DEFAULT_LOCALE_IS_C and 'LC_ALL' in extra_vars )):
368
381
_expected_warnings = expected_warnings
369
382
_coercion_expected = coercion_expected
370
383
else :
@@ -378,8 +391,8 @@ def _check_c_locale_coercion(self,
378
391
_expected_warnings == [CLI_COERCION_WARNING ]):
379
392
_expected_warnings = None
380
393
self ._check_child_encoding_details (base_var_dict ,
381
- fs_encoding ,
382
- stream_encoding ,
394
+ _fs_encoding ,
395
+ _stream_encoding ,
383
396
None ,
384
397
_expected_warnings ,
385
398
_coercion_expected )
0 commit comments