mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-30022: Get rid of using EnvironmentError and IOError (except test… (#1051)
This commit is contained in:
parent
fdbd01151d
commit
55fe1ae970
36 changed files with 1538 additions and 1538 deletions
|
@ -61,7 +61,7 @@ PyDoc_STRVAR(module_doc,
|
|||
"At the top of the I/O hierarchy is the abstract base class IOBase. It\n"
|
||||
"defines the basic interface to a stream. Note, however, that there is no\n"
|
||||
"separation between reading and writing to streams; implementations are\n"
|
||||
"allowed to raise an IOError if they do not support a given operation.\n"
|
||||
"allowed to raise an OSError if they do not support a given operation.\n"
|
||||
"\n"
|
||||
"Extending IOBase is RawIOBase which deals simply with the reading and\n"
|
||||
"writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide\n"
|
||||
|
@ -107,7 +107,7 @@ _io.open
|
|||
closefd: bool(accept={int}) = True
|
||||
opener: object = None
|
||||
|
||||
Open file and return a stream. Raise IOError upon failure.
|
||||
Open file and return a stream. Raise OSError upon failure.
|
||||
|
||||
file is either a text or byte string giving the name (and the path
|
||||
if the file isn't in the current working directory) of the file to
|
||||
|
@ -231,7 +231,7 @@ static PyObject *
|
|||
_io_open_impl(PyObject *module, PyObject *file, const char *mode,
|
||||
int buffering, const char *encoding, const char *errors,
|
||||
const char *newline, int closefd, PyObject *opener)
|
||||
/*[clinic end generated code: output=aefafc4ce2b46dc0 input=7f81b2a1d3b02344]*/
|
||||
/*[clinic end generated code: output=aefafc4ce2b46dc0 input=03da2940c8a65871]*/
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
|
@ -656,7 +656,7 @@ PyInit__io(void)
|
|||
if (PyModule_AddIntMacro(m, DEFAULT_BUFFER_SIZE) < 0)
|
||||
goto fail;
|
||||
|
||||
/* UnsupportedOperation inherits from ValueError and IOError */
|
||||
/* UnsupportedOperation inherits from ValueError and OSError */
|
||||
state->unsupported_operation = PyObject_CallFunction(
|
||||
(PyObject *)&PyType_Type, "s(OO){}",
|
||||
"UnsupportedOperation", PyExc_OSError, PyExc_ValueError);
|
||||
|
|
|
@ -67,7 +67,7 @@ extern Py_ssize_t _PyIO_find_line_ending(
|
|||
int translated, int universal, PyObject *readnl,
|
||||
int kind, const char *start, const char *end, Py_ssize_t *consumed);
|
||||
|
||||
/* Return 1 if an EnvironmentError with errno == EINTR is set (and then
|
||||
/* Return 1 if an OSError with errno == EINTR is set (and then
|
||||
clears the error indicator), 0 otherwise.
|
||||
Should only be called when PyErr_Occurred() is true.
|
||||
*/
|
||||
|
|
|
@ -695,7 +695,7 @@ _buffered_raw_tell(buffered *self)
|
|||
Py_DECREF(res);
|
||||
if (n < 0) {
|
||||
if (!PyErr_Occurred())
|
||||
PyErr_Format(PyExc_IOError,
|
||||
PyErr_Format(PyExc_OSError,
|
||||
"Raw stream returned invalid position %" PY_PRIdOFF,
|
||||
(PY_OFF_T_COMPAT)n);
|
||||
return -1;
|
||||
|
@ -728,7 +728,7 @@ _buffered_raw_seek(buffered *self, Py_off_t target, int whence)
|
|||
Py_DECREF(res);
|
||||
if (n < 0) {
|
||||
if (!PyErr_Occurred())
|
||||
PyErr_Format(PyExc_IOError,
|
||||
PyErr_Format(PyExc_OSError,
|
||||
"Raw stream returned invalid position %" PY_PRIdOFF,
|
||||
(PY_OFF_T_COMPAT)n);
|
||||
return -1;
|
||||
|
@ -776,7 +776,7 @@ _buffered_init(buffered *self)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Return 1 if an EnvironmentError with errno == EINTR is set (and then
|
||||
/* Return 1 if an OSError with errno == EINTR is set (and then
|
||||
clears the error indicator), 0 otherwise.
|
||||
Should only be called when PyErr_Occurred() is true.
|
||||
*/
|
||||
|
@ -785,17 +785,17 @@ _PyIO_trap_eintr(void)
|
|||
{
|
||||
static PyObject *eintr_int = NULL;
|
||||
PyObject *typ, *val, *tb;
|
||||
PyEnvironmentErrorObject *env_err;
|
||||
PyOSErrorObject *env_err;
|
||||
|
||||
if (eintr_int == NULL) {
|
||||
eintr_int = PyLong_FromLong(EINTR);
|
||||
assert(eintr_int != NULL);
|
||||
}
|
||||
if (!PyErr_ExceptionMatches(PyExc_EnvironmentError))
|
||||
if (!PyErr_ExceptionMatches(PyExc_OSError))
|
||||
return 0;
|
||||
PyErr_Fetch(&typ, &val, &tb);
|
||||
PyErr_NormalizeException(&typ, &val, &tb);
|
||||
env_err = (PyEnvironmentErrorObject *) val;
|
||||
env_err = (PyOSErrorObject *) val;
|
||||
assert(env_err != NULL);
|
||||
if (env_err->myerrno != NULL &&
|
||||
PyObject_RichCompareBool(env_err->myerrno, eintr_int, Py_EQ) > 0) {
|
||||
|
@ -1374,7 +1374,7 @@ buffered_iternext(buffered *self)
|
|||
line = PyObject_CallMethodObjArgs((PyObject *)self,
|
||||
_PyIO_str_readline, NULL);
|
||||
if (line && !PyBytes_Check(line)) {
|
||||
PyErr_Format(PyExc_IOError,
|
||||
PyErr_Format(PyExc_OSError,
|
||||
"readline() should have returned a bytes object, "
|
||||
"not '%.200s'", Py_TYPE(line)->tp_name);
|
||||
Py_DECREF(line);
|
||||
|
@ -1501,7 +1501,7 @@ _bufferedreader_raw_read(buffered *self, char *start, Py_ssize_t len)
|
|||
n = PyNumber_AsSsize_t(res, PyExc_ValueError);
|
||||
Py_DECREF(res);
|
||||
if (n < 0 || n > len) {
|
||||
PyErr_Format(PyExc_IOError,
|
||||
PyErr_Format(PyExc_OSError,
|
||||
"raw readinto() returned invalid length %zd "
|
||||
"(should have been between 0 and %zd)", n, len);
|
||||
return -1;
|
||||
|
@ -1858,7 +1858,7 @@ _bufferedwriter_raw_write(buffered *self, char *start, Py_ssize_t len)
|
|||
n = PyNumber_AsSsize_t(res, PyExc_ValueError);
|
||||
Py_DECREF(res);
|
||||
if (n < 0 || n > len) {
|
||||
PyErr_Format(PyExc_IOError,
|
||||
PyErr_Format(PyExc_OSError,
|
||||
"raw write() returned invalid length %zd "
|
||||
"(should have been between 0 and %zd)", n, len);
|
||||
return -1;
|
||||
|
|
|
@ -7,7 +7,7 @@ PyDoc_STRVAR(_io_open__doc__,
|
|||
" errors=None, newline=None, closefd=True, opener=None)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Open file and return a stream. Raise IOError upon failure.\n"
|
||||
"Open file and return a stream. Raise OSError upon failure.\n"
|
||||
"\n"
|
||||
"file is either a text or byte string giving the name (and the path\n"
|
||||
"if the file isn\'t in the current working directory) of the file to\n"
|
||||
|
@ -158,4 +158,4 @@ _io_open(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=79fd04d9c9d8f28f input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=e6011c784fe6589b input=a9049054013a1b77]*/
|
||||
|
|
|
@ -123,7 +123,7 @@ internal_close(fileio *self)
|
|||
}
|
||||
if (err < 0) {
|
||||
errno = save_errno;
|
||||
PyErr_SetFromErrno(PyExc_IOError);
|
||||
PyErr_SetFromErrno(PyExc_OSError);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -456,7 +456,7 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
|
|||
directories, so we need a check. */
|
||||
if (S_ISDIR(fdfstat.st_mode)) {
|
||||
errno = EISDIR;
|
||||
PyErr_SetFromErrnoWithFilenameObject(PyExc_IOError, nameobj);
|
||||
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, nameobj);
|
||||
goto error;
|
||||
}
|
||||
#endif /* defined(S_ISDIR) */
|
||||
|
@ -910,7 +910,7 @@ portable_lseek(int fd, PyObject *posobj, int whence)
|
|||
_Py_END_SUPPRESS_IPH
|
||||
Py_END_ALLOW_THREADS
|
||||
if (res < 0)
|
||||
return PyErr_SetFromErrno(PyExc_IOError);
|
||||
return PyErr_SetFromErrno(PyExc_OSError);
|
||||
|
||||
#if defined(HAVE_LARGEFILE_SUPPORT)
|
||||
return PyLong_FromLongLong(res);
|
||||
|
@ -1023,7 +1023,7 @@ _io_FileIO_truncate_impl(fileio *self, PyObject *posobj)
|
|||
|
||||
if (ret != 0) {
|
||||
Py_DECREF(posobj);
|
||||
PyErr_SetFromErrno(PyExc_IOError);
|
||||
PyErr_SetFromErrno(PyExc_OSError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -526,7 +526,7 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit)
|
|||
goto fail;
|
||||
}
|
||||
if (!PyBytes_Check(readahead)) {
|
||||
PyErr_Format(PyExc_IOError,
|
||||
PyErr_Format(PyExc_OSError,
|
||||
"peek() should have returned a bytes object, "
|
||||
"not '%.200s'", Py_TYPE(readahead)->tp_name);
|
||||
Py_DECREF(readahead);
|
||||
|
@ -566,7 +566,7 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit)
|
|||
goto fail;
|
||||
}
|
||||
if (!PyBytes_Check(b)) {
|
||||
PyErr_Format(PyExc_IOError,
|
||||
PyErr_Format(PyExc_OSError,
|
||||
"read() should have returned a bytes object, "
|
||||
"not '%.200s'", Py_TYPE(b)->tp_name);
|
||||
Py_DECREF(b);
|
||||
|
|
|
@ -410,7 +410,7 @@ stringio_iternext(stringio *self)
|
|||
line = PyObject_CallMethodObjArgs((PyObject *)self,
|
||||
_PyIO_str_readline, NULL);
|
||||
if (line && !PyUnicode_Check(line)) {
|
||||
PyErr_Format(PyExc_IOError,
|
||||
PyErr_Format(PyExc_OSError,
|
||||
"readline() should have returned a str object, "
|
||||
"not '%.200s'", Py_TYPE(line)->tp_name);
|
||||
Py_DECREF(line);
|
||||
|
@ -498,7 +498,7 @@ _io_StringIO_seek_impl(stringio *self, Py_ssize_t pos, int whence)
|
|||
return NULL;
|
||||
}
|
||||
else if (whence != 0 && pos != 0) {
|
||||
PyErr_SetString(PyExc_IOError,
|
||||
PyErr_SetString(PyExc_OSError,
|
||||
"Can't do nonzero cur-relative seeks");
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -924,7 +924,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
|
|||
goto error;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IOError,
|
||||
PyErr_SetString(PyExc_OSError,
|
||||
"could not determine default encoding");
|
||||
}
|
||||
|
||||
|
@ -2205,7 +2205,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
|
|||
|
||||
/* Skip chars_to_skip of the decoded characters. */
|
||||
if (PyUnicode_GetLength(self->decoded_chars) < cookie.chars_to_skip) {
|
||||
PyErr_SetString(PyExc_IOError, "can't restore logical file position");
|
||||
PyErr_SetString(PyExc_OSError, "can't restore logical file position");
|
||||
goto fail;
|
||||
}
|
||||
self->decoded_chars_used = cookie.chars_to_skip;
|
||||
|
@ -2255,7 +2255,7 @@ _io_TextIOWrapper_tell_impl(textio *self)
|
|||
goto fail;
|
||||
}
|
||||
if (!self->telling) {
|
||||
PyErr_SetString(PyExc_IOError,
|
||||
PyErr_SetString(PyExc_OSError,
|
||||
"telling position disabled by next() call");
|
||||
goto fail;
|
||||
}
|
||||
|
@ -2421,7 +2421,7 @@ _io_TextIOWrapper_tell_impl(textio *self)
|
|||
cookie.need_eof = 1;
|
||||
|
||||
if (chars_decoded < chars_to_skip) {
|
||||
PyErr_SetString(PyExc_IOError,
|
||||
PyErr_SetString(PyExc_OSError,
|
||||
"can't reconstruct logical file position");
|
||||
goto fail;
|
||||
}
|
||||
|
@ -2693,7 +2693,7 @@ textiowrapper_iternext(textio *self)
|
|||
line = PyObject_CallMethodObjArgs((PyObject *)self,
|
||||
_PyIO_str_readline, NULL);
|
||||
if (line && !PyUnicode_Check(line)) {
|
||||
PyErr_Format(PyExc_IOError,
|
||||
PyErr_Format(PyExc_OSError,
|
||||
"readline() should have returned a str object, "
|
||||
"not '%.200s'", Py_TYPE(line)->tp_name);
|
||||
Py_DECREF(line);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue