Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/test/test_io/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def test_invalid_operations(self):
self.assertRaises(exc, fp.readline)
with self.open(os_helper.TESTFN, "wb", buffering=0) as fp:
self.assertRaises(exc, fp.read)
self.assertRaises(exc, fp.readall)
self.assertRaises(exc, fp.readline)
with self.open(os_helper.TESTFN, "rb", buffering=0) as fp:
self.assertRaises(exc, fp.write, b"blah")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Update ``io.FileIO.readall``, an implementation of :meth:`io.RawIOBase.readall`,
to follow :class:`io.IOBase` guidelines and raise :exc:`io.UnsupportedOperation`
when a file is in "w" mode rather than :exc:`OSError`
14 changes: 9 additions & 5 deletions Modules/_io/clinic/fileio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions Modules/_io/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading