Index: Modules/_io/fileio.c =================================================================== --- Modules/_io/fileio.c (révision 73491) +++ Modules/_io/fileio.c (copie de travail) @@ -736,7 +736,7 @@ static PyObject * fileio_seek(fileio *self, PyObject *args) { - PyObject *posobj; + PyObject *posobj, *res; int whence = 0; if (self->fd < 0) @@ -745,16 +745,25 @@ if (!PyArg_ParseTuple(args, "O|i", &posobj, &whence)) return NULL; - return portable_lseek(self->fd, posobj, whence); + res = portable_lseek(self->fd, posobj, whence); + if (res == NULL && self->seekable > 0) + /* Perhaps the file can't be seeked anymore */ + self->seekable = -1; + return res; } static PyObject * fileio_tell(fileio *self, PyObject *args) { + PyObject *res; if (self->fd < 0) return err_closed(); - return portable_lseek(self->fd, NULL, 1); + res = portable_lseek(self->fd, NULL, 1); + if (res == NULL && self->seekable > 0) + /* Perhaps the file can't be seeked anymore */ + self->seekable = -1; + return res; } #ifdef HAVE_FTRUNCATE Index: Modules/_io/textio.c =================================================================== --- Modules/_io/textio.c (révision 73491) +++ Modules/_io/textio.c (copie de travail) @@ -1038,25 +1038,35 @@ PyObject *cookieObj; int cmp; - self->encoding_start_of_stream = 1; - cookieObj = PyObject_CallMethodObjArgs(buffer, _PyIO_str_tell, NULL); - if (cookieObj == NULL) - goto error; - - cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ); - Py_DECREF(cookieObj); - if (cmp < 0) { - goto error; + if (cookieObj == NULL) { + if (PyErr_ExceptionMatches(PyExc_EnvironmentError)) { + /* Perhaps the stream isn't seekable after all? */ + PyErr_Clear(); + res = PyObject_CallMethod(buffer, "seekable", NULL); + if (res == NULL) + goto error; + self->seekable = self->telling = PyObject_IsTrue(res); + Py_DECREF(res); + } + else + goto error; } - - if (cmp == 0) { - self->encoding_start_of_stream = 0; - res = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_setstate, - _PyIO_zero, NULL); - if (res == NULL) + else { + self->encoding_start_of_stream = 1; + cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ); + Py_DECREF(cookieObj); + if (cmp < 0) { goto error; - Py_DECREF(res); + } + if (cmp == 0) { + self->encoding_start_of_stream = 0; + res = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_setstate, + _PyIO_zero, NULL); + if (res == NULL) + goto error; + Py_DECREF(res); + } } }