summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/pythonrun.c9
-rw-r--r--Python/sysmodule.c6
2 files changed, 9 insertions, 6 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 634572e..98ae115 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -275,7 +275,8 @@ Py_InitializeEx(int install_sigs)
sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
if (!sys_isatty)
PyErr_Clear();
- if(sys_isatty && PyObject_IsTrue(sys_isatty)) {
+ if(sys_isatty && PyObject_IsTrue(sys_isatty) &&
+ PyFile_Check(sys_stream)) {
if (!PyFile_SetEncoding(sys_stream, codeset))
Py_FatalError("Cannot set codeset of stdin");
}
@@ -285,7 +286,8 @@ Py_InitializeEx(int install_sigs)
sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
if (!sys_isatty)
PyErr_Clear();
- if(sys_isatty && PyObject_IsTrue(sys_isatty)) {
+ if(sys_isatty && PyObject_IsTrue(sys_isatty) &&
+ PyFile_Check(sys_stream)) {
if (!PyFile_SetEncoding(sys_stream, codeset))
Py_FatalError("Cannot set codeset of stdout");
}
@@ -295,7 +297,8 @@ Py_InitializeEx(int install_sigs)
sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
if (!sys_isatty)
PyErr_Clear();
- if(sys_isatty && PyObject_IsTrue(sys_isatty)) {
+ if(sys_isatty && PyObject_IsTrue(sys_isatty) &&
+ PyFile_Check(sys_stream)) {
if (!PyFile_SetEncoding(sys_stream, codeset))
Py_FatalError("Cannot set codeset of stderr");
}
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 4970adf..59f6cfc 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1087,17 +1087,17 @@ _PySys_Init(void)
if (PyErr_Occurred())
return NULL;
#ifdef MS_WINDOWS
- if(isatty(_fileno(stdin))){
+ if(isatty(_fileno(stdin)) && PyFile_Check(sysin)) {
sprintf(buf, "cp%d", GetConsoleCP());
if (!PyFile_SetEncoding(sysin, buf))
return NULL;
}
- if(isatty(_fileno(stdout))) {
+ if(isatty(_fileno(stdout)) && PyFile_Check(sysout)) {
sprintf(buf, "cp%d", GetConsoleOutputCP());
if (!PyFile_SetEncoding(sysout, buf))
return NULL;
}
- if(isatty(_fileno(stderr))) {
+ if(isatty(_fileno(stderr)) && PyFile_Check(syserr)) {
sprintf(buf, "cp%d", GetConsoleOutputCP());
if (!PyFile_SetEncoding(syserr, buf))
return NULL;