summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/fileio.c3
-rw-r--r--Modules/_io/iobase.c6
-rw-r--r--Modules/_io/textio.c26
3 files changed, 14 insertions, 21 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 4f450da..ff278cf 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -417,7 +417,8 @@ err_closed(void)
static PyObject *
err_mode(char *action)
{
- PyErr_Format(PyExc_ValueError, "File not open for %s", action);
+ PyErr_Format(IO_STATE->unsupported_operation,
+ "File not open for %s", action);
return NULL;
}
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index 2d664ab..6521ae2 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -317,7 +317,7 @@ _PyIOBase_check_seekable(PyObject *self, PyObject *args)
return NULL;
if (res != Py_True) {
Py_CLEAR(res);
- PyErr_SetString(PyExc_IOError, "File or stream is not seekable.");
+ iobase_unsupported("File or stream is not seekable.");
return NULL;
}
if (args == Py_True) {
@@ -346,7 +346,7 @@ _PyIOBase_check_readable(PyObject *self, PyObject *args)
return NULL;
if (res != Py_True) {
Py_CLEAR(res);
- PyErr_SetString(PyExc_IOError, "File or stream is not readable.");
+ iobase_unsupported("File or stream is not readable.");
return NULL;
}
if (args == Py_True) {
@@ -375,7 +375,7 @@ _PyIOBase_check_writable(PyObject *self, PyObject *args)
return NULL;
if (res != Py_True) {
Py_CLEAR(res);
- PyErr_SetString(PyExc_IOError, "File or stream is not writable.");
+ iobase_unsupported("File or stream is not writable.");
return NULL;
}
if (args == Py_True) {
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index b659795..08827b9 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -1259,10 +1259,8 @@ textiowrapper_write(textio *self, PyObject *args)
CHECK_CLOSED(self);
- if (self->encoder == NULL) {
- PyErr_SetString(PyExc_IOError, "not writable");
- return NULL;
- }
+ if (self->encoder == NULL)
+ return _unsupported("not writable");
Py_INCREF(text);
@@ -1399,7 +1397,7 @@ textiowrapper_read_chunk(textio *self)
*/
if (self->decoder == NULL) {
- PyErr_SetString(PyExc_IOError, "not readable");
+ _unsupported("not readable");
return -1;
}
@@ -1489,10 +1487,8 @@ textiowrapper_read(textio *self, PyObject *args)
CHECK_CLOSED(self);
- if (self->decoder == NULL) {
- PyErr_SetString(PyExc_IOError, "not readable");
- return NULL;
- }
+ if (self->decoder == NULL)
+ return _unsupported("not readable");
if (_textiowrapper_writeflush(self) < 0)
return NULL;
@@ -1983,8 +1979,7 @@ textiowrapper_seek(textio *self, PyObject *args)
Py_INCREF(cookieObj);
if (!self->seekable) {
- PyErr_SetString(PyExc_IOError,
- "underlying stream is not seekable");
+ _unsupported("underlying stream is not seekable");
goto fail;
}
@@ -1995,8 +1990,7 @@ textiowrapper_seek(textio *self, PyObject *args)
goto fail;
if (cmp == 0) {
- PyErr_SetString(PyExc_IOError,
- "can't do nonzero cur-relative seeks");
+ _unsupported("can't do nonzero cur-relative seeks");
goto fail;
}
@@ -2016,8 +2010,7 @@ textiowrapper_seek(textio *self, PyObject *args)
goto fail;
if (cmp == 0) {
- PyErr_SetString(PyExc_IOError,
- "can't do nonzero end-relative seeks");
+ _unsupported("can't do nonzero end-relative seeks");
goto fail;
}
@@ -2151,8 +2144,7 @@ textiowrapper_tell(textio *self, PyObject *args)
CHECK_CLOSED(self);
if (!self->seekable) {
- PyErr_SetString(PyExc_IOError,
- "underlying stream is not seekable");
+ _unsupported("underlying stream is not seekable");
goto fail;
}
if (!self->telling) {