Lines Matching defs:locale
1 # Tests the attempted automatic coercion of the C locale to a UTF-8 locale
3 import locale
15 # Set the list of ways we expect to be able to ask for the "C" locale
18 # Set our expectation for the default encoding used in the C locale
23 # Set our expectation for the default locale used when none is specified
35 # Linux distros typically alias the POSIX locale directly to the C
36 # locale.
41 # AIX uses iso8859-1 in the C locale, other *nix platforms use ASCII
50 # CPython's own locale handling machinery
59 # * Any platform other than AIX that uses latin-1 in the C locale
60 # * Any Linux distro where POSIX isn't a simple alias for the C locale
61 # * Any Linux distro where the default locale is something other than "C"
69 # order here must much the target locale order in Python/pylifecycle.c
72 # There's no reliable cross-platform way of checking locale alias
74 # is to try them with locale.setlocale(). We do that in a subprocess
75 # in setUpModule() below to avoid altering the locale of the test runner.
77 # If the relevant locale module attributes exist, and we're not on a platform
79 # `locale.nl_langinfo(locale.CODESET)` works, as if it fails, the interpreter
80 # will skip locale coercion for that particular target locale
83 hasattr(locale, "nl_langinfo") and
84 hasattr(locale, "CODESET")
88 cmd_fmt = "import locale; print(locale.setlocale(locale.LC_CTYPE, '{}'))"
91 cmd_fmt += "; import sys; sys.exit(not locale.nl_langinfo(locale.CODESET))"
119 # coercion triggered, or because the C locale was detected
159 "Python runtime initialized with LC_CTYPE=C (a locale with default ASCII "
165 # Details of the CLI locale coercion warning emitted at runtime
167 "Python detected LC_CTYPE=C: LC_CTYPE coerced to {} (set another locale "
168 "or PYTHONCOERCECLOCALE=0 to disable this locale coercion behavior)."
192 # Coercion is expected to use the first available target locale
207 # Base class to check expected locale handling behaviour
215 """Check the C locale handling for the given process environment
244 raise unittest.SkipTest("No C-with-UTF-8 locale available")
248 # Explicitly setting a target locale should give the same behaviour as
249 # is seen when implicitly coercing to that target locale
283 "C locale coercion disabled at build time")
293 """Check the C locale handling for various configurations
324 # Check behaviour for the default locale
334 # locale environment variables are undefined or empty. When
362 # This should coerce to the first available target locale by default
367 # and hence should result in the locale coercion being enabled
379 # The setting "0" should result in the locale coercion being disabled
392 # Setting LC_ALL should render the locale coercion ineffective
398 # And result in a warning about a lack of locale compatibility
407 # skip the test if the LC_CTYPE locale is C or coerced
408 old_loc = locale.setlocale(locale.LC_CTYPE, None)
409 self.addCleanup(locale.setlocale, locale.LC_CTYPE, old_loc)
411 loc = locale.setlocale(locale.LC_CTYPE, "")
412 except locale.Error as e:
415 self.skipTest("test requires LC_CTYPE locale different than C")
417 self.skipTest("coerced LC_CTYPE locale: %s" % loc)
419 # bpo-35336: PYTHONCOERCECLOCALE=1 must not coerce the LC_CTYPE locale
421 code = 'import locale; print(locale.setlocale(locale.LC_CTYPE, None))'