diff Python/pythonrun.c @ 67996:32386fa67a12 3.2

Merged revisions 88530 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r88530 | victor.stinner | 2011-02-23 13:07:37 +0100 (mer., 23 févr. 2011) | 4 lines Issue #11272: Fix input() and sys.stdin for Windows newline On Windows, input() strips '\r' (and not only '\n'), and sys.stdin uses universal newline (replace '\r\n' by '\n'). ........
author Victor Stinner <victor.stinner@haypocalc.com>
date Wed, 23 Feb 2011 12:10:23 +0000
parents aba16a5683d3
children 3c9232a684ae
line wrap: on
line diff
--- a/Python/pythonrun.c	Wed Feb 23 11:52:31 2011 +0000
+++ b/Python/pythonrun.c	Wed Feb 23 12:10:23 2011 +0000
@@ -778,6 +778,7 @@
 {
     PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL, *res;
     const char* mode;
+    const char* newline;
     PyObject *line_buffering;
     int buffering, isatty;
 
@@ -828,9 +829,17 @@
     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;
+    }
+#endif
+
     stream = PyObject_CallMethod(io, "TextIOWrapper", "OsssO",
                                  buf, encoding, errors,
-                                 "\n", line_buffering);
+                                 newline, line_buffering);
     Py_CLEAR(buf);
     if (stream == NULL)
         goto error;