Author xdegaye
Recipients Jan Niklas Hasse, Sworddragon, abarry, akira, barry, ezio.melotti, inada.naoki, lemburg, ncoghlan, r.david.murray, vstinner, xdegaye, yan12125
Date 2017-01-18.15:15:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1484752560.88.0.512769974572.issue28180@psf.upfronthosting.co.za>
In-reply-to
Content
pep538_coerce_legacy_c_locale_v3.diff fixes issue 28997 on Android (api 21 and 24). This issue is raised because there is an inconsistency between Python on Android that considers the locale encoding to be always UTF-8 and GNU Readline that does not accept eight-bit characters when LANG is not set (on Android).

On Android, setlocale(CATEGORY, "") does not look for the locale environment variables (LANG, ...) but sets the 'C' locale instead, so the patch does not fully behave as expected and the 'Py_Initialize detected' warning is emitted. Here is the output of an interactive session on Android:

root@generic_x86:/data/data/org.bitbucket.pyona # python
Python detected LC_CTYPE=C, forcing LC_ALL & LANG to C.UTF-8 (set PYTHONALLOWCLOCALE to disable this locale coercion behaviour).
Py_Initialize detected LC_CTYPE=C, which limits Unicode compatibility. Some libraries and operating system interfaces may not work correctly. Set `PYTHONALLOWCLOCALE=1 LC_CTYPE=C` to configure a similar environment when running Python directly.
Python 3.7.0a0 (default:0503024831ad+, Jan 18 2017, 11:34:53)
[GCC 4.2.1 Compatible Android Clang 3.8.256229 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale, os
>>> os.environ['LANG']
'C.UTF-8'
>>> locale.getdefaultlocale()
('en_US', 'UTF-8')
>>> locale.setlocale(locale.LC_CTYPE)
'C'
>>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
'C.UTF-8'
>>> locale.setlocale(locale.LC_CTYPE)
'C.UTF-8'

The attached android_setlocale.patch fixes the following problems when applied after pep538_coerce_legacy_c_locale_v3.diff:
* No 'Py_Initialize detected' warning is emitted.
* locale.setlocale(locale.LC_CTYPE) returns now 'C.UTF-8'.
History
Date User Action Args
2017-01-18 15:16:01xdegayesetrecipients: + xdegaye, lemburg, barry, ncoghlan, vstinner, ezio.melotti, r.david.murray, inada.naoki, akira, Sworddragon, yan12125, abarry, Jan Niklas Hasse
2017-01-18 15:16:00xdegayesetmessageid: <1484752560.88.0.512769974572.issue28180@psf.upfronthosting.co.za>
2017-01-18 15:16:00xdegayelinkissue28180 messages
2017-01-18 15:16:00xdegayecreate