diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/_pyio.py | 1 | ||||
-rw-r--r-- | Lib/test/test_io.py | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 654a69c..334c2b7 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -1696,6 +1696,7 @@ class TextIOWrapper(TextIOBase): return cookie def read(self, n=None): + self._checkReadable() if n is None: n = -1 decoder = self._decoder or self._get_decoder() diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index d5be405..53017f3 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -1754,6 +1754,13 @@ class TextIOWrapperTest(unittest.TestCase): 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 = "" |