diff options
author | Steve Dower <steve.dower@microsoft.com> | 2016-12-28 16:03:28 -0800 |
---|---|---|
committer | Steve Dower <steve.dower@microsoft.com> | 2016-12-28 16:03:28 -0800 |
commit | 6dd5667d0639af9a1d887db678b077c48e11985f (patch) | |
tree | cdb804a6523e941cfe51b38c2ff8917baba9a416 /Lib/locale.py | |
parent | 9cc01c067740c1f831c405db033632efd320c24d (diff) | |
parent | 7e1e287d5713d79e19fb673741f6450bca22ebc4 (diff) | |
download | cpython-6dd5667d0639af9a1d887db678b077c48e11985f.tar.gz |
Issue #29079: Prevent infinite loop in pathlib.resolve() on Windows
Diffstat (limited to 'Lib/locale.py')
-rw-r--r-- | Lib/locale.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Lib/locale.py b/Lib/locale.py index 4de0090ed9..f8d1d78c36 100644 --- a/Lib/locale.py +++ b/Lib/locale.py @@ -618,15 +618,21 @@ else: try: CODESET except NameError: - # Fall back to parsing environment variables :-( - def getpreferredencoding(do_setlocale = True): - """Return the charset that the user is likely using, - by looking at environment variables.""" - res = getdefaultlocale()[1] - if res is None: - # LANG not set, default conservatively to ASCII - res = 'ascii' - return res + if hasattr(sys, 'getandroidapilevel'): + # On Android langinfo.h and CODESET are missing, and UTF-8 is + # always used in mbstowcs() and wcstombs(). + def getpreferredencoding(do_setlocale = True): + return 'UTF-8' + else: + # Fall back to parsing environment variables :-( + def getpreferredencoding(do_setlocale = True): + """Return the charset that the user is likely using, + by looking at environment variables.""" + res = getdefaultlocale()[1] + if res is None: + # LANG not set, default conservatively to ASCII + res = 'ascii' + return res else: def getpreferredencoding(do_setlocale = True): """Return the charset that the user is likely using, |