summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-04-10 11:34:13 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-04-10 11:34:13 (GMT)
commitfc43511867bfee131a3bfb18969ad02a1bb44a07 (patch)
tree2f07faf1728b809886d9e2616baaec002ff9cea4 /Python
parent731b1b12b8de92b5da8bcdb5ba686f1d3a83662a (diff)
downloadcpython-fc43511867bfee131a3bfb18969ad02a1bb44a07.zip
cpython-fc43511867bfee131a3bfb18969ad02a1bb44a07.tar.gz
cpython-fc43511867bfee131a3bfb18969ad02a1bb44a07.tar.bz2
Issue #25339: PYTHONIOENCODING now has priority over locale in setting the
error handler for stdin and stdout.
Diffstat (limited to 'Python')
-rw-r--r--Python/pylifecycle.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 35ca88f..ce52990 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1135,15 +1135,6 @@ initstdio(void)
encoding = _Py_StandardStreamEncoding;
errors = _Py_StandardStreamErrors;
if (!encoding || !errors) {
- if (!errors) {
- /* When the LC_CTYPE locale is the POSIX locale ("C locale"),
- stdin and stdout use the surrogateescape error handler by
- default, instead of the strict error handler. */
- char *loc = setlocale(LC_CTYPE, NULL);
- if (loc != NULL && strcmp(loc, "C") == 0)
- errors = "surrogateescape";
- }
-
pythonioencoding = Py_GETENV("PYTHONIOENCODING");
if (pythonioencoding) {
char *err;
@@ -1156,7 +1147,7 @@ initstdio(void)
if (err) {
*err = '\0';
err++;
- if (*err && !_Py_StandardStreamErrors) {
+ if (*err && !errors) {
errors = err;
}
}
@@ -1164,6 +1155,14 @@ initstdio(void)
encoding = pythonioencoding;
}
}
+ if (!errors && !(pythonioencoding && *pythonioencoding)) {
+ /* When the LC_CTYPE locale is the POSIX locale ("C locale"),
+ stdin and stdout use the surrogateescape error handler by
+ default, instead of the strict error handler. */
+ char *loc = setlocale(LC_CTYPE, NULL);
+ if (loc != NULL && strcmp(loc, "C") == 0)
+ errors = "surrogateescape";
+ }
}
/* Set sys.stdin */