summaryrefslogtreecommitdiffstats
path: root/Lib/_pyio.py
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2022-11-03 03:03:12 (GMT)
committerGitHub <noreply@github.com>2022-11-03 03:03:12 (GMT)
commit2cfcaf5af602b297fc90086de4d8ac980c7891e2 (patch)
tree530ba8bd333f6199f161af18a7f1d2d8ed569ffd /Lib/_pyio.py
parent26720fffd090929fd2058b73e5970cc520b30aef (diff)
downloadcpython-2cfcaf5af602b297fc90086de4d8ac980c7891e2.zip
cpython-2cfcaf5af602b297fc90086de4d8ac980c7891e2.tar.gz
cpython-2cfcaf5af602b297fc90086de4d8ac980c7891e2.tar.bz2
gh-98999: Raise `ValueError` in `_pyio` on closed buffers (gh-99009)
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r--Lib/_pyio.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index 1251078..163cf9d 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -1129,6 +1129,7 @@ class BufferedReader(_BufferedIOMixin):
do at most one raw read to satisfy it. We never return more
than self.buffer_size.
"""
+ self._checkClosed("peek of closed file")
with self._read_lock:
return self._peek_unlocked(size)
@@ -1147,6 +1148,7 @@ class BufferedReader(_BufferedIOMixin):
"""Reads up to size bytes, with at most one read() system call."""
# Returns up to size bytes. If at least one byte is buffered, we
# only return buffered bytes. Otherwise, we do one raw read.
+ self._checkClosed("read of closed file")
if size < 0:
size = self.buffer_size
if size == 0:
@@ -1164,6 +1166,8 @@ class BufferedReader(_BufferedIOMixin):
def _readinto(self, buf, read1):
"""Read data into *buf* with at most one system call."""
+ self._checkClosed("readinto of closed file")
+
# Need to create a memoryview object of type 'b', otherwise
# we may not be able to assign bytes to it, and slicing it
# would create a new object.
@@ -1213,6 +1217,7 @@ class BufferedReader(_BufferedIOMixin):
def seek(self, pos, whence=0):
if whence not in valid_seek_flags:
raise ValueError("invalid whence value")
+ self._checkClosed("seek of closed file")
with self._read_lock:
if whence == 1:
pos -= len(self._read_buf) - self._read_pos