mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
Issue #19977: When the `LC_TYPE
locale is the POSIX locale (
C
` locale),
:py:data:`sys.stdin` and :py:data:`sys.stdout` are now using the ``surrogateescape`` error handler, instead of the ``strict`` error handler.
This commit is contained in:
parent
01adf06d37
commit
7143029d43
4 changed files with 62 additions and 2 deletions
|
@ -1156,6 +1156,15 @@ 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;
|
||||
|
@ -1168,7 +1177,7 @@ initstdio(void)
|
|||
if (err) {
|
||||
*err = '\0';
|
||||
err++;
|
||||
if (*err && !errors) {
|
||||
if (*err && !_Py_StandardStreamErrors) {
|
||||
errors = err;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue