mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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.
This commit is contained in:
parent
0001a1b69e
commit
3529718925
5 changed files with 52 additions and 17 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue