Mercurial > cpython-lru_cache-weakref
diff Python/pythonrun.c @ 47444:bb2c4bdc3c68
Forward-port PYTHONIOENCODING.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Mon, 02 Jun 2008 11:13:03 +0000 |
| parents | 23ab586c427a |
| children | b6b534b828b3 |
line wrap: on
line diff
--- a/Python/pythonrun.c Mon Jun 02 10:08:54 2008 +0000 +++ b/Python/pythonrun.c Mon Jun 02 11:13:03 2008 +0000 @@ -701,6 +701,7 @@ PyObject *std = NULL; int status = 0, fd; PyObject * encoding_attr; + char *encoding, *errors; /* Hack to avoid a nasty recursion issue when Python is invoked in verbose mode: pre-import the Latin-1 and UTF-8 codecs */ @@ -730,6 +731,16 @@ goto error; } + encoding = Py_GETENV("PYTHONIOENCODING"); + if (encoding) { + encoding = strdup(encoding); + errors = strchr(encoding, ':'); + if (errors) { + *errors = '\0'; + errors++; + } + } + /* Set sys.stdin */ fd = fileno(stdin); /* Under some conditions stdin, stdout and stderr may not be connected @@ -745,8 +756,8 @@ #endif } else { - if (!(std = PyFile_FromFd(fd, "<stdin>", "r", -1, NULL, NULL, - "\n", 0))) { + if (!(std = PyFile_FromFd(fd, "<stdin>", "r", -1, encoding, + errors, "\n", 0))) { goto error; } } /* if (fd < 0) */ @@ -765,8 +776,8 @@ #endif } else { - if (!(std = PyFile_FromFd(fd, "<stdout>", "w", -1, NULL, NULL, - "\n", 0))) { + if (!(std = PyFile_FromFd(fd, "<stdout>", "w", -1, encoding, + errors, "\n", 0))) { goto error; } } /* if (fd < 0) */ @@ -786,8 +797,8 @@ #endif } else { - if (!(std = PyFile_FromFd(fd, "<stderr>", "w", -1, NULL, NULL, - "\n", 0))) { + if (!(std = PyFile_FromFd(fd, "<stderr>", "w", -1, encoding, + errors, "\n", 0))) { goto error; } } /* if (fd < 0) */
