summaryrefslogtreecommitdiffstats
path: root/Modules/_io/bytesio.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-09-05 18:11:49 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-09-05 18:11:49 (GMT)
commit1d857453b7065dafdc34a72c1bbb2a993782b383 (patch)
treee1ba8cd8fd1fb6d2b811e96632e8efefa97a2d51 /Modules/_io/bytesio.c
parent397e5c98bc27416fe8a407e39e4c5aa4baf94423 (diff)
downloadcpython-1d857453b7065dafdc34a72c1bbb2a993782b383.zip
cpython-1d857453b7065dafdc34a72c1bbb2a993782b383.tar.gz
cpython-1d857453b7065dafdc34a72c1bbb2a993782b383.tar.bz2
Issue #15841: The readable(), writable() and seekable() methods of BytesIO
and StringIO objects now raise ValueError when the object has been closed. Patch by Alessandro Moura.
Diffstat (limited to 'Modules/_io/bytesio.c')
-rw-r--r--Modules/_io/bytesio.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index 03f4c7d..ef951aa 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -121,7 +121,7 @@ resize_buffer(bytesio *self, size_t size)
}
/* Internal routine for writing a string of bytes to the buffer of a BytesIO
- object. Returns the number of bytes wrote, or -1 on error. */
+ object. Returns the number of bytes written, or -1 on error. */
static Py_ssize_t
write_bytes(bytesio *self, const char *bytes, Py_ssize_t len)
{
@@ -171,10 +171,20 @@ bytesio_get_closed(bytesio *self)
}
}
+PyDoc_STRVAR(readable_doc,
+"readable() -> bool. Returns True if the IO object can be read.");
+
+PyDoc_STRVAR(writable_doc,
+"writable() -> bool. Returns True if the IO object can be written.");
+
+PyDoc_STRVAR(seekable_doc,
+"seekable() -> bool. Returns True if the IO object can be seeked.");
+
/* Generic getter for the writable, readable and seekable properties */
static PyObject *
-return_true(bytesio *self)
+return_not_closed(bytesio *self)
{
+ CHECK_CLOSED(self);
Py_RETURN_TRUE;
}
@@ -867,9 +877,9 @@ static PyGetSetDef bytesio_getsetlist[] = {
};
static struct PyMethodDef bytesio_methods[] = {
- {"readable", (PyCFunction)return_true, METH_NOARGS, NULL},
- {"seekable", (PyCFunction)return_true, METH_NOARGS, NULL},
- {"writable", (PyCFunction)return_true, METH_NOARGS, NULL},
+ {"readable", (PyCFunction)return_not_closed, METH_NOARGS, readable_doc},
+ {"seekable", (PyCFunction)return_not_closed, METH_NOARGS, seekable_doc},
+ {"writable", (PyCFunction)return_not_closed, METH_NOARGS, writable_doc},
{"close", (PyCFunction)bytesio_close, METH_NOARGS, close_doc},
{"flush", (PyCFunction)bytesio_flush, METH_NOARGS, flush_doc},
{"isatty", (PyCFunction)bytesio_isatty, METH_NOARGS, isatty_doc},