8000 UTF-8 -> utf-8 · python/cpython@7720b10 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7720b10

Browse files
committed
UTF-8 -> utf-8
1 parent 44730dd commit 7720b10

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

Doc/glossary.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,11 @@ Glossary
706706

707707
locale encoding
708708
On Unix, it is the encoding of the LC_CTYPE locale. It can be set with
709-
``locale.setlocale(locale.LC_CTYPE, new_locale)``.
709+
:func:`locale.setlocale(locale.LC_CTYPE, new_locale) <locale.setlocale>`.
710710

711711
On Windows, it is the ANSI code page (ex: ``"cp1252"``).
712712

713-
On Android and VxWorks, Python uses ``"UTF-8"`` as the locale encoding.
713+
On Android and VxWorks, Python uses ``"utf-8"`` as the locale encoding.
714714

715715
``locale.getencoding()`` can be used to get the locale encoding.
716716

Doc/library/locale.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ The :mod:`locale` module defines the following exception and functions:
327327
is not necessary or desired, *do_setlocale* should be set to ``False``.
328328

329329
On Android or if the :ref:`Python UTF-8 Mode <utf8-mode>` is enabled, always
330-
return ``'UTF-8'``, the :term:`locale encoding` and the *do_setlocale*
330+
return ``'utf-8'``, the :term:`locale encoding` and the *do_setlocale*
331331
argument are ignored.
332332

333333
The :ref:`Python preinitialization <c-preinit>` configures the LC_CTYPE
@@ -337,18 +337,23 @@ The :mod:`locale` module defines the following exception and functions:
337337
The function now always returns ``"UTF-8"`` on Android or if the
338338
:ref:`Python UTF-8 Mode <utf8-mode>` is enabled.
339339

340+
.. versionchanged:: 3.11
341+
The function now returns ``"utf-8"`` instead of ``"UTF-8"`` on Android
342+
or if the :ref:`Python UTF-8 Mode <utf8-mode>` is enabled.
343+
340344

341345
.. function:: getencoding()
342346

343347
Get the current :term:`locale encoding`:
344348

345-
* On Android and VxWorks, return ``"UTF-8"``.
349+
* On Android and VxWorks, return ``"utf-8"``.
346350
* On Unix, return the encoding of the current :data:`LC_CTYPE` locale.
347-
Return ``"UTF-8"`` if ``nl_langinfo(CODESET)`` returns an empty string:
351+
Return ``"utf-8"`` if ``nl_langinfo(CODESET)`` returns an empty string:
348352
for example, if the current LC_CTYPE locale is not supported.
349353
* On Windows, return the ANSI code page.
350354

351-
This function is similar to :func:`getpreferredencoding(False) <getpreferredencoding>` except this
355+
This function is similar to
356+
:func:`getpreferredencoding(False) <getpreferredencoding>` except this
352357
function ignores the :ref:`Python UTF-8 Mode <utf8-mode>`.
353358

354359
.. versionadded:: 3.11

Lib/locale.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,11 @@ def getencoding():
643643
if hasattr(sys, 'getandroidapilevel'):
644644
# On Android langinfo.h and CODESET are missing, and UTF-8 is
645645
# always used in mbstowcs() and wcstombs().
646-
return 'UTF-8'
646+
return 'utf-8'
647647
encoding = getdefaultlocale()[1]
648648
if encoding is None:
649649
# LANG not set, default to UTF-8
650-
encoding = 'UTF-8'
650+
encoding = 'utf-8'
651651
return encoding
652652

653653
try:
@@ -656,15 +656,15 @@ def getencoding():
656656
def getpreferredencoding(do_setlocale=True):
657657
"""Return the charset that the user is likely using."""
658658
if sys.flags.utf8_mode:
659-
return 'UTF-8'
659+
return 'utf-8'
660660
return getencoding()
661661
else:
662662
# On Unix, if CODESET is available, use that.
663663
def getpreferredencoding(do_setlocale=True):
664664
"""Return the charset that the user is likely using,
665665
according to the system configuration."""
666666
if sys.flags.utf8_mode:
667-
return 'UTF-8'
667+
return 'utf-8'
668668

669669
if not do_setlocale:
670670
return getencoding()

Python/fileutils.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ _Py_device_encoding(int fd)
9595
#else
9696
if (_PyRuntime.preconfig.utf8_mode) {
9797
_Py_DECLARE_STR(utf_8, "utf-8");
98-
PyObject *encoding = &_Py_STR(utf_8);
99-
Py_INCREF(encoding);
100-
return encoding;
98+
return Py_NewRef(&_Py_STR(utf_8));
10199
}
102100
return _Py_GetLocaleEncodingObject();
103101
#endif
@@ -879,10 +877,10 @@ _Py_EncodeLocaleEx(const wchar_t *text, char **str,
879877

880878
// Get the current locale encoding name:
881879
//
882-
// - Return "UTF-8" if _Py_FORCE_UTF8_LOCALE macro is defined (ex: on Android)
883-
// - Return "UTF-8" if the UTF-8 Mode is enabled
880+
// - Return "utf-8" if _Py_FORCE_UTF8_LOCALE macro is defined (ex: on Android)
881+
// - Return "utf-8" if the UTF-8 Mode is enabled
884882
// - On Windows, return the ANSI code page (ex: "cp1250")
885-
// - Return "UTF-8" if nl_langinfo(CODESET) returns an empty string.
883+
// - Return "utf-8" if nl_langinfo(CODESET) returns an empty string.
886884
// - Otherwise, return nl_langinfo(CODESET).
887885
//
888886
// Return NULL on memory allocation failure.
@@ -894,7 +892,7 @@ _Py_GetLocaleEncoding(void)
894892
#ifdef _Py_FORCE_UTF8_LOCALE
895893
// On Android langinfo.h and CODESET are missing,
896894
// and UTF-8 is always used in mbstowcs() and wcstombs().
897-
return _PyMem_RawWcsdup(L"UTF-8");
895+
return _PyMem_RawWcsdup(L"utf-8");
898896
#else
899897

900898
#ifdef MS_WINDOWS
@@ -908,7 +906,7 @@ _Py_GetLocaleEncoding(void)
908906
if (!encoding || encoding[0] == '\0') {
909907
// Use UTF-8 if nl_langinfo() returns an empty string. It can happen on
910908
// macOS if the LC_CTYPE locale is not supported.
911-
return _PyMem_RawWcsdup(L"UTF-8");
909+
return _PyMem_RawWcsdup(L"utf-8");
912910
}
913911

914912
wchar_t *wstr;

Python/initconfig.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,7 @@ config_get_locale_encoding(PyConfig *config, const PyPreConfig *preconfig,
17811781
{
17821782
wchar_t *encoding;
17831783
if (preconfig->utf8_mode) {
1784-
encoding = _PyMem_RawWcsdup(L"UTF-8");
1784+
encoding = _PyMem_RawWcsdup(L"utf-8");
17851785
}
17861786
else {
17871787
encoding = _Py_GetLocaleEncoding();

0 commit comments

Comments
 (0)
0