diff Python/pythonrun.c @ 37423:57b1ff138995 legacy-trunk

Bug #1421664: Set sys.stderr.encoding
author Martin v. Löwis <martin@v.loewis.de>
date Mon, 03 Apr 2006 10:56:49 +0000
parents 89142cadcfb9
children 65ecb83ea7dd
line wrap: on
line diff
--- a/Python/pythonrun.c	Mon Apr 03 08:10:33 2006 +0000
+++ b/Python/pythonrun.c	Mon Apr 03 10:56:49 2006 +0000
@@ -281,6 +281,16 @@
 		}
 		Py_XDECREF(sys_isatty);
 
+		sys_stream = PySys_GetObject("stderr");
+		sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
+		if (!sys_isatty)
+			PyErr_Clear();
+		if(sys_isatty && PyObject_IsTrue(sys_isatty)) {
+			if (!PyFile_SetEncoding(sys_stream, codeset))
+				Py_FatalError("Cannot set codeset of stderr");
+		}
+		Py_XDECREF(sys_isatty);
+
 		if (!Py_FileSystemDefaultEncoding)
 			Py_FileSystemDefaultEncoding = codeset;
 		else