diff options
author | Victor Stinner <vstinner@python.org> | 2020-11-04 10:20:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 10:20:10 (GMT) |
commit | 3529718925f40d14ed48d281d809187bc7314a14 (patch) | |
tree | 1f51f7fb13e93df52a45291fe5384de6e9e09a16 /Python/initconfig.c | |
parent | 0001a1b69ecda47b0406daa88c2943877580bcae (diff) | |
download | cpython-3529718925f40d14ed48d281d809187bc7314a14.zip cpython-3529718925f40d14ed48d281d809187bc7314a14.tar.gz cpython-3529718925f40d14ed48d281d809187bc7314a14.tar.bz2 |
bpo-42236: os.device_encoding() respects UTF-8 Mode (GH-23119)
On Unix, the os.device_encoding() function now returns 'UTF-8' rather
than the device encoding if the Python UTF-8 Mode is enabled.
Diffstat (limited to 'Python/initconfig.c')
-rw-r--r-- | Python/initconfig.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Python/initconfig.c b/Python/initconfig.c index 7bb28ed..15fb3e4 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -1515,8 +1515,8 @@ config_init_stdio_encoding(PyConfig *config, { PyStatus status; - /* If Py_SetStandardStreamEncoding() have been called, use these - parameters. */ + /* If Py_SetStandardStreamEncoding() has been called, use its + arguments if they are not NULL. */ if (config->stdio_encoding == NULL && _Py_StandardStreamEncoding != NULL) { status = CONFIG_SET_BYTES_STR(config, &config->stdio_encoding, _Py_StandardStreamEncoding, @@ -1535,6 +1535,7 @@ config_init_stdio_encoding(PyConfig *config, } } + // Exit if encoding and errors are defined if (config->stdio_encoding != NULL && config->stdio_errors != NULL) { return _PyStatus_OK(); } @@ -1634,12 +1635,12 @@ config_get_fs_encoding(PyConfig *config, const PyPreConfig *preconfig, if (preconfig->utf8_mode) { return PyConfig_SetString(config, fs_encoding, L"utf-8"); } - else if (_Py_GetForceASCII()) { + + if (_Py_GetForceASCII()) { return PyConfig_SetString(config, fs_encoding, L"ascii"); } - else { - return config_get_locale_encoding(config, preconfig, fs_encoding); - } + + return config_get_locale_encoding(config, preconfig, fs_encoding); #endif // !MS_WINDOWS } |