mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
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').
This commit is contained in:
parent
dd071045e7
commit
c0f1a1afae
4 changed files with 48 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue