msg252515 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-10-08 06:51 |
The error handler of sys.stdout and sys.stdin is set to "surrogateescape" even for non-ASCII encoding. $ LANG= PYTHONIOENCODING=UTF-8 ./python -c 'import sys; print(sys.stdout.encoding, sys.stdout.errors)' UTF-8 surrogateescape |
|
|
msg253009 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2015-10-14 16:35 |
Sorry, I don't understand the issue. Do you consider that using surrogateescape is a bug? Which behaviour do you expect? Python 3.5 now uses surrogateescape by default for stdout and stderr when the locale is POSIX. I guess that you got the POSIX locale using "LANG=". |
|
|
msg253011 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-10-14 17:02 |
I'm not sure this is a bug, but it looks at least unexpected, that surrogateescape is used with non-ASCII encoding. For example my last test for fails on POSIX locale in 3.5+, and it is not so easy to make it working. May be change error handler to surrogateescape only if PYTHONIOENCODING is not specified? |
|
|
msg253018 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2015-10-14 20:12 |
"it looks at least unexpected, that surrogateescape is used with non-ASCII encoding" What do you mean by non-ASCII encoding? surrogateescape is used by all encodings for all OS operations on Python 3, like os.listdir(), even for UTF-8. |
|
|
msg254463 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-11-10 20:50 |
The default encoding of sys.stdio and sys.stdout is determined by (in order of increasing precedence): 1. locale 2. PYTHONIOENCODING 3. Py_SetStandardStreamEncoding() The default error handler before 3.5 was determined by: 1. 'strict' 2. PYTHONIOENCODING 3. Py_SetStandardStreamEncoding() The default error handler since 3.5 () is determined by: 1. PYTHONIOENCODING 2. locale 3. Py_SetStandardStreamEncoding() Even if you explicitly specified the error handler by PYTHONIOENCODING, it doesn't have effect in POSIX locale. This doesn't look right to me. I think the order should be the same as for encoding. Proposed patch makes PYTHONIOENCODING to override locale default for error handler. |
|
|
msg262991 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2016-04-07 15:35 |
What do you think about this Victor? |
|
|
msg263012 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2016-04-08 09:37 |
I believe the problem may be that we can't readily tell the difference between "PYTHONIOENCODING=ascii" and "PYTHONIOENCODING=ascii:strict", and in the former case we'd ideally still end up using "surrogateescape" by default. That said, the real intent of the change was "If the detected encoding is ASCII, enable surrogateescape automatically", and detecting the POSIX locale was a proxy for that. We didn't account for PYTHONIOENCODING being used to select a more sensible encoding. |
|
|
msg263015 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2016-04-08 10:46 |
Making "PYTHONIOENCODING=ascii" to mean "PYTHONIOENCODING=ascii:surrogateescape" is different (and may be more complex) issue. What error handler should use open(name, encoding='ascii')? open(name) in POSIX locale? This issue is about incorrect working of PYTHONIOENCODING in POSIX locale. |
|
|
msg263090 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2016-04-09 12:53 |
Ok, I now understand the issue. Your change looks good to me. I agree that strict error handler is good choice for PYTHONIOENCODING=ascii. |
|
|
msg263091 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2016-04-09 12:53 |
The patch looks good to me. |
|
|
msg263130 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2016-04-10 11:45 |
New changeset 56eca1c08738 by Serhiy Storchaka in branch '3.5': Issue #25339: PYTHONIOENCODING now has priority over locale in setting the https://hg.python.org/cpython/rev/56eca1c08738 New changeset 9c6623099da1 by Serhiy Storchaka in branch 'default': Issue #25339: PYTHONIOENCODING now has priority over locale in setting the https://hg.python.org/cpython/rev/9c6623099da1 |
|
|
msg263133 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2016-04-10 11:50 |
Thank you for your review Victor. I have added yet one minor change in tests because -I doesn't suppress PYTHONIOENCODING. |
|
|