[pypy-svn] pypy default: fix TextIOWrapper.__repr__
alex_gaynor
commits-noreply at bitbucket.org
Sun Jan 30 00:19:15 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r41466:0c59f171f3d6
Date: 2011-01-29 18:18 -0500
http://bitbucket.org/pypy/pypy/changeset/0c59f171f3d6/
Log: fix 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
@@ -277,8 +277,8 @@
# of the stream
self.snapshot = None
- @unwrap_spec('self', ObjSpace, W_Root, W_Root, W_Root, W_Root, int)
- def descr_init(self, space, w_buffer, w_encoding=None,
+ @unwrap_spec('self', ObjSpace, W_Root, "str_or_None", W_Root, W_Root, int)
+ def descr_init(self, space, w_buffer, encoding=None,
w_errors=None, w_newline=None, line_buffering=0):
self.state = STATE_ZERO
@@ -286,7 +286,7 @@
# Set encoding
self.w_encoding = None
- if space.is_w(w_encoding, space.w_None):
+ if encoding is None:
try:
w_locale = space.call_method(space.builtin, '__import__',
space.wrap("locale"))
@@ -302,8 +302,8 @@
self.w_encoding = None
if self.w_encoding:
pass
- elif not space.is_w(w_encoding, space.w_None):
- self.w_encoding = w_encoding
+ elif encoding is not None:
+ self.w_encoding = space.wrap(encoding)
else:
raise OperationError(space.w_IOError, space.wrap(
"could not determine default encoding"))
@@ -921,6 +921,7 @@
__new__ = generic_new_descr(W_TextIOWrapper),
__init__ = interp2app(W_TextIOWrapper.descr_init),
__repr__ = interp2app(W_TextIOWrapper.descr_repr),
+ __module__ = "_io",
read = interp2app(W_TextIOWrapper.read_w),
readline = interp2app(W_TextIOWrapper.readline_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
@@ -173,6 +173,8 @@
assert repr(t) == "<_io.TextIOWrapper encoding='utf-8'>"
t = _io.TextIOWrapper(_io.BytesIO(""), encoding="ascii")
assert repr(t) == "<_io.TextIOWrapper encoding='ascii'>"
+ t = _io.TextIOWrapper(_io.BytesIO(""), encoding=u"utf-8")
+ assert repr(t) == "<_io.TextIOWrapper encoding='utf-8'>"
class AppTestIncrementalNewlineDecoder:
More information about the Pypy-commit
mailing list