]> granicus.if.org Git - python/commitdiff
ignore errors when trying to fetch sys.stdin.encoding (closes #17863)
authorBenjamin Peterson <benjamin@python.org>
Mon, 29 Apr 2013 14:23:08 +0000 (10:23 -0400)
committerBenjamin Peterson <benjamin@python.org>
Mon, 29 Apr 2013 14:23:08 +0000 (10:23 -0400)
Misc/NEWS
Python/pythonrun.c

index eced97a6deb125bf2db6b109d4037f9ef2fc87c7..0a3ef49722ba85ed373e3c37a0345513e7b396d6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 3.3.2?
 Core and Builtins
 -----------------
 
+- Issue #17863: In the interactive console, don't loop forever if the encoding
+  can't be fetched from stdin.
+
 - Issue #17867: Raise an ImportError if __import__ is not found in __builtins__.
 
 - Issue #17857: Prevent build failures with pre-3.5.0 versions of sqlite3,
index dd3201757410c92d599d9e5676e04668815e41fc..ee6071e631e54a0d1edf7433bfbb34fb6943b76b 100644 (file)
@@ -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) {