r70928 - in python/branches/py3k: Lib/_pyio.py Lib/test/test_io.py Misc/NEWS Modules/_textio.c
Author: benjamin.peterson Date: Wed Apr 1 01:11:32 2009 New Revision: 70928 Log: fix TextIOWrapper.read() when the buffer is not readable #5628 Modified: python/branches/py3k/Lib/_pyio.py python/branches/py3k/Lib/test/test_io.py python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/_textio.c Modified: python/branches/py3k/Lib/_pyio.py ============================================================================== --- python/branches/py3k/Lib/_pyio.py (original) +++ python/branches/py3k/Lib/_pyio.py Wed Apr 1 01:11:32 2009 @@ -1696,6 +1696,7 @@ return cookie def read(self, n=None): + self._checkReadable() if n is None: n = -1 decoder = self._decoder or self._get_decoder() Modified: python/branches/py3k/Lib/test/test_io.py ============================================================================== --- python/branches/py3k/Lib/test/test_io.py (original) +++ python/branches/py3k/Lib/test/test_io.py Wed Apr 1 01:11:32 2009 @@ -1754,6 +1754,13 @@ self.assertEquals(f.read(), data * 2) self.assertEquals(buf.getvalue(), (data * 2).encode(encoding)) + def test_unreadable(self): + class UnReadable(self.BytesIO): + def readable(self): + return False + txt = self.TextIOWrapper(UnReadable()) + self.assertRaises(IOError, txt.read) + def test_read_one_by_one(self): txt = self.TextIOWrapper(self.BytesIO(b"AA\r\nBB")) reads = "" Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Apr 1 01:11:32 2009 @@ -53,6 +53,8 @@ Library ------- +- Issue #5628: Fix io.TextIOWrapper.read() with a unreadable buffer. + - Issue #5619: Multiprocessing children disobey the debug flag and causes popups on windows buildbots. Patch applied to work around this issue. Modified: python/branches/py3k/Modules/_textio.c ============================================================================== --- python/branches/py3k/Modules/_textio.c (original) +++ python/branches/py3k/Modules/_textio.c Wed Apr 1 01:11:32 2009 @@ -1348,6 +1348,11 @@ CHECK_CLOSED(self); + if (self->decoder == NULL) { + PyErr_SetString(PyExc_IOError, "not readable"); + return NULL; + } + if (_TextIOWrapper_writeflush(self) < 0) return NULL;
participants (1)
-
benjamin.peterson