mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-85524: Raise "UnsupportedOperation" on FileIO.readall (#141214)
io.UnsupportedOperation is a subclass of OSError and recommended by io.IOBase for this case; matches other read methods on io.FileIO.
This commit is contained in:
parent
909f76dab9
commit
6f988b08d1
4 changed files with 23 additions and 8 deletions
|
|
@ -728,6 +728,9 @@ new_buffersize(fileio *self, size_t currentsize)
|
|||
@permit_long_docstring_body
|
||||
_io.FileIO.readall
|
||||
|
||||
cls: defining_class
|
||||
/
|
||||
|
||||
Read all data from the file, returned as bytes.
|
||||
|
||||
Reads until either there is an error or read() returns size 0 (indicates EOF).
|
||||
|
|
@ -738,8 +741,8 @@ data is available (EAGAIN is returned before bytes are read) returns None.
|
|||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_io_FileIO_readall_impl(fileio *self)
|
||||
/*[clinic end generated code: output=faa0292b213b4022 input=10d8b2ec403302dc]*/
|
||||
_io_FileIO_readall_impl(fileio *self, PyTypeObject *cls)
|
||||
/*[clinic end generated code: output=d546737ec895c462 input=cecda40bf9961299]*/
|
||||
{
|
||||
Py_off_t pos, end;
|
||||
PyBytesWriter *writer;
|
||||
|
|
@ -750,6 +753,10 @@ _io_FileIO_readall_impl(fileio *self)
|
|||
if (self->fd < 0) {
|
||||
return err_closed();
|
||||
}
|
||||
if (!self->readable) {
|
||||
_PyIO_State *state = get_io_state_by_cls(cls);
|
||||
return err_mode(state, "reading");
|
||||
}
|
||||
|
||||
if (self->stat_atopen != NULL && self->stat_atopen->st_size < _PY_READ_MAX) {
|
||||
end = (Py_off_t)self->stat_atopen->st_size;
|
||||
|
|
@ -873,7 +880,7 @@ _io_FileIO_read_impl(fileio *self, PyTypeObject *cls, Py_ssize_t size)
|
|||
}
|
||||
|
||||
if (size < 0)
|
||||
return _io_FileIO_readall_impl(self);
|
||||
return _io_FileIO_readall_impl(self, cls);
|
||||
|
||||
if (size > _PY_READ_MAX) {
|
||||
size = _PY_READ_MAX;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue