[pypy-commit] pypy py3k: Correctly implement isatty() on text files.

amauryfa noreply at buildbot.pypy.org
Sat Oct 22 00:28:39 CEST 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r48332:c4c393a85de6
Date: 2011-10-22 00:24 +0200
http://bitbucket.org/pypy/pypy/changeset/c4c393a85de6/

Log:	Correctly implement isatty() on text files. Important for the
	interactive mode!

diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -448,6 +448,10 @@
             space.wrap("<_io.TextIOWrapper %sencoding=%r>"), w_args
         )
 
+    def isatty_w(self, space):
+        self._check_init(space)
+        return space.call_method(self.w_buffer, "isatty")
+
     def readable_w(self, space):
         self._check_init(space)
         return space.call_method(self.w_buffer, "readable")
@@ -993,6 +997,7 @@
     close = interp2app(W_TextIOWrapper.close_w),
 
     line_buffering = interp_attrproperty("line_buffering", W_TextIOWrapper),
+    isatty = interp2app(W_TextIOWrapper.isatty_w),
     readable = interp2app(W_TextIOWrapper.readable_w),
     writable = interp2app(W_TextIOWrapper.writable_w),
     seekable = interp2app(W_TextIOWrapper.seekable_w),
diff --git a/pypy/module/_io/test/test_textio.py b/pypy/module/_io/test/test_textio.py
--- a/pypy/module/_io/test/test_textio.py
+++ b/pypy/module/_io/test/test_textio.py
@@ -29,6 +29,14 @@
         assert t.readable()
         assert t.seekable()
 
+    def test_isatty(self):
+        import _io
+        class Tty(_io.BytesIO):
+            def isatty(self):
+                return True
+        txt = _io.TextIOWrapper(Tty())
+        assert txt.isatty()
+
     def test_unreadable(self):
         import _io
         class UnReadable(_io.BytesIO):


More information about the pypy-commit mailing list