summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-09-19 21:56:36 (GMT)
committerGitHub <noreply@github.com>2018-09-19 21:56:36 (GMT)
commit06e7608207daab9fb82d13ccf2d3664535442f11 (patch)
tree690da78834ebfbe2f3f0316972bfcbde97a67a8f /Lib
parent76531e2e82319a487d659bc469441bd4b8251608 (diff)
downloadcpython-06e7608207daab9fb82d13ccf2d3664535442f11.zip
cpython-06e7608207daab9fb82d13ccf2d3664535442f11.tar.gz
cpython-06e7608207daab9fb82d13ccf2d3664535442f11.tar.bz2
Revert "bpo-34589: Add -X coerce_c_locale command line option (GH-9378)" (GH-9430)
* Revert "bpo-34589: Add -X coerce_c_locale command line option (GH-9378)" This reverts commit dbdee0073cf0b88fe541980ace1f650900f455cc. * Revert "bpo-34589: C locale coercion off by default (GH-9073)" This reverts commit 7a0791b6992d420dc52536257f2f093851ed7215. * Revert "bpo-34589: Make _PyCoreConfig.coerce_c_locale private (GH-9371)" This reverts commit 188ebfa475a6f6aa2d0ea14ca8e1fbe7865b6d27.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_c_locale_coercion.py55
-rw-r--r--Lib/test/test_cmd_line.py7
-rw-r--r--Lib/test/test_embed.py8
-rw-r--r--Lib/test/test_sys.py8
-rw-r--r--Lib/test/test_utf8_mode.py3
5 files changed, 22 insertions, 59 deletions
diff --git a/Lib/test/test_c_locale_coercion.py b/Lib/test/test_c_locale_coercion.py
index f62208a..1db293b 100644
--- a/Lib/test/test_c_locale_coercion.py
+++ b/Lib/test/test_c_locale_coercion.py
@@ -139,7 +139,7 @@ class EncodingDetails(_EncodingDetails):
return data
@classmethod
- def get_child_details(cls, env_vars, xoption=None):
+ def get_child_details(cls, env_vars):
"""Retrieves fsencoding and standard stream details from a child process
Returns (encoding_details, stderr_lines):
@@ -150,11 +150,10 @@ class EncodingDetails(_EncodingDetails):
The child is run in isolated mode if the current interpreter supports
that.
"""
- args = []
- if xoption:
- args.extend(("-X", f"coerce_c_locale={xoption}"))
- args.extend(("-X", "utf8=0", "-c", cls.CHILD_PROCESS_SCRIPT))
- result, py_cmd = run_python_until_end(*args, **env_vars)
+ result, py_cmd = run_python_until_end(
+ "-X", "utf8=0", "-c", cls.CHILD_PROCESS_SCRIPT,
+ **env_vars
+ )
if not result.rc == 0:
result.fail(py_cmd)
# All subprocess outputs in this test case should be pure ASCII
@@ -213,8 +212,7 @@ class _LocaleHandlingTestCase(unittest.TestCase):
expected_fs_encoding,
expected_stream_encoding,
expected_warnings,
- coercion_expected,
- xoption=None):
+ coercion_expected):
"""Check the C locale handling for the given process environment
Parameters:
@@ -222,7 +220,7 @@ class _LocaleHandlingTestCase(unittest.TestCase):
expected_stream_encoding: expected encoding for standard streams
expected_warning: stderr output to expect (if any)
"""
- result = EncodingDetails.get_child_details(env_vars, xoption)
+ result = EncodingDetails.get_child_details(env_vars)
encoding_details, stderr_lines = result
expected_details = EncodingDetails.get_expected_details(
coercion_expected,
@@ -292,7 +290,6 @@ class LocaleCoercionTests(_LocaleHandlingTestCase):
coerce_c_locale,
expected_warnings=None,
coercion_expected=True,
- use_xoption=False,
**extra_vars):
"""Check the C locale handling for various configurations
@@ -322,12 +319,8 @@ class LocaleCoercionTests(_LocaleHandlingTestCase):
"PYTHONCOERCECLOCALE": "",
}
base_var_dict.update(extra_vars)
- xoption = None
if coerce_c_locale is not None:
- if use_xoption:
- xoption = coerce_c_locale
- else:
- base_var_dict["PYTHONCOERCECLOCALE"] = coerce_c_locale
+ base_var_dict["PYTHONCOERCECLOCALE"] = coerce_c_locale
# Check behaviour for the default locale
with self.subTest(default_locale=True,
@@ -349,8 +342,7 @@ class LocaleCoercionTests(_LocaleHandlingTestCase):
fs_encoding,
stream_encoding,
_expected_warnings,
- _coercion_expected,
- xoption=xoption)
+ _coercion_expected)
# Check behaviour for explicitly configured locales
for locale_to_set in EXPECTED_C_LOCALE_EQUIVALENTS:
@@ -365,8 +357,7 @@ class LocaleCoercionTests(_LocaleHandlingTestCase):
fs_encoding,
stream_encoding,
expected_warnings,
- coercion_expected,
- xoption=xoption)
+ coercion_expected)
def test_PYTHONCOERCECLOCALE_not_set(self):
# This should coerce to the first available target locale by default
@@ -413,32 +404,6 @@ class LocaleCoercionTests(_LocaleHandlingTestCase):
expected_warnings=[LEGACY_LOCALE_WARNING],
coercion_expected=False)
- def test_xoption_set_to_1(self):
- self._check_c_locale_coercion("utf-8", "utf-8", coerce_c_locale="1",
- use_xoption=True)
-
- def test_xoption_set_to_zero(self):
- # The setting "0" should result in the locale coercion being disabled
- self._check_c_locale_coercion(EXPECTED_C_LOCALE_FS_ENCODING,
- EXPECTED_C_LOCALE_STREAM_ENCODING,
- coerce_c_locale="0",
- coercion_expected=False,
- use_xoption=True)
- # Setting LC_ALL=C shouldn't make any difference to the behaviour
- self._check_c_locale_coercion(EXPECTED_C_LOCALE_FS_ENCODING,
- EXPECTED_C_LOCALE_STREAM_ENCODING,
- coerce_c_locale="0",
- LC_ALL="C",
- coercion_expected=False,
- use_xoption=True)
-
- def test_xoption_set_to_warn(self):
- # -X coerce_c_locale=warn enables runtime warnings for legacy locales
- self._check_c_locale_coercion("utf-8", "utf-8",
- coerce_c_locale="warn",
- expected_warnings=[CLI_COERCION_WARNING],
- use_xoption=True)
-
def test_main():
test.support.run_unittest(
LocaleConfigurationTests,
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 7e967b2..21511b8 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -159,16 +159,13 @@ class CmdLineTest(unittest.TestCase):
env = os.environ.copy()
# Use C locale to get ascii for the locale encoding
env['LC_ALL'] = 'C'
+ env['PYTHONCOERCECLOCALE'] = '0'
code = (
b'import locale; '
b'print(ascii("' + undecodable + b'"), '
b'locale.getpreferredencoding())')
p = subprocess.Popen(
- [sys.executable,
- # Disable C locale coercion and UTF-8 Mode to not use UTF-8
- "-X", "coerce_c_locale=0",
- "-X", "utf8=0",
- "-c", code],
+ [sys.executable, "-c", code],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
env=env)
stdout, stderr = p.communicate()
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index e531fd4..80233a5 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -277,6 +277,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'filesystem_errors': None,
'utf8_mode': 0,
+ 'coerce_c_locale': 0,
+ 'coerce_c_locale_warn': 0,
'pycache_prefix': NULL_STR,
'program_name': './_testembed',
@@ -304,8 +306,6 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'_install_importlib': 1,
'_check_hash_pycs_mode': 'default',
'_frozen': 0,
- '_coerce_c_locale': 0,
- '_coerce_c_locale_warn': 0,
}
def get_stdio_encoding(self, env):
@@ -324,6 +324,10 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'print(sys.getfilesystemencoding(), '
'sys.getfilesystemencodeerrors())')
args = (sys.executable, '-c', code)
+ env = dict(env)
+ if not isolated:
+ env['PYTHONCOERCECLOCALE'] = '0'
+ env['PYTHONUTF8'] = '0'
proc = subprocess.run(args, text=True, env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index a7f2928..b90366d 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -656,8 +656,9 @@ class SysModuleTest(unittest.TestCase):
def c_locale_get_error_handler(self, locale, isolated=False, encoding=None):
# Force the POSIX locale
- env = dict(os.environ)
+ env = os.environ.copy()
env["LC_ALL"] = locale
+ env["PYTHONCOERCECLOCALE"] = "0"
code = '\n'.join((
'import sys',
'def dump(name):',
@@ -667,10 +668,7 @@ class SysModuleTest(unittest.TestCase):
'dump("stdout")',
'dump("stderr")',
))
- args = [sys.executable,
- "-X", "utf8=0",
- "-X", "coerce_c_locale=0",
- "-c", code]
+ args = [sys.executable, "-X", "utf8=0", "-c", code]
if isolated:
args.append("-I")
if encoding is not None:
diff --git a/Lib/test/test_utf8_mode.py b/Lib/test/test_utf8_mode.py
index c3cbb49..7280ce7 100644
--- a/Lib/test/test_utf8_mode.py
+++ b/Lib/test/test_utf8_mode.py
@@ -27,8 +27,6 @@ class UTF8ModeTests(unittest.TestCase):
return (loc in POSIX_LOCALES)
def get_output(self, *args, failure=False, **kw):
- # Always disable the C locale coercion (PEP 538)
- args = ('-X', 'coerce_c_locale=0', *args)
kw = dict(self.DEFAULT_ENV, **kw)
if failure:
out = assert_python_failure(*args, **kw)
@@ -118,6 +116,7 @@ class UTF8ModeTests(unittest.TestCase):
# PYTHONLEGACYWINDOWSFSENCODING disables the UTF-8 mode
# and has the priority over -X utf8 and PYTHONUTF8
out = self.get_output('-X', 'utf8', '-c', code,
+ PYTHONUTF8='strict',
PYTHONLEGACYWINDOWSFSENCODING='1')
self.assertEqual(out, 'mbcs/replace')