[pypy-svn] r79277 - in pypy/branch/fast-forward/pypy/module/_io: . test
afa at codespeak.net
afa at codespeak.net
Fri Nov 19 16:04:04 CET 2010
Author: afa
Date: Fri Nov 19 16:04:02 2010
New Revision: 79277
Modified:
pypy/branch/fast-forward/pypy/module/_io/interp_textio.py
pypy/branch/fast-forward/pypy/module/_io/test/test_textio.py
Log:
Fix a crash when underlying buffer is not readable
Modified: pypy/branch/fast-forward/pypy/module/_io/interp_textio.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/interp_textio.py (original)
+++ pypy/branch/fast-forward/pypy/module/_io/interp_textio.py Fri Nov 19 16:04:02 2010
@@ -218,6 +218,7 @@
def __init__(self, space):
W_TextIOBase.__init__(self, space)
self.state = STATE_ZERO
+ self.w_decoder = None
@unwrap_spec('self', ObjSpace, W_Root, W_Root, W_Root, W_Root, int)
def descr_init(self, space, w_buffer, w_encoding=None,
@@ -285,6 +286,10 @@
raise OperationError(space.w_ValueError, space.wrap(
"underlying buffer has been detached"))
+ def _check_closed(self, space, message=None):
+ self._check_init(space)
+ W_TextIOBase._check_closed(self, space, message)
+
@unwrap_spec('self', ObjSpace)
def readable_w(self, space):
self._check_init(space)
@@ -302,7 +307,10 @@
@unwrap_spec('self', ObjSpace, W_Root)
def read_w(self, space, w_size=None):
- self._check_init(space)
+ self._check_closed(space)
+ if not self.w_decoder:
+ raise OperationError(space.w_IOError, space.wrap("not readable"))
+
# XXX w_size?
w_bytes = space.call_method(self.w_buffer, "read")
return space.call_method(self.w_decoder, "decode", w_bytes)
Modified: pypy/branch/fast-forward/pypy/module/_io/test/test_textio.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/test/test_textio.py (original)
+++ pypy/branch/fast-forward/pypy/module/_io/test/test_textio.py Fri Nov 19 16:04:02 2010
@@ -29,6 +29,14 @@
assert t.readable()
assert t.seekable()
+ def test_unreadable(self):
+ import _io
+ class UnReadable(_io.BytesIO):
+ def readable(self):
+ return False
+ txt = _io.TextIOWrapper(UnReadable())
+ raises(IOError, txt.read)
+
def test_newlinetranslate(self):
import _io
r = _io.BytesIO(b"abc\r\ndef\rg")
More information about the Pypy-commit
mailing list