mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-29240, bpo-32030: Py_Main() re-reads config if encoding changes (#4899)
bpo-29240, bpo-32030: If the encoding change (C locale coerced or UTF-8 Mode changed), Py_Main() now reads again the configuration with the new encoding. Changes: * Add _Py_UnixMain() called by main(). * Rename pymain_free_pymain() to pymain_clear_pymain(), it can now be called multipled times. * Rename pymain_parse_cmdline_envvars() to pymain_read_conf(). * Py_Main() now clears orig_argc and orig_argv at exit. * Remove argv_copy2, Py_Main() doesn't modify argv anymore. There is no need anymore to get two copies of the wchar_t** argv. * _PyCoreConfig: add coerce_c_locale and coerce_c_locale_warn. * Py_UTF8Mode is now initialized to -1. * Locale coercion (PEP 538) now respects -I and -E options.
This commit is contained in:
parent
e796b2fe26
commit
9454060e84
12 changed files with 325 additions and 215 deletions
|
@ -65,7 +65,7 @@ def _set_locale_in_subprocess(locale_name):
|
|||
# If there's no valid CODESET, we expect coercion to be skipped
|
||||
cmd_fmt += "; import sys; sys.exit(not locale.nl_langinfo(locale.CODESET))"
|
||||
cmd = cmd_fmt.format(locale_name)
|
||||
result, py_cmd = run_python_until_end("-c", cmd, __isolated=True)
|
||||
result, py_cmd = run_python_until_end("-c", cmd, PYTHONCOERCECLOCALE='')
|
||||
return result.rc == 0
|
||||
|
||||
|
||||
|
@ -131,7 +131,6 @@ class EncodingDetails(_EncodingDetails):
|
|||
"""
|
||||
result, py_cmd = run_python_until_end(
|
||||
"-X", "utf8=0", "-c", cls.CHILD_PROCESS_SCRIPT,
|
||||
__isolated=True,
|
||||
**env_vars
|
||||
)
|
||||
if not result.rc == 0:
|
||||
|
@ -236,6 +235,7 @@ class LocaleConfigurationTests(_LocaleHandlingTestCase):
|
|||
"LANG": "",
|
||||
"LC_CTYPE": "",
|
||||
"LC_ALL": "",
|
||||
"PYTHONCOERCECLOCALE": "",
|
||||
}
|
||||
for env_var in ("LANG", "LC_CTYPE"):
|
||||
for locale_to_set in AVAILABLE_TARGETS:
|
||||
|
@ -294,6 +294,7 @@ class LocaleCoercionTests(_LocaleHandlingTestCase):
|
|||
"LANG": "",
|
||||
"LC_CTYPE": "",
|
||||
"LC_ALL": "",
|
||||
"PYTHONCOERCECLOCALE": "",
|
||||
}
|
||||
base_var_dict.update(extra_vars)
|
||||
for env_var in ("LANG", "LC_CTYPE"):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue