mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
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().
This commit is contained in:
parent
3a975b5e92
commit
b1a91d26c6
2 changed files with 16 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue