diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-09-05 18:13:48 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-09-05 18:13:48 (GMT) |
commit | 11946fbe804d99d26724e65dcb061cda6666c4e9 (patch) | |
tree | 33d3fac84bc13fdc95c9de2943d10641fe097a21 /Modules/_io/stringio.c | |
parent | e8677c038f94795f54de324e5d9235636c92afa0 (diff) | |
parent | 1d857453b7065dafdc34a72c1bbb2a993782b383 (diff) | |
download | cpython-11946fbe804d99d26724e65dcb061cda6666c4e9.zip cpython-11946fbe804d99d26724e65dcb061cda6666c4e9.tar.gz cpython-11946fbe804d99d26724e65dcb061cda6666c4e9.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/stringio.c')
-rw-r--r-- | Modules/_io/stringio.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c index a1c31c0..9d73884 100644 --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -760,10 +760,21 @@ stringio_init(stringio *self, PyObject *args, PyObject *kwds) } /* Properties and pseudo-properties */ + +PyDoc_STRVAR(stringio_readable_doc, +"readable() -> bool. Returns True if the IO object can be read."); + +PyDoc_STRVAR(stringio_writable_doc, +"writable() -> bool. Returns True if the IO object can be written."); + +PyDoc_STRVAR(stringio_seekable_doc, +"seekable() -> bool. Returns True if the IO object can be seeked."); + static PyObject * stringio_seekable(stringio *self, PyObject *args) { CHECK_INITIALIZED(self); + CHECK_CLOSED(self); Py_RETURN_TRUE; } @@ -771,6 +782,7 @@ static PyObject * stringio_readable(stringio *self, PyObject *args) { CHECK_INITIALIZED(self); + CHECK_CLOSED(self); Py_RETURN_TRUE; } @@ -778,6 +790,7 @@ static PyObject * stringio_writable(stringio *self, PyObject *args) { CHECK_INITIALIZED(self); + CHECK_CLOSED(self); Py_RETURN_TRUE; } @@ -956,9 +969,9 @@ static struct PyMethodDef stringio_methods[] = { {"seek", (PyCFunction)stringio_seek, METH_VARARGS, stringio_seek_doc}, {"write", (PyCFunction)stringio_write, METH_O, stringio_write_doc}, - {"seekable", (PyCFunction)stringio_seekable, METH_NOARGS}, - {"readable", (PyCFunction)stringio_readable, METH_NOARGS}, - {"writable", (PyCFunction)stringio_writable, METH_NOARGS}, + {"seekable", (PyCFunction)stringio_seekable, METH_NOARGS, stringio_seekable_doc}, + {"readable", (PyCFunction)stringio_readable, METH_NOARGS, stringio_readable_doc}, + {"writable", (PyCFunction)stringio_writable, METH_NOARGS, stringio_writable_doc}, {"__getstate__", (PyCFunction)stringio_getstate, METH_NOARGS}, {"__setstate__", (PyCFunction)stringio_setstate, METH_O}, |