diff options
author | Victor Stinner <vstinner@python.org> | 2023-06-06 14:55:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-06 14:55:21 (GMT) |
commit | b1a91d26c67250ff7abeb20064e7766096604001 (patch) | |
tree | 8d93339fa3dd90aae408c5ff63b0a71fd409f64d /Lib/locale.py | |
parent | 3a975b5e92736cd2f68a09aa71a17d373b9355e9 (diff) | |
download | cpython-b1a91d26c67250ff7abeb20064e7766096604001.zip cpython-b1a91d26c67250ff7abeb20064e7766096604001.tar.gz cpython-b1a91d26c67250ff7abeb20064e7766096604001.tar.bz2 |
gh-104783: locale.getencoding() fallback uses FS encoding (#105381)
The locale.getencoding() function now uses
sys.getfilesystemencoding() if _locale.getencoding() is missing,
instead of calling locale.getdefaultlocale().
Diffstat (limited to 'Lib/locale.py')
-rw-r--r-- | Lib/locale.py | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/Lib/locale.py b/Lib/locale.py index 0197967..cd52ecd 100644 --- a/Lib/locale.py +++ b/Lib/locale.py @@ -616,16 +616,12 @@ def setlocale(category, locale=None): try: from _locale import getencoding except ImportError: + # When _locale.getencoding() is missing, locale.getencoding() uses the + # Python filesystem encoding. + _encoding = sys.getfilesystemencoding() def getencoding(): - if hasattr(sys, 'getandroidapilevel'): - # On Android langinfo.h and CODESET are missing, and UTF-8 is - # always used in mbstowcs() and wcstombs(). - return 'utf-8' - encoding = _getdefaultlocale()[1] - if encoding is None: - # LANG not set, default to UTF-8 - encoding = 'utf-8' - return encoding + return _encoding + try: CODESET |