From 91106cd9ff2f321c0f60fbaa09fd46c80aa5c266 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 13 Dec 2017 12:29:09 +0100 Subject: 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. --- Python/sysmodule.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index f10099b523..141e189d0b 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1814,6 +1814,7 @@ static PyStructSequence_Field flags_fields[] = { {"hash_randomization", "-R"}, {"isolated", "-I"}, {"dev_mode", "-X dev"}, + {"utf8_mode", "-X utf8"}, {0} }; @@ -1821,7 +1822,7 @@ static PyStructSequence_Desc flags_desc = { "sys.flags", /* name */ flags__doc__, /* doc */ flags_fields, /* fields */ - 14 + 15 }; static PyObject* @@ -1853,8 +1854,9 @@ make_flags(void) SetFlag(Py_QuietFlag); SetFlag(Py_HashRandomizationFlag); SetFlag(Py_IsolatedFlag); -#undef SetFlag PyStructSequence_SET_ITEM(seq, pos++, PyBool_FromLong(core_config->dev_mode)); + SetFlag(Py_UTF8Mode); +#undef SetFlag if (PyErr_Occurred()) { Py_DECREF(seq); -- cgit v1.2.1