summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-04-10 11:35:21 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-04-10 11:35:21 (GMT)
commit403002723fe926d9b1b126c0486049676f3de160 (patch)
treef9397fddb7702ca97698a9faee76462ed0084cea /Python
parentcfff15d2746d5d48a8c7821ee39bbe81755309eb (diff)
parentfc43511867bfee131a3bfb18969ad02a1bb44a07 (diff)
downloadcpython-403002723fe926d9b1b126c0486049676f3de160.zip
cpython-403002723fe926d9b1b126c0486049676f3de160.tar.gz
cpython-403002723fe926d9b1b126c0486049676f3de160.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 502a1e6..74bdb19 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1166,15 +1166,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;
@@ -1187,7 +1178,7 @@ initstdio(void)
if (err) {
*err = '\0';
err++;
- if (*err && !_Py_StandardStreamErrors) {
+ if (*err && !errors) {
errors = err;
}
}
@@ -1195,6 +1186,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 */