[pypy-commit] pypy py3k: update input to py3

pjenvey noreply at buildbot.pypy.org
Mon Oct 29 20:34:56 CET 2012


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r58597:0aaca88b57f4
Date: 2012-10-29 12:31 -0700
http://bitbucket.org/pypy/pypy/changeset/0aaca88b57f4/

Log:	update input to py3

diff --git a/pypy/module/__builtin__/app_io.py b/pypy/module/__builtin__/app_io.py
--- a/pypy/module/__builtin__/app_io.py
+++ b/pypy/module/__builtin__/app_io.py
@@ -13,10 +13,6 @@
         pass
     else:
         flush()
-    try:
-        stdout.softspace = 0
-    except (AttributeError, TypeError):
-        pass
 
 def input(prompt=''):
     """input([prompt]) -> string
@@ -33,11 +29,17 @@
         stdout = sys.stdout
     except AttributeError:
         raise RuntimeError("input: lost sys.stdout")
+    try:
+        stderr = sys.stderr
+    except AttributeError:
+        raise RuntimeError("input: lost sys.stderr")
+
+    stderr.flush()
 
     # hook for the readline module
     if (hasattr(sys, '__raw_input__') and
-        isinstance(stdin, file)  and stdin.fileno() == 0 and stdin.isatty() and
-        isinstance(stdout, file) and stdout.fileno() == 1):
+        stdin.fileno() == 0 and stdin.isatty() and
+        stdout.fileno() == 1):
         _write_prompt(stdout, '')
         return sys.__raw_input__(str(prompt))
 
diff --git a/pypy/module/__builtin__/test/test_rawinput.py b/pypy/module/__builtin__/test/test_rawinput.py
--- a/pypy/module/__builtin__/test/test_rawinput.py
+++ b/pypy/module/__builtin__/test/test_rawinput.py
@@ -6,6 +6,11 @@
 
     def test_input_and_raw_input(self):
         import sys, io
+        flushed = [False]
+        class CheckFlushed(io.StringIO):
+            def flush(self):
+                flushed[0] = True
+                super().flush()
         for prompt, expected in [("def:", "abc/def:/ghi\n"),
                                  ("", "abc//ghi\n"),
                                  (42, "abc/42/ghi\n"),
@@ -13,10 +18,14 @@
                                  (Ellipsis, "abc//ghi\n")]:
             for inputfn, inputtext, gottext in [
                     (input, "foo\nbar\n", "foo")]:
-                save = sys.stdin, sys.stdout
+                save = sys.stdin, sys.stdout, sys.stderr
                 try:
                     sys.stdin = io.StringIO(inputtext)
                     out = sys.stdout = io.StringIO()
+                    # Ensure that input flushes stderr
+                    flushed = [False]
+                    err = sys.stderr = CheckFlushed()
+                    sys.stderr.write('foo')
                     print("abc", end='')
                     out.write('/')
                     if prompt is Ellipsis:
@@ -26,8 +35,9 @@
                     out.write('/')
                     print("ghi")
                 finally:
-                    sys.stdin, sys.stdout = save
+                    sys.stdin, sys.stdout, sys.stderr = save
                 assert out.getvalue() == expected
+                assert flushed[0]
                 assert got == gottext
 
     def test_softspace(self):


More information about the pypy-commit mailing list