[pypy-svn] pypy default: Fixed TextIOWrapper.{__repr__,name}.

alex_gaynor commits-noreply at bitbucket.org
Sun Jan 30 22:07:35 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r41476:62b4f5bfc4de
Date: 2011-01-30 16:07 -0500
http://bitbucket.org/pypy/pypy/changeset/62b4f5bfc4de/

Log:	Fixed TextIOWrapper.{__repr__,name}.

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
@@ -407,6 +407,10 @@
         self._check_init(space)
         return space.getattr(self.w_buffer, space.wrap("closed"))
 
+    def name_get_w(space, self):
+        self._check_init(space)
+        return space.getattr(self.w_buffer, space.wrap("name"))
+
     @unwrap_spec('self', ObjSpace)
     def flush_w(self, space):
         self._check_closed(space)
@@ -943,5 +947,6 @@
     writable = interp2app(W_TextIOWrapper.writable_w),
     seekable = interp2app(W_TextIOWrapper.seekable_w),
     fileno = interp2app(W_TextIOWrapper.fileno_w),
+    name = GetSetProperty(W_TextIOWrapper.name_get_w),
     closed = GetSetProperty(W_TextIOWrapper.closed_get_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
@@ -166,6 +166,13 @@
                         assert got_line == exp_line
                     assert len(got_lines) == len(exp_lines)
 
+    def test_name(self):
+        import _io
+
+        t = _io.TextIOWrapper(_io.BytesIO(""))
+        # CPython raises an AttributeError, we raise a TypeError.
+        raises((AttributeError, TypeError), setattr, t, "name", "anything")
+
     def test_repr(self):
         import _io
 
@@ -175,7 +182,9 @@
         assert repr(t) == "<_io.TextIOWrapper encoding='ascii'>"
         t = _io.TextIOWrapper(_io.BytesIO(""), encoding=u"utf-8")
         assert repr(t) == "<_io.TextIOWrapper encoding='utf-8'>"
-        t.name = "dummy"
+        b = _io.BytesIO("")
+        t = _io.TextIOWrapper(b, encoding="utf-8")
+        b.name = "dummy"
         assert repr(t) == "<_io.TextIOWrapper name='dummy' encoding='utf-8'>"
 
 


More information about the Pypy-commit mailing list