Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r57961:1c9014214660 Date: 2012-10-09 17:53 -0700 http://bitbucket.org/pypy/pypy/changeset/1c9014214660/
Log: add mode to TextIOWrapper repr 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 @@ -441,15 +441,18 @@ self._check_init(space) W_TextIOBase._check_closed(self, space, message) + def __w_attr_repr(self, space, name): + w_attr = space.findattr(self, space.wrap(name)) + if w_attr is None: + return space.wrap("") + return space.mod(space.wrap("%s=%%r " % name), w_attr) + def descr_repr(self, space): - w_name = space.findattr(self, space.wrap("name")) - if w_name is None: - w_name_str = space.wrap("") - else: - w_name_str = space.mod(space.wrap("name=%r "), w_name) - w_args = space.newtuple([w_name_str, self.w_encoding]) + w_args = space.newtuple([self.__w_attr_repr(space, 'name'), + self.__w_attr_repr(space, 'mode'), + self.w_encoding]) return space.mod( - space.wrap("<_io.TextIOWrapper %sencoding=%r>"), w_args + space.wrap("<_io.TextIOWrapper %s%sencoding=%r>"), w_args ) def isatty_w(self, space): 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 @@ -209,6 +209,10 @@ t = _io.TextIOWrapper(b, encoding="utf-8") b.name = "dummy" assert repr(t) == "<_io.TextIOWrapper name='dummy' encoding='utf-8'>" + t.mode = "r" + assert repr(t) == "<_io.TextIOWrapper name='dummy' mode='r' encoding='utf-8'>" + b.name = b"dummy" + assert repr(t) == "<_io.TextIOWrapper name=b'dummy' mode='r' encoding='utf-8'>" def test_rawio(self): # Issue #12591: TextIOWrapper must work with raw I/O objects, so _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit