diff options
Diffstat (limited to 'Modules/_io/textio.c')
-rw-r--r-- | Modules/_io/textio.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 14f9488..0f0092f 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -2344,7 +2344,8 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) goto fail; } - if (whence == 1) { + switch (whence) { + case SEEK_CUR: /* seek relative to current position */ cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ); if (cmp < 0) @@ -2362,8 +2363,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) cookieObj = _PyObject_CallMethodId((PyObject *)self, &PyId_tell, NULL); if (cookieObj == NULL) goto fail; - } - else if (whence == 2) { + case SEEK_END: /* seek relative to end of file */ cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ); if (cmp < 0) @@ -2401,10 +2401,12 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) } } return res; - } - else if (whence != 0) { + case SEEK_SET: + break; + default: PyErr_Format(PyExc_ValueError, - "invalid whence (%d, should be 0, 1 or 2)", whence); + "invalid whence (%d, should be %d, %d or %d)", whence, + SEEK_SET, SEEK_CUR, SEEK_END); goto fail; } |