diff Python/pythonrun.c @ 83551:68d1ac152b5d 3.3

ignore errors when trying to fetch sys.stdin.encoding (closes #17863)
author Benjamin Peterson <benjamin@python.org>
date Mon, 29 Apr 2013 10:23:08 -0400
parents 215297665098
children 8c1385205a35 97522b189c79
line wrap: on
line diff
--- a/Python/pythonrun.c	Mon Apr 29 09:08:14 2013 -0400
+++ b/Python/pythonrun.c	Mon Apr 29 10:23:08 2013 -0400
@@ -1237,16 +1237,15 @@
     _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) {