summaryrefslogtreecommitdiffstats
path: root/Lib/locale.py
diff options
context:
space:
mode:
authorXavier de Gaye <xdegaye@users.sourceforge.net>2016-12-17 08:19:11 (GMT)
committerXavier de Gaye <xdegaye@users.sourceforge.net>2016-12-17 08:19:11 (GMT)
commit6c9dcda6b4e58367128726afc41fe05ee2f6388d (patch)
tree7e0636952cccad165fdf4b741a65d0a4cf046de5 /Lib/locale.py
parentb06cde61a2105cf9e0ec52fd7e2c131ae0cd15fa (diff)
downloadcpython-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.py24
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,