Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 30109:fb2abca2d2d5 2.3
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Verify that the encoding actually exists. Fixes #775985.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Sat, 09 Aug 2003 09:48:29 +0000 |
| parents | e9e5832d706f |
| children | 8c9e3ed594fe 1c117dbb2def |
comparison
equal
deleted
inserted
replaced
| 30107:616a8c0cc917 | 30109:fb2abca2d2d5 |
|---|---|
| 903 PyObject *sysin, *sysout, *syserr; | 903 PyObject *sysin, *sysout, *syserr; |
| 904 char *s; | 904 char *s; |
| 905 #ifdef MS_WINDOWS | 905 #ifdef MS_WINDOWS |
| 906 char buf[10]; | 906 char buf[10]; |
| 907 #endif | 907 #endif |
| 908 #if defined(HAVE_LANGINFO_H) && defined(CODESET) | |
| 909 char *oldloc, *codeset; | |
| 910 #endif | |
| 911 | 908 |
| 912 m = Py_InitModule3("sys", sys_methods, sys_doc); | 909 m = Py_InitModule3("sys", sys_methods, sys_doc); |
| 913 sysdict = PyModule_GetDict(m); | 910 sysdict = PyModule_GetDict(m); |
| 914 | 911 |
| 915 sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL); | 912 sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL); |
| 928 if (!PyFile_SetEncoding(sysout, buf)) | 925 if (!PyFile_SetEncoding(sysout, buf)) |
| 929 return NULL; | 926 return NULL; |
| 930 } | 927 } |
| 931 #endif | 928 #endif |
| 932 | 929 |
| 933 #if defined(HAVE_LANGINFO_H) && defined(CODESET) | |
| 934 oldloc = setlocale(LC_CTYPE, 0); | |
| 935 setlocale(LC_CTYPE, ""); | |
| 936 codeset = nl_langinfo(CODESET); | |
| 937 setlocale(LC_CTYPE, oldloc); | |
| 938 if(codeset && isatty(fileno(stdin))){ | |
| 939 if (!PyFile_SetEncoding(sysin, codeset)) | |
| 940 return NULL; | |
| 941 } | |
| 942 if(codeset && isatty(fileno(stdout))) { | |
| 943 if (!PyFile_SetEncoding(sysout, codeset)) | |
| 944 return NULL; | |
| 945 } | |
| 946 #endif | |
| 947 | |
| 948 PyDict_SetItemString(sysdict, "stdin", sysin); | 930 PyDict_SetItemString(sysdict, "stdin", sysin); |
| 949 PyDict_SetItemString(sysdict, "stdout", sysout); | 931 PyDict_SetItemString(sysdict, "stdout", sysout); |
| 950 PyDict_SetItemString(sysdict, "stderr", syserr); | 932 PyDict_SetItemString(sysdict, "stderr", syserr); |
| 951 /* Make backup copies for cleanup */ | 933 /* Make backup copies for cleanup */ |
| 952 PyDict_SetItemString(sysdict, "__stdin__", sysin); | 934 PyDict_SetItemString(sysdict, "__stdin__", sysin); |
