Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (révision 68778) +++ Python/pythonrun.c (copie de travail) @@ -739,7 +739,11 @@ PyObject *line_buffering; int buffering, isatty; - if (Py_UnbufferedStdioFlag) + /* stdin is always opened in buffered mode, first because it shouldn't + make a difference, second because TextIOWrapper depends on the + presence of a read1() method which only exists on buffered streams. + */ + if (Py_UnbufferedStdioFlag && write_mode) buffering = 0; else buffering = -1; @@ -753,7 +757,7 @@ if (buf == NULL) goto error; - if (!Py_UnbufferedStdioFlag) { + if (buffering) { raw = PyObject_GetAttrString(buf, "raw"); if (raw == NULL) goto error; Index: Lib/test/test_cmd_line.py =================================================================== --- Lib/test/test_cmd_line.py (révision 68778) +++ Lib/test/test_cmd_line.py (copie de travail) @@ -159,7 +159,17 @@ self.assertEqual(data.strip(), b'x', "text %s not line-buffered" % stream) + def test_unbuffered_input(self): + # sys.stdin still works with '-u' + code = ("import sys; sys.stdout.write(sys.stdin.read(1))") + p = _spawn_python('-u', '-c', code) + p.stdin.write(b'x') + p.stdin.flush() + data, rc = _kill_python_and_exit_code(p) + self.assertEqual(rc, 0) + self.assertEqual(data.strip(), b'x') + def test_main(): test.support.run_unittest(CmdLineTest) test.support.reap_children()