mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
gh-98999: Raise ValueError in _pyio on closed buffers (gh-99009)
This commit is contained in:
parent
26720fffd0
commit
2cfcaf5af6
3 changed files with 33 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue