diff options
author | Inada Naoki <songofacandy@gmail.com> | 2022-04-09 09:54:54 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-09 09:54:54 +0900 |
commit | 677320348728ce058fa3579017e985af74a236d4 (patch) | |
tree | 944297b71196964eab27a3336918c5a8f1e6a17d /Python/fileutils.c | |
parent | cd29bd13ef1fe18970c5d43b66c545dd03117cb9 (diff) | |
download | cpython-git-677320348728ce058fa3579017e985af74a236d4.tar.gz |
bpo-47000: Add `locale.getencoding()` (GH-32068)
Diffstat (limited to 'Python/fileutils.c')
-rw-r--r-- | Python/fileutils.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c index d1d62dce5d..582c6bafd8 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -93,6 +93,10 @@ _Py_device_encoding(int fd) return PyUnicode_FromFormat("cp%u", (unsigned int)cp); #else + if (_PyRuntime.preconfig.utf8_mode) { + _Py_DECLARE_STR(utf_8, "utf-8"); + return Py_NewRef(&_Py_STR(utf_8)); + } return _Py_GetLocaleEncodingObject(); #endif } @@ -873,10 +877,10 @@ _Py_EncodeLocaleEx(const wchar_t *text, char **str, // Get the current locale encoding name: // -// - Return "UTF-8" if _Py_FORCE_UTF8_LOCALE macro is defined (ex: on Android) -// - Return "UTF-8" if the UTF-8 Mode is enabled +// - Return "utf-8" if _Py_FORCE_UTF8_LOCALE macro is defined (ex: on Android) +// - Return "utf-8" if the UTF-8 Mode is enabled // - On Windows, return the ANSI code page (ex: "cp1250") -// - Return "UTF-8" if nl_langinfo(CODESET) returns an empty string. +// - Return "utf-8" if nl_langinfo(CODESET) returns an empty string. // - Otherwise, return nl_langinfo(CODESET). // // Return NULL on memory allocation failure. @@ -888,12 +892,8 @@ _Py_GetLocaleEncoding(void) #ifdef _Py_FORCE_UTF8_LOCALE // On Android langinfo.h and CODESET are missing, // and UTF-8 is always used in mbstowcs() and wcstombs(). - return _PyMem_RawWcsdup(L"UTF-8"); + return _PyMem_RawWcsdup(L"utf-8"); #else - const PyPreConfig *preconfig = &_PyRuntime.preconfig; - if (preconfig->utf8_mode) { - return _PyMem_RawWcsdup(L"UTF-8"); - } #ifdef MS_WINDOWS wchar_t encoding[23]; @@ -906,7 +906,7 @@ _Py_GetLocaleEncoding(void) if (!encoding || encoding[0] == '\0') { // Use UTF-8 if nl_langinfo() returns an empty string. It can happen on // macOS if the LC_CTYPE locale is not supported. - return _PyMem_RawWcsdup(L"UTF-8"); + return _PyMem_RawWcsdup(L"utf-8"); } wchar_t *wstr; |