[Python-checkins] r68982 - in python/branches/release30-maint: Lib/test/test_cmd_line.py Python/pythonrun.c

antoine.pitrou python-checkins at python.org
Mon Jan 26 23:03:09 CET 2009


Author: antoine.pitrou
Date: Mon Jan 26 23:03:09 2009
New Revision: 68982

Log:
Merged revisions 68977,68981 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r68977 | antoine.pitrou | 2009-01-26 22:48:00 +0100 (lun., 26 janv. 2009) | 3 lines
  
  Followup of #4705: we can't skip the binary buffering layer for stdin because FileIO doesn't have a read1() method
........
  r68981 | antoine.pitrou | 2009-01-26 23:00:21 +0100 (lun., 26 janv. 2009) | 3 lines
  
  Fix test so as to also pass in debug mode
........


Modified:
   python/branches/release30-maint/   (props changed)
   python/branches/release30-maint/Lib/test/test_cmd_line.py
   python/branches/release30-maint/Python/pythonrun.c

Modified: python/branches/release30-maint/Lib/test/test_cmd_line.py
==============================================================================
--- python/branches/release30-maint/Lib/test/test_cmd_line.py	(original)
+++ python/branches/release30-maint/Lib/test/test_cmd_line.py	Mon Jan 26 23:03:09 2009
@@ -159,6 +159,16 @@
             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.assert_(data.startswith(b'x'), data)
+
 
 def test_main():
     test.support.run_unittest(CmdLineTest)

Modified: python/branches/release30-maint/Python/pythonrun.c
==============================================================================
--- python/branches/release30-maint/Python/pythonrun.c	(original)
+++ python/branches/release30-maint/Python/pythonrun.c	Mon Jan 26 23:03:09 2009
@@ -739,7 +739,12 @@
 	PyObject *line_buffering;
 	int buffering, isatty;
 
-	if (Py_UnbufferedStdioFlag)
+	/* stdin is always opened in buffered mode, first because it shouldn't
+	   make a difference in common use cases, 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 +758,7 @@
 	if (buf == NULL)
 		goto error;
 
-	if (!Py_UnbufferedStdioFlag) {
+	if (buffering) {
 		raw = PyObject_GetAttrString(buf, "raw");
 		if (raw == NULL)
 			goto error;


More information about the Python-checkins mailing list