+29
-18
lines changedFilter options
+29
-18
lines changed Original file line number Diff line number Diff line change
@@ -14,6 +14,13 @@
14
14
from test.support import make_legacy_pyc, strip_python_stderr
15
15
16
16
17
+
RUNTIME_C_LOCALE_WARNING = (
18
+
"Python runtime initialized with LC_CTYPE=C (a locale with default ASCII "
19
+
"encoding), which may cause Unicode compatibility problems. Using C.UTF-8, "
20
+
"C.utf8, or UTF-8 (if available) as alternative Unicode-compatible "
21
+
"locales is recommended."
22
+
)
23
+
17
24
# Cached result of the expensive test performed in the function below.
18
25
__cached_interp_requires_environment = None
19
26
@@ -55,7 +62,7 @@ def fail(self, cmd_line):
55
62
"""Provide helpful details about failed subcommand runs"""
56
63
# Limit to 80 lines to ASCII characters
57
64
maxlen = 80 * 100
58
-
out, err = res.out, res.err
65
+
out, err = self.out, self.err
59
66
if len(out) > maxlen:
60
67
out = b'(... truncated stdout ...)' + out[-maxlen:]
61
68
if len(err) > maxlen:
@@ -74,7 +81,7 @@ def fail(self, cmd_line):
74
81
"---\n"
75
82
"%s\n"
76
83
"---"
77
-
% (res.rc, cmd_line,
84
+
% (self.rc, cmd_line,
78
85
out,
79
86
err))
80
87
Original file line number Diff line number Diff line change
@@ -8,8 +8,10 @@
8
8
import subprocess
9
9
import tempfile
10
10
from test.support import script_helper, is_android
11
-
from test.support.script_helper import (spawn_python, kill_python, assert_python_ok,
12
-
assert_python_failure)
11
+
from test.support.script_helper import (
12
+
spawn_python, kill_python, assert_python_ok, assert_python_failure,
13
+
RUNTIME_C_LOCALE_WARNING
14
+
)
13
15
14
16
15
17
# XXX (ncoghlan): Move to script_helper and make consistent with run_python
@@ -150,6 +152,7 @@ def test_undecodable_code(self):
150
152
env = os.environ.copy()
151
153
# Use C locale to get ascii for the locale encoding
152
154
env['LC_ALL'] = 'C'
155
+
env['PYTHONCOERCECLOCALE'] = '0'
153
156
code = (
154
157
b'import locale; '
155
158
b'print(ascii("' + undecodable + b'"), '
@@ -159,17 +162,18 @@ def test_undecodable_code(self):
159
162
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
160
163
env=env)
161
164
stdout, stderr = p.communicate()
165
+
pattern = RUNTIME_C_LOCALE_WARNING.encode() + b'\n'
162
166
if p.returncode == 1:
163
167
# _Py_char2wchar() decoded b'\xff' as '\udcff' (b'\xff' is not
164
168
# decodable from ASCII) and run_command() failed on
165
169
# PyUnicode_AsUTF8String(). This is the expected behaviour on
166
170
# Linux.
167
-
pattern = b"Unable to decode the command from the command line:"
171
+
pattern += b"Unable to decode the command from the command line:"
168
172
elif p.returncode == 0:
169
173
# _Py_char2wchar() decoded b'\xff' as '\xff' even if the locale is
170
174
# C and the locale encoding is ASCII. It occurs on FreeBSD, Solaris
171
175
# and Mac OS X.
172
-
pattern = b"'\\xff' "
176
+
pattern += b"'\\xff' "
173
177
# The output is followed by the encoding name, an alias to ASCII.
174
178
# Examples: "US-ASCII" or "646" (ISO 646, on Solaris).
175
179
else:
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
8
8
from test.support.script_helper import (
9
9
run_python_until_end,
10
10
interpreter_requires_environment,
11
+
RUNTIME_C_LOCALE_WARNING
11
12
)
12
13
13
14
# In order to get the warning messages to match up as expected, the candidate
@@ -29,19 +30,12 @@ def _set_locale_in_subprocess(locale_name, category):
29
30
result, py_cmd = run_python_until_end("-c", cmd, __isolated=True)
30
31
return result.rc == 0
31
32
32
-
# Details of the warnings emitted at runtime
33
+
# Details of the CLI warning emitted at runtime
33
34
CLI_COERCION_WARNING_FMT = (
34
35
"Python detected LC_CTYPE=C, {} set to {} (set another locale or "
35
36
"PYTHONCOERCECLOCALE=0 to disable this locale coercion behaviour)."
36
37
)
37
38
38
-
LIBRARY_C_LOCALE_WARNING = (
39
-
"Python runtime initialized with LC_CTYPE=C (a locale with default ASCII "
40
-
"encoding), which may cause Unicode compatibility problems. Using C.UTF-8 "
41
-
"C.utf8, or UTF-8 (if available) as alternative Unicode-compatible "
42
-
"locales is recommended."
43
-
)
44
-
45
39
@test.support.cpython_only
46
40
class LocaleOverrideTest(unittest.TestCase):
47
41
@@ -109,7 +103,7 @@ def _check_c_locale_coercion(self, expected_fsencoding, coerce_c_locale):
109
103
if coerce_c_locale == "0":
110
104
# Check the library emits a warning
111
105
expected_warning = [
112
-
LIBRARY_C_LOCALE_WARNING,
106
+
RUNTIME_C_LOCALE_WARNING,
113
107
]
114
108
else:
115
109
# Check C locale is coerced with a warning on stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
1
1
import unittest, test.support
2
-
from test.support.script_helper import assert_python_ok, assert_python_failure
2
+
from test.support.script_helper import (
3
+
assert_python_ok, assert_python_failure,
4
+
RUNTIME_C_LOCALE_WARNING
5
+
)
3
6
import sys, io, os
4
7
import struct
5
8
import subprocess
@@ -676,10 +679,13 @@ def test_getfilesystemencoding(self):
676
679
expected = None
677
680
self.check_fsencoding(fs_encoding, expected)
678
681
682
+
_SKIP_RUNTIME_C_LOCALE_WARNING = len(RUNTIME_C_LOCALE_WARNING + "\n")
683
+
679
684
def c_locale_get_error_handler(self, isolated=False, encoding=None):
680
685
# Force the POSIX locale
681
686
env = os.environ.copy()
682
687
env["LC_ALL"] = "C"
688
+
env["PYTHONCOERCECLOCALE"] = "0"
683
689
code = '\n'.join((
684
690
'import sys',
685
691
'def dump(name):',
@@ -702,7 +708,7 @@ def c_locale_get_error_handler(self, isolated=False, encoding=None):
702
708
env=env,
703
709
universal_newlines=True)
704
710
stdout, stderr = p.communicate()
705
-
return stdout
711
+
return stdout[self._SKIP_RUNTIME_C_LOCALE_WARNING:]
706
712
707
713
def test_c_locale_surrogateescape(self):
708
714
out = self.c_locale_get_error_handler(isolated=True)
Original file line number Diff line number Diff line change
@@ -304,7 +304,7 @@ import_init(PyInterpreterState *interp, PyObject *sysmod)
304
304
305
305
static const char *_C_LOCALE_WARNING =
306
306
"Python runtime initialized with LC_CTYPE=C (a locale with default ASCII "
307
-
"encoding), which may cause Unicode compatibility problems. Using C.UTF-8 "
307
+
"encoding), which may cause Unicode compatibility problems. Using C.UTF-8, "
308
308
"C.utf8, or UTF-8 (if available) as alternative Unicode-compatible "
309
309
"locales is recommended.\n";
310
310
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4