mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue #25339: PYTHONIOENCODING now has priority over locale in setting the
error handler for stdin and stdout.
This commit is contained in:
commit
403002723f
3 changed files with 35 additions and 14 deletions
|
@ -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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue