mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
encoding and surrogateespace error handler instead of the locale encoding to be consistent with os.environ. Add PySys_AddWarnOptionUnicode() function.
This commit is contained in:
parent
a5bf3f520c
commit
9ca9c25bcd
5 changed files with 27 additions and 12 deletions
|
@ -425,7 +425,7 @@ Py_Main(int argc, wchar_t **argv)
|
|||
#else
|
||||
if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') {
|
||||
char *buf, *oldloc;
|
||||
wchar_t *warning;
|
||||
PyObject *warning;
|
||||
|
||||
/* settle for strtok here as there's no one standard
|
||||
C89 wcstok */
|
||||
|
@ -437,9 +437,10 @@ Py_Main(int argc, wchar_t **argv)
|
|||
oldloc = strdup(setlocale(LC_ALL, NULL));
|
||||
setlocale(LC_ALL, "");
|
||||
for (p = strtok(buf, ","); p != NULL; p = strtok(NULL, ",")) {
|
||||
if ((warning = _Py_char2wchar(p)) != NULL) {
|
||||
PySys_AddWarnOption(warning);
|
||||
PyMem_Free(warning);
|
||||
warning = PyUnicode_DecodeFSDefault(p);
|
||||
if (warning != NULL) {
|
||||
PySys_AddWarnOptionUnicode(warning);
|
||||
Py_DECREF(warning);
|
||||
}
|
||||
}
|
||||
setlocale(LC_ALL, oldloc);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue