Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r58755:dc70da613d27
Date: 2012-10-27 23:19 +0200
http://bitbucket.org/pypy/pypy/changeset/dc70da613d27/

Log:    Ensure that sys.stdout &co have a "mode" attribute.

diff --git a/pypy/translator/goal/app_main.py b/pypy/translator/goal/app_main.py
--- a/pypy/translator/goal/app_main.py
+++ b/pypy/translator/goal/app_main.py
@@ -290,6 +290,10 @@
     stream = io.TextIOWrapper(buf, encoding, errors,
                               newline=newline,
                               line_buffering=line_buffering)
+    if writing:
+        stream.mode = 'w'
+    else:
+        stream.mode = 'r'
     return stream
 
 
diff --git a/pypy/translator/goal/test2/test_app_main.py 
b/pypy/translator/goal/test2/test_app_main.py
--- a/pypy/translator/goal/test2/test_app_main.py
+++ b/pypy/translator/goal/test2/test_app_main.py
@@ -446,6 +446,14 @@
         child.expect('789')    # expect to see it before the timeout hits
         child.sendline('X')
 
+    def test_file_modes(self):
+        child = self.spawn(['-c', 'import sys; print(sys.stdout.mode)'])
+        child.expect('w')
+        child = self.spawn(['-c', 'import sys; print(sys.stderr.mode)'])
+        child.expect('w')
+        child = self.spawn(['-c', 'import sys; print(sys.stdin.mode)'])
+        child.expect('r')
+
     def test_options_i_m(self):
         if sys.platform == "win32":
             skip("close_fds is not supported on Windows platforms")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to