mirror of
https://github.com/python/cpython.git
synced 2025-09-19 07:00:59 +00:00
Issue #23796: peak and read1 methods of BufferedReader now raise ValueError
if they called on a closed object. Patch by John Hergenroeder.
This commit is contained in:
parent
b9db9e152f
commit
ea6d5592f2
3 changed files with 16 additions and 0 deletions
|
@ -1115,6 +1115,14 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
|
||||||
self.assertEqual(rawio._extraneous_reads, 0,
|
self.assertEqual(rawio._extraneous_reads, 0,
|
||||||
"failed for {}: {} != 0".format(n, rawio._extraneous_reads))
|
"failed for {}: {} != 0".format(n, rawio._extraneous_reads))
|
||||||
|
|
||||||
|
def test_read_on_closed(self):
|
||||||
|
# Issue #23796
|
||||||
|
b = io.BufferedReader(io.BytesIO(b"12"))
|
||||||
|
b.read(1)
|
||||||
|
b.close()
|
||||||
|
self.assertRaises(ValueError, b.peek)
|
||||||
|
self.assertRaises(ValueError, b.read1, 1)
|
||||||
|
|
||||||
|
|
||||||
class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
|
class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
|
||||||
tp = io.BufferedReader
|
tp = io.BufferedReader
|
||||||
|
|
|
@ -45,6 +45,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #23796: peak and read1 methods of BufferedReader now raise ValueError
|
||||||
|
if they called on a closed object. Patch by John Hergenroeder.
|
||||||
|
|
||||||
- Issue #24134: assertRaises(), assertRaisesRegex(), assertWarns() and
|
- Issue #24134: assertRaises(), assertRaisesRegex(), assertWarns() and
|
||||||
assertWarnsRegex() checks are not longer successful if the callable is None.
|
assertWarnsRegex() checks are not longer successful if the callable is None.
|
||||||
|
|
||||||
|
|
|
@ -889,6 +889,8 @@ buffered_peek(buffered *self, PyObject *args)
|
||||||
PyObject *res = NULL;
|
PyObject *res = NULL;
|
||||||
|
|
||||||
CHECK_INITIALIZED(self)
|
CHECK_INITIALIZED(self)
|
||||||
|
CHECK_CLOSED(self, "peek of closed file")
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "|n:peek", &n)) {
|
if (!PyArg_ParseTuple(args, "|n:peek", &n)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -963,6 +965,9 @@ buffered_read1(buffered *self, PyObject *args)
|
||||||
"read length must be positive");
|
"read length must be positive");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHECK_CLOSED(self, "read of closed file")
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return PyBytes_FromStringAndSize(NULL, 0);
|
return PyBytes_FromStringAndSize(NULL, 0);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue