[Python-checkins] cpython: Issue #23796: peak and read1 methods of BufferedReader now raise ValueError
berker.peksag
python-checkins at python.org
Tue May 12 16:00:58 CEST 2015
https://hg.python.org/cpython/rev/41e9d324f10d
changeset: 95978:41e9d324f10d
user: Berker Peksag <berker.peksag at gmail.com>
date: Tue May 12 17:01:05 2015 +0300
summary:
Issue #23796: peak and read1 methods of BufferedReader now raise ValueError
if they called on a closed object.
Patch by John Hergenroeder.
files:
Lib/test/test_io.py | 8 ++++++++
Misc/NEWS | 3 +++
Modules/_io/bufferedio.c | 5 +++++
3 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -1191,6 +1191,14 @@
self.assertEqual(rawio._extraneous_reads, 0,
"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):
tp = io.BufferedReader
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,9 @@
Library
-------
+- Issue #23796: peak and read1 methods of BufferedReader now raise ValueError
+ if they called on a closed object. Patch by John Hergenroeder.
+
- Issue #21795: smtpd now supports the 8BITMIME extension whenever
the new *decode_data* constructor argument is set to False.
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -871,6 +871,8 @@
PyObject *res = NULL;
CHECK_INITIALIZED(self)
+ CHECK_CLOSED(self, "peek of closed file")
+
if (!ENTER_BUFFERED(self))
return NULL;
@@ -947,6 +949,9 @@
"read length must be positive");
return NULL;
}
+
+ CHECK_CLOSED(self, "read of closed file")
+
if (n == 0)
return PyBytes_FromStringAndSize(NULL, 0);
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list