Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 47413:1062b7dec95b legacy-trunk
New environment variable PYTHONIOENCODING.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Sun, 01 Jun 2008 07:20:46 +0000 |
| parents | 4fe192d48960 |
| children | 88bd07c0a847 |
comparison
equal
deleted
inserted
replaced
| 47409:0156c336e6b3 | 47413:1062b7dec95b |
|---|---|
| 1230 _PySys_Init(void) | 1230 _PySys_Init(void) |
| 1231 { | 1231 { |
| 1232 PyObject *m, *v, *sysdict; | 1232 PyObject *m, *v, *sysdict; |
| 1233 PyObject *sysin, *sysout, *syserr; | 1233 PyObject *sysin, *sysout, *syserr; |
| 1234 char *s; | 1234 char *s; |
| 1235 #ifdef MS_WINDOWS | |
| 1236 char buf[128]; | |
| 1237 #endif | |
| 1238 | 1235 |
| 1239 m = Py_InitModule3("sys", sys_methods, sys_doc); | 1236 m = Py_InitModule3("sys", sys_methods, sys_doc); |
| 1240 if (m == NULL) | 1237 if (m == NULL) |
| 1241 return NULL; | 1238 return NULL; |
| 1242 sysdict = PyModule_GetDict(m); | 1239 sysdict = PyModule_GetDict(m); |
| 1270 sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL); | 1267 sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL); |
| 1271 sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush); | 1268 sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush); |
| 1272 syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush); | 1269 syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush); |
| 1273 if (PyErr_Occurred()) | 1270 if (PyErr_Occurred()) |
| 1274 return NULL; | 1271 return NULL; |
| 1275 #ifdef MS_WINDOWS | |
| 1276 if(isatty(_fileno(stdin)) && PyFile_Check(sysin)) { | |
| 1277 sprintf(buf, "cp%d", GetConsoleCP()); | |
| 1278 if (!PyFile_SetEncoding(sysin, buf)) | |
| 1279 return NULL; | |
| 1280 } | |
| 1281 if(isatty(_fileno(stdout)) && PyFile_Check(sysout)) { | |
| 1282 sprintf(buf, "cp%d", GetConsoleOutputCP()); | |
| 1283 if (!PyFile_SetEncoding(sysout, buf)) | |
| 1284 return NULL; | |
| 1285 } | |
| 1286 if(isatty(_fileno(stderr)) && PyFile_Check(syserr)) { | |
| 1287 sprintf(buf, "cp%d", GetConsoleOutputCP()); | |
| 1288 if (!PyFile_SetEncoding(syserr, buf)) | |
| 1289 return NULL; | |
| 1290 } | |
| 1291 #endif | |
| 1292 | 1272 |
| 1293 PyDict_SetItemString(sysdict, "stdin", sysin); | 1273 PyDict_SetItemString(sysdict, "stdin", sysin); |
| 1294 PyDict_SetItemString(sysdict, "stdout", sysout); | 1274 PyDict_SetItemString(sysdict, "stdout", sysout); |
| 1295 PyDict_SetItemString(sysdict, "stderr", syserr); | 1275 PyDict_SetItemString(sysdict, "stderr", syserr); |
| 1296 /* Make backup copies for cleanup */ | 1276 /* Make backup copies for cleanup */ |
