summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-08-03 23:37:32 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2012-08-03 23:37:32 (GMT)
commit90ef747e04ee586ef475b8ef03d3548e5059b105 (patch)
tree2be3b143ad927947a40c287a2b47234a035162da
parent401e17d0f06dd6594835424c5544689abdc0cc9f (diff)
downloadcpython-90ef747e04ee586ef475b8ef03d3548e5059b105.zip
cpython-90ef747e04ee586ef475b8ef03d3548e5059b105.tar.gz
cpython-90ef747e04ee586ef475b8ef03d3548e5059b105.tar.bz2
Close #13119: use "\r\n" newline for sys.stdout/err on Windows
sys.stdout and sys.stderr are now using "\r\n" newline on Windows, as Python 2.
-rw-r--r--Lib/test/test_cmd_line.py17
-rw-r--r--Misc/NEWS3
-rw-r--r--Python/pythonrun.c13
3 files changed, 28 insertions, 5 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 1a21281..f463af4 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -265,6 +265,23 @@ class CmdLineTest(unittest.TestCase):
"print(repr(input()))",
b"'abc'")
+ def test_output_newline(self):
+ # Issue 13119 Newline for print() should be \r\n on Windows.
+ code = """if 1:
+ import sys
+ print(1)
+ print(2)
+ print(3, file=sys.stderr)
+ print(4, file=sys.stderr)"""
+ rc, out, err = assert_python_ok('-c', code)
+
+ if sys.platform == 'win32':
+ self.assertEqual(b'1\r\n2\r\n', out)
+ self.assertEqual(b'3\r\n4', err)
+ else:
+ self.assertEqual(b'1\n2\n', out)
+ self.assertEqual(b'3\n4', err)
+
def test_unmached_quote(self):
# Issue #10206: python program starting with unmatched quote
# spewed spaces to stdout
diff --git a/Misc/NEWS b/Misc/NEWS
index d5e3113..dbaf864 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
Core and Builtins
-----------------
+- Issue #13119: sys.stdout and sys.stderr are now using "\r\n" newline on
+ Windows, as Python 2.
+
- Issue #14579: Fix CVE-2012-2135: vulnerability in the utf-16 decoder after
error handling. Patch by Serhiy Storchaka.
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 4609468..cf4e34c 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -870,12 +870,15 @@ create_stdio(PyObject* io,
Py_CLEAR(raw);
Py_CLEAR(text);
- newline = "\n";
#ifdef MS_WINDOWS
- if (!write_mode) {
- /* translate \r\n to \n for sys.stdin on Windows */
- newline = NULL;
- }
+ /* sys.stdin: enable universal newline mode, translate "\r\n" and "\r"
+ newlines to "\n".
+ sys.stdout and sys.stderr: translate "\n" to "\r\n". */
+ newline = NULL;
+#else
+ /* sys.stdin: split lines at "\n".
+ sys.stdout and sys.stderr: don't translate newlines (use "\n"). */
+ newline = "\n";
#endif
stream = PyObject_CallMethod(io, "TextIOWrapper", "OsssO",