From: Martin v. Löwis Date: Mon, 3 Apr 2006 10:56:49 +0000 (+0000) Subject: Bug #1421664: Set sys.stderr.encoding X-Git-Tag: v2.5a1~55 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea62d2535f6160d5b4306ea060f5da05cfa7e9ab;p=thirdparty%2FPython%2Fcpython.git Bug #1421664: Set sys.stderr.encoding --- diff --git a/Misc/NEWS b/Misc/NEWS index cb99814e04be..70ed7cacedce 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 2.5 alpha 1? Core and builtins ----------------- +- Bug #1421664: sys.stderr.encoding is now set to the same value as + sys.stdout.encoding. + - __import__ accepts keyword arguments. - Patch #1460496: round() now accepts keyword arguments. diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 4c8c5176e526..1aa6930435a7 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -281,6 +281,16 @@ Py_InitializeEx(int install_sigs) } 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 diff --git a/Python/sysmodule.c b/Python/sysmodule.c index dfa6ac84d91f..4a527424c4a1 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1069,6 +1069,11 @@ _PySys_Init(void) if (!PyFile_SetEncoding(sysout, buf)) return NULL; } + if(isatty(_fileno(stderr))) { + sprintf(buf, "cp%d", GetConsoleOutputCP()); + if (!PyFile_SetEncoding(syserr, buf)) + return NULL; + } #endif PyDict_SetItemString(sysdict, "stdin", sysin);