diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-03-18 00:18:21 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-03-18 00:18:21 (GMT) |
commit | 7143029d4360637aadbd7ddf386ea5c64fb83095 (patch) | |
tree | 618e8173c347bcfe20ea4e073d29e6c419fe702b /Python/pythonrun.c | |
parent | 01adf06d375dcc5d2dab7a2d7dc487e0223977c9 (diff) | |
download | cpython-7143029d4360637aadbd7ddf386ea5c64fb83095.zip cpython-7143029d4360637aadbd7ddf386ea5c64fb83095.tar.gz cpython-7143029d4360637aadbd7ddf386ea5c64fb83095.tar.bz2 |
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.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index e9947e9..bb9f425 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -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; } } |