summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-05-14 22:01:31 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-05-14 22:01:31 (GMT)
commit81971eafbef55f635413ed530beb4a6651c68549 (patch)
treeb4c62f8c86b55e4ba3370e7cdc34e5231c39d58e /Modules
parent37d1c18bda0e1596c465c75f8fe928400899399a (diff)
downloadcpython-81971eafbef55f635413ed530beb4a6651c68549.zip
cpython-81971eafbef55f635413ed530beb4a6651c68549.tar.gz
cpython-81971eafbef55f635413ed530beb4a6651c68549.tar.bz2
correctly handle invalid operations on streams (like writing on a non-writable one)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/textio.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 8d2a686..b78256e 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -1228,6 +1228,11 @@ TextIOWrapper_write(PyTextIOWrapperObject *self, PyObject *args)
CHECK_CLOSED(self);
+ if (self->encoder == NULL) {
+ PyErr_SetString(PyExc_IOError, "not writable");
+ return NULL;
+ }
+
Py_INCREF(text);
textlen = PyUnicode_GetSize(text);
@@ -1363,7 +1368,7 @@ TextIOWrapper_read_chunk(PyTextIOWrapperObject *self)
*/
if (self->decoder == NULL) {
- PyErr_SetString(PyExc_ValueError, "no decoder");
+ PyErr_SetString(PyExc_IOError, "not readable");
return -1;
}