diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2008-06-02 11:13:03 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2008-06-02 11:13:03 (GMT) |
commit | 0f5998911c0a39400a42bad781e84eba822fed38 (patch) | |
tree | 0734e865de7015c126a4cfce5c0507f863a89a71 /Python | |
parent | e95593e9b1498843b403d20f956a0eac9d3b4cc0 (diff) | |
download | cpython-0f5998911c0a39400a42bad781e84eba822fed38.zip cpython-0f5998911c0a39400a42bad781e84eba822fed38.tar.gz cpython-0f5998911c0a39400a42bad781e84eba822fed38.tar.bz2 |
Forward-port PYTHONIOENCODING.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pythonrun.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 2e93a3a..f2f14ed 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -701,6 +701,7 @@ initstdio(void) 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 @@ initstdio(void) 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 @@ initstdio(void) #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 @@ initstdio(void) #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 @@ initstdio(void) #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) */ |