mirror of https://github.com/python/cpython
bpo-44687: Ensure BufferedReader objects with unread buffers can peek even when the underlying file is closed (GH-28457)
This commit is contained in:
parent
cd760ceb67
commit
a450398933
|
@ -0,0 +1 @@
|
|||
:meth:`BufferedReader.peek` no longer raises :exc:`ValueError` when the entire file has already been buffered.
|
|
@ -341,11 +341,10 @@ _enter_buffered_busy(buffered *self)
|
|||
: buffered_closed(self)))
|
||||
|
||||
#define CHECK_CLOSED(self, error_msg) \
|
||||
if (IS_CLOSED(self)) { \
|
||||
if (IS_CLOSED(self) & (Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t) == 0)) { \
|
||||
PyErr_SetString(PyExc_ValueError, error_msg); \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
} \
|
||||
|
||||
#define VALID_READ_BUFFER(self) \
|
||||
(self->readable && self->read_end != -1)
|
||||
|
@ -530,6 +529,9 @@ buffered_close(buffered *self, PyObject *args)
|
|||
Py_CLEAR(res);
|
||||
}
|
||||
|
||||
self->read_end = 0;
|
||||
self->pos = 0;
|
||||
|
||||
end:
|
||||
LEAVE_BUFFERED(self)
|
||||
return res;
|
||||
|
|
Loading…
Reference in New Issue