diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2020-02-21 17:57:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-21 17:57:26 (GMT) |
commit | fd5116c0e77aec05f67fb24f10562ac920648035 (patch) | |
tree | e980fc8e6aa1ed8d62312fb17dbf01935c1e6e04 /Modules | |
parent | d4d17fd2cf69e7c8f4cd03fbf2d575370945b952 (diff) | |
download | cpython-fd5116c0e77aec05f67fb24f10562ac920648035.zip cpython-fd5116c0e77aec05f67fb24f10562ac920648035.tar.gz cpython-fd5116c0e77aec05f67fb24f10562ac920648035.tar.bz2 |
bpo-35950: Raise UnsupportedOperation in BufferedReader.truncate() (GH-18586)
The truncate() method of io.BufferedReader() should raise
UnsupportedOperation when it is called on a read-only
io.BufferedReader() instance.
https://bugs.python.org/issue35950
Automerge-Triggered-By: @methane
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_io/bufferedio.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 6f55577..a09082c 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -1315,15 +1315,19 @@ _io__Buffered_truncate_impl(buffered *self, PyObject *pos) PyObject *res = NULL; CHECK_INITIALIZED(self) + CHECK_CLOSED(self, "truncate of closed file") + if (!self->writable) { + return bufferediobase_unsupported("truncate"); + } if (!ENTER_BUFFERED(self)) return NULL; - if (self->writable) { - res = buffered_flush_and_rewind_unlocked(self); - if (res == NULL) - goto end; - Py_CLEAR(res); + res = buffered_flush_and_rewind_unlocked(self); + if (res == NULL) { + goto end; } + Py_CLEAR(res); + res = PyObject_CallMethodOneArg(self->raw, _PyIO_str_truncate, pos); if (res == NULL) goto end; |