[Python-checkins] r81539 - in python/branches/release26-maint: Lib/test/test_sys.py Misc/NEWS Python/pythonrun.c
victor.stinner
python-checkins at python.org
Wed May 26 00:40:38 CEST 2010
Author: victor.stinner
Date: Wed May 26 00:40:38 2010
New Revision: 81539
Log:
Merged revisions 81537 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81537 | victor.stinner | 2010-05-26 00:30:32 +0200 (mer., 26 mai 2010) | 3 lines
Issue #3798: Write sys.exit() message to sys.stderr to use stderr encoding and
error handler, instead of writing to the C stderr file in utf-8
........
Modified:
python/branches/release26-maint/ (props changed)
python/branches/release26-maint/Lib/test/test_sys.py
python/branches/release26-maint/Misc/NEWS
python/branches/release26-maint/Python/pythonrun.c
Modified: python/branches/release26-maint/Lib/test/test_sys.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_sys.py (original)
+++ python/branches/release26-maint/Lib/test/test_sys.py Wed May 26 00:40:38 2010
@@ -173,6 +173,26 @@
"raise SystemExit(47)"])
self.assertEqual(rc, 47)
+ def check_exit_message(code, expected, env=None):
+ process = subprocess.Popen([sys.executable, "-c", code],
+ stderr=subprocess.PIPE, env=env)
+ stdout, stderr = process.communicate()
+ self.assertEqual(process.returncode, 1)
+ self.assertTrue(stderr.startswith(expected),
+ "%s doesn't start with %s" % (repr(stderr), repr(expected)))
+
+ # test that stderr buffer if flushed before the exit message is written
+ # into stderr
+ check_exit_message(
+ r'import sys; sys.stderr.write("unflushed,"); sys.exit("message")',
+ b"unflushed,message")
+
+ # test that the unicode message is encoded to the stderr encoding
+ env = os.environ.copy()
+ env['PYTHONIOENCODING'] = 'latin-1'
+ check_exit_message(
+ r'import sys; sys.exit(u"h\xe9")',
+ b"h\xe9", env=env)
def test_getdefaultencoding(self):
if test.test_support.have_unicode:
Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS (original)
+++ python/branches/release26-maint/Misc/NEWS Wed May 26 00:40:38 2010
@@ -12,6 +12,9 @@
Core and Builtins
-----------------
+- Issue #3798: Write sys.exit() message to sys.stderr to use stderr encoding
+ and error handler, instead of writing to the C stderr file in utf-8
+
- Issue #7902: When using explicit relative import syntax, don't try
implicit relative import semantics.
Modified: python/branches/release26-maint/Python/pythonrun.c
==============================================================================
--- python/branches/release26-maint/Python/pythonrun.c (original)
+++ python/branches/release26-maint/Python/pythonrun.c Wed May 26 00:40:38 2010
@@ -1111,7 +1111,13 @@
if (PyInt_Check(value))
exitcode = (int)PyInt_AsLong(value);
else {
- PyObject_Print(value, stderr, Py_PRINT_RAW);
+ PyObject *sys_stderr = PySys_GetObject("stderr");
+ if (sys_stderr != NULL && sys_stderr != Py_None) {
+ PyFile_WriteObject(value, sys_stderr, Py_PRINT_RAW);
+ } else {
+ PyObject_Print(value, stderr, Py_PRINT_RAW);
+ fflush(stderr);
+ }
PySys_WriteStderr("\n");
exitcode = 1;
}
More information about the Python-checkins
mailing list