bpo-34485: Enhance init_sys_streams() (GH-8978)

Python now gets the locale encoding with C code to initialize the encoding
of standard streams like sys.stdout. Moreover, the encoding is now
initialized to the Python codec name to get a normalized encoding name and
to ensure that the codec is loaded. The change avoids importing
_bootlocale and _locale modules at startup by default.

When the PYTHONIOENCODING environment variable only contains an encoding,
the error handler is now is now set explicitly to "strict".

Rename also get_default_standard_stream_error_handler() to
get_stdio_errors().

Reduce the buffer to format the "cpXXX" string (Windows locale encoding).
This commit is contained in:
Victor Stinner 2018-08-28 23:26:33 +02:00 committed by GitHub
parent d500e5307a
commit 9e4994d410
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 91 additions and 43 deletions

View file

@ -113,9 +113,9 @@ static int test_forced_io_encoding(void)
printf("--- Set errors only ---\n");
check_stdio_details(NULL, "ignore");
printf("--- Set encoding only ---\n");
check_stdio_details("latin-1", NULL);
check_stdio_details("iso8859-1", NULL);
printf("--- Set encoding and errors ---\n");
check_stdio_details("latin-1", "replace");
check_stdio_details("iso8859-1", "replace");
/* Check calling after initialization fails */
Py_Initialize();