summaryrefslogtreecommitdiff
path: root/Lib/locale.py
diff options
context:
space:
mode:
authorMariatta Wijaya <mariatta.wijaya@gmail.com>2017-02-06 20:18:39 -0800
committerMariatta Wijaya <mariatta.wijaya@gmail.com>2017-02-06 20:18:39 -0800
commit731cca110f376cdbaffb536e42d6c9d6da574fa8 (patch)
tree9cb95caf6f8b933115820bf699725d9cd600d2df /Lib/locale.py
parentda79bcf8ac7ae72218ab023e1ed54390bc1a3a27 (diff)
parentc8102f4d974669f4c5e4ca7bcd73292a1ac5bcbf (diff)
downloadcpython-731cca110f376cdbaffb536e42d6c9d6da574fa8.tar.gz
Issue #29371: merge with 3.6
Diffstat (limited to 'Lib/locale.py')
-rw-r--r--Lib/locale.py24
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,