mirror of
https://github.com/python/cpython.git
synced 2025-09-09 18:32:22 +00:00
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Verify that the encoding actually exists. Fixes #775985. Will backport to 2.3.
This commit is contained in:
parent
fc9b75fafb
commit
a2c17c5820
2 changed files with 51 additions and 33 deletions
|
@ -905,9 +905,6 @@ _PySys_Init(void)
|
|||
#ifdef MS_WINDOWS
|
||||
char buf[10];
|
||||
#endif
|
||||
#if defined(HAVE_LANGINFO_H) && defined(CODESET)
|
||||
char *oldloc, *codeset;
|
||||
#endif
|
||||
|
||||
m = Py_InitModule3("sys", sys_methods, sys_doc);
|
||||
sysdict = PyModule_GetDict(m);
|
||||
|
@ -930,21 +927,6 @@ _PySys_Init(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LANGINFO_H) && defined(CODESET)
|
||||
oldloc = setlocale(LC_CTYPE, 0);
|
||||
setlocale(LC_CTYPE, "");
|
||||
codeset = nl_langinfo(CODESET);
|
||||
setlocale(LC_CTYPE, oldloc);
|
||||
if(codeset && isatty(fileno(stdin))){
|
||||
if (!PyFile_SetEncoding(sysin, codeset))
|
||||
return NULL;
|
||||
}
|
||||
if(codeset && isatty(fileno(stdout))) {
|
||||
if (!PyFile_SetEncoding(sysout, codeset))
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyDict_SetItemString(sysdict, "stdin", sysin);
|
||||
PyDict_SetItemString(sysdict, "stdout", sysout);
|
||||
PyDict_SetItemString(sysdict, "stderr", syserr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue