diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-09-05 18:13:48 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-09-05 18:13:48 (GMT) |
commit | 11946fbe804d99d26724e65dcb061cda6666c4e9 (patch) | |
tree | 33d3fac84bc13fdc95c9de2943d10641fe097a21 /Lib | |
parent | e8677c038f94795f54de324e5d9235636c92afa0 (diff) | |
parent | 1d857453b7065dafdc34a72c1bbb2a993782b383 (diff) | |
download | cpython-11946fbe804d99d26724e65dcb061cda6666c4e9.zip cpython-11946fbe804d99d26724e65dcb061cda6666c4e9.tar.gz cpython-11946fbe804d99d26724e65dcb061cda6666c4e9.tar.bz2 |
Issue #15841: The readable(), writable() and seekable() methods of BytesIO
and StringIO objects now raise ValueError when the object has been closed.
Patch by Alessandro Moura.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/_pyio.py | 8 | ||||
-rw-r--r-- | Lib/test/test_memoryio.py | 7 |
2 files changed, 11 insertions, 4 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 387c585..fa77ec1 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -895,12 +895,18 @@ class BytesIO(BufferedIOBase): return pos def readable(self): + if self.closed: + raise ValueError("I/O operation on closed file.") return True def writable(self): + if self.closed: + raise ValueError("I/O operation on closed file.") return True def seekable(self): + if self.closed: + raise ValueError("I/O operation on closed file.") return True @@ -1562,6 +1568,8 @@ class TextIOWrapper(TextIOBase): return self._buffer def seekable(self): + if self.closed: + raise ValueError("I/O operation on closed file.") return self._seekable def readable(self): diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py index 04ec8e7..e5db945 100644 --- a/Lib/test/test_memoryio.py +++ b/Lib/test/test_memoryio.py @@ -318,9 +318,9 @@ class MemoryTestMixin: self.assertEqual(memio.isatty(), False) self.assertEqual(memio.closed, False) memio.close() - self.assertEqual(memio.writable(), True) - self.assertEqual(memio.readable(), True) - self.assertEqual(memio.seekable(), True) + self.assertRaises(ValueError, memio.writable) + self.assertRaises(ValueError, memio.readable) + self.assertRaises(ValueError, memio.seekable) self.assertRaises(ValueError, memio.isatty) self.assertEqual(memio.closed, True) @@ -665,7 +665,6 @@ class CBytesIOTest(PyBytesIOTest): check(io.BytesIO(b'a'), basesize + 1 + 1 ) check(io.BytesIO(b'a' * 1000), basesize + 1000 + 1 ) - class CStringIOTest(PyStringIOTest): ioclass = io.StringIO UnsupportedOperation = io.UnsupportedOperation |