mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-29240: PEP 540: Add a new UTF-8 Mode (#855)
* Add -X utf8 command line option, PYTHONUTF8 environment variable and a new sys.flags.utf8_mode flag. * If the LC_CTYPE locale is "C" at startup: enable automatically the UTF-8 mode. * Add _winapi.GetACP(). encodings._alias_mbcs() now calls _winapi.GetACP() to get the ANSI code page * locale.getpreferredencoding() now returns 'UTF-8' in the UTF-8 mode. As a side effect, open() now uses the UTF-8 encoding by default in this mode. * Py_DecodeLocale() and Py_EncodeLocale() now use the UTF-8 encoding in the UTF-8 Mode. * Update subprocess._args_from_interpreter_flags() to handle -X utf8 * Skip some tests relying on the current locale if the UTF-8 mode is enabled. * Add test_utf8mode.py. * _Py_DecodeUTF8_surrogateescape() gets a new optional parameter to return also the length (number of wide characters). * pymain_get_global_config() and pymain_set_global_config() now always copy flag values, rather than only copying if the new value is greater than the old value.
This commit is contained in:
parent
c3e070f849
commit
91106cd9ff
27 changed files with 598 additions and 183 deletions
|
@ -527,7 +527,7 @@ class SysModuleTest(unittest.TestCase):
|
|||
"inspect", "interactive", "optimize", "dont_write_bytecode",
|
||||
"no_user_site", "no_site", "ignore_environment", "verbose",
|
||||
"bytes_warning", "quiet", "hash_randomization", "isolated",
|
||||
"dev_mode")
|
||||
"dev_mode", "utf8_mode")
|
||||
for attr in attrs:
|
||||
self.assertTrue(hasattr(sys.flags, attr), attr)
|
||||
attr_type = bool if attr == "dev_mode" else int
|
||||
|
@ -535,6 +535,8 @@ class SysModuleTest(unittest.TestCase):
|
|||
self.assertTrue(repr(sys.flags))
|
||||
self.assertEqual(len(sys.flags), len(attrs))
|
||||
|
||||
self.assertIn(sys.flags.utf8_mode, {0, 1, 2})
|
||||
|
||||
def assert_raise_on_new_sys_type(self, sys_attr):
|
||||
# Users are intentionally prevented from creating new instances of
|
||||
# sys.flags, sys.version_info, and sys.getwindowsversion.
|
||||
|
@ -710,8 +712,8 @@ class SysModuleTest(unittest.TestCase):
|
|||
# have no any effect
|
||||
out = self.c_locale_get_error_handler(encoding=':')
|
||||
self.assertEqual(out,
|
||||
'stdin: surrogateescape\n'
|
||||
'stdout: surrogateescape\n'
|
||||
'stdin: strict\n'
|
||||
'stdout: strict\n'
|
||||
'stderr: backslashreplace\n')
|
||||
out = self.c_locale_get_error_handler(encoding='')
|
||||
self.assertEqual(out,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue