summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2013-04-29 10:23:08 -0400
committerBenjamin Peterson <benjamin@python.org>2013-04-29 10:23:08 -0400
commitd322109d564f5c3e5704c110d50e14d79a11d2c3 (patch)
treee7696811c94245729673ef579a36c62464be4af0 /Python/pythonrun.c
parent8f7ad672b6efa1b4fbda720d50b60bac316fcc73 (diff)
downloadcpython-d322109d564f5c3e5704c110d50e14d79a11d2c3.tar.gz
ignore errors when trying to fetch sys.stdin.encoding (closes #17863)
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index dd32017574..ee6071e631 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1237,16 +1237,15 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags
_Py_IDENTIFIER(encoding);
if (fp == stdin) {
- /* Fetch encoding from sys.stdin */
+ /* Fetch encoding from sys.stdin if possible. */
v = PySys_GetObject("stdin");
- if (v == NULL || v == Py_None)
- return -1;
- oenc = _PyObject_GetAttrId(v, &PyId_encoding);
- if (!oenc)
- return -1;
- enc = _PyUnicode_AsString(oenc);
- if (enc == NULL)
- return -1;
+ if (v && v != Py_None) {
+ oenc = _PyObject_GetAttrId(v, &PyId_encoding);
+ if (oenc)
+ enc = _PyUnicode_AsString(oenc);
+ if (!enc)
+ PyErr_Clear();
+ }
}
v = PySys_GetObject("ps1");
if (v != NULL) {