mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +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
|
@ -55,9 +55,6 @@ get_surrogateescape(_Py_error_handler errors, int *surrogateescape)
|
|||
PyObject *
|
||||
_Py_device_encoding(int fd)
|
||||
{
|
||||
#if defined(MS_WINDOWS)
|
||||
UINT cp;
|
||||
#endif
|
||||
int valid;
|
||||
_Py_BEGIN_SUPPRESS_IPH
|
||||
valid = isatty(fd);
|
||||
|
@ -66,6 +63,7 @@ _Py_device_encoding(int fd)
|
|||
Py_RETURN_NONE;
|
||||
|
||||
#if defined(MS_WINDOWS)
|
||||
UINT cp;
|
||||
if (fd == 0)
|
||||
cp = GetConsoleCP();
|
||||
else if (fd == 1 || fd == 2)
|
||||
|
@ -74,16 +72,14 @@ _Py_device_encoding(int fd)
|
|||
cp = 0;
|
||||
/* GetConsoleCP() and GetConsoleOutputCP() return 0 if the application
|
||||
has no console */
|
||||
if (cp != 0)
|
||||
return PyUnicode_FromFormat("cp%u", (unsigned int)cp);
|
||||
#elif defined(CODESET)
|
||||
{
|
||||
char *codeset = nl_langinfo(CODESET);
|
||||
if (codeset != NULL && codeset[0] != 0)
|
||||
return PyUnicode_FromString(codeset);
|
||||
if (cp == 0) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
return PyUnicode_FromFormat("cp%u", (unsigned int)cp);
|
||||
#else
|
||||
return _Py_GetLocaleEncodingObject();
|
||||
#endif
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
#if !defined(_Py_FORCE_UTF8_FS_ENCODING) && !defined(MS_WINDOWS)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue