diff options
author | Xavier de Gaye <xdegaye@users.sourceforge.net> | 2016-12-17 08:19:11 (GMT) |
---|---|---|
committer | Xavier de Gaye <xdegaye@users.sourceforge.net> | 2016-12-17 08:19:11 (GMT) |
commit | 6c9dcda6b4e58367128726afc41fe05ee2f6388d (patch) | |
tree | 7e0636952cccad165fdf4b741a65d0a4cf046de5 /Lib/locale.py | |
parent | b06cde61a2105cf9e0ec52fd7e2c131ae0cd15fa (diff) | |
download | cpython-6c9dcda6b4e58367128726afc41fe05ee2f6388d.zip cpython-6c9dcda6b4e58367128726afc41fe05ee2f6388d.tar.gz cpython-6c9dcda6b4e58367128726afc41fe05ee2f6388d.tar.bz2 |
Issue #28596: The preferred encoding is UTF-8 on Android.
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 4de0090..f8d1d78 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, |