summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-02-23 12:07:37 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-02-23 12:07:37 (GMT)
commitc0f1a1afae3843986eb0bef54b165424361f2510 (patch)
treec650a798108af5024bcee2c01ae8f67586c952c8 /Python/pythonrun.c
parentdd071045e776e1c3e8cf6750a2fd1d0958bf19b3 (diff)
downloadcpython-c0f1a1afae3843986eb0bef54b165424361f2510.zip
cpython-c0f1a1afae3843986eb0bef54b165424361f2510.tar.gz
cpython-c0f1a1afae3843986eb0bef54b165424361f2510.tar.bz2
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').
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 33f1873..8e97d7f 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -778,6 +778,7 @@ create_stdio(PyObject* io,
{
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 @@ 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;
+ }
+#endif
+
stream = PyObject_CallMethod(io, "TextIOWrapper", "OsssO",
buf, encoding, errors,
- "\n", line_buffering);
+ newline, line_buffering);
Py_CLEAR(buf);
if (stream == NULL)
goto error;