File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,16 @@ def test_unbuffered_output(self):
159159 self .assertEqual (data .strip (), b'x' ,
160160 "text %s not line-buffered" % stream )
161161
162+ def test_unbuffered_input (self ):
163+ # sys.stdin still works with '-u'
164+ code = ("import sys; sys.stdout.write(sys.stdin.read(1))" )
165+ p = _spawn_python ('-u' , '-c' , code )
166+ p .stdin .write (b'x' )
167+ p .stdin .flush ()
168+ data , rc = _kill_python_and_exit_code (p )
169+ self .assertEqual (rc , 0 )
170+ self .assertEqual (data .strip (), b'x' )
171+
162172
163173def test_main ():
164174 test .support .run_unittest (CmdLineTest )
Original file line number Diff line number Diff line change @@ -739,7 +739,12 @@ create_stdio(PyObject* io,
739739 PyObject * line_buffering ;
740740 int buffering , isatty ;
741741
742- if (Py_UnbufferedStdioFlag )
742+ /* stdin is always opened in buffered mode, first because it shouldn't
743+ make a difference in common use cases, second because TextIOWrapper
744+ depends on the presence of a read1() method which only exists on
745+ buffered streams.
746+ */
747+ if (Py_UnbufferedStdioFlag && write_mode )
743748 buffering = 0 ;
744749 else
745750 buffering = -1 ;
@@ -753,7 +758,7 @@ create_stdio(PyObject* io,
753758 if (buf == NULL )
754759 goto error ;
755760
756- if (! Py_UnbufferedStdioFlag ) {
761+ if (buffering ) {
757762 raw = PyObject_GetAttrString (buf , "raw" );
758763 if (raw == NULL )
759764 goto error ;
You can’t perform that action at this time.
0 commit comments