Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 68118:aba16a5683d3
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:07:37 +0000 |
| parents | 3bf4d9f1660a |
| children | 3c9232a684ae |
comparison
equal
deleted
inserted
replaced
| 68117:2325fe36aa34 | 68118:aba16a5683d3 |
|---|---|
| 776 int fd, int write_mode, char* name, | 776 int fd, int write_mode, char* name, |
| 777 char* encoding, char* errors) | 777 char* encoding, char* errors) |
| 778 { | 778 { |
| 779 PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL, *res; | 779 PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL, *res; |
| 780 const char* mode; | 780 const char* mode; |
| 781 const char* newline; | |
| 781 PyObject *line_buffering; | 782 PyObject *line_buffering; |
| 782 int buffering, isatty; | 783 int buffering, isatty; |
| 783 | 784 |
| 784 /* stdin is always opened in buffered mode, first because it shouldn't | 785 /* stdin is always opened in buffered mode, first because it shouldn't |
| 785 make a difference in common use cases, second because TextIOWrapper | 786 make a difference in common use cases, second because TextIOWrapper |
| 826 line_buffering = Py_False; | 827 line_buffering = Py_False; |
| 827 | 828 |
| 828 Py_CLEAR(raw); | 829 Py_CLEAR(raw); |
| 829 Py_CLEAR(text); | 830 Py_CLEAR(text); |
| 830 | 831 |
| 832 newline = "\n"; | |
| 833 #ifdef MS_WINDOWS | |
| 834 if (!write_mode) { | |
| 835 /* translate \r\n to \n for sys.stdin on Windows */ | |
| 836 newline = NULL; | |
| 837 } | |
| 838 #endif | |
| 839 | |
| 831 stream = PyObject_CallMethod(io, "TextIOWrapper", "OsssO", | 840 stream = PyObject_CallMethod(io, "TextIOWrapper", "OsssO", |
| 832 buf, encoding, errors, | 841 buf, encoding, errors, |
| 833 "\n", line_buffering); | 842 newline, line_buffering); |
| 834 Py_CLEAR(buf); | 843 Py_CLEAR(buf); |
| 835 if (stream == NULL) | 844 if (stream == NULL) |
| 836 goto error; | 845 goto error; |
| 837 | 846 |
| 838 if (write_mode) | 847 if (write_mode) |
