bpo-30022: Get rid of using EnvironmentError and IOError (except test… (#1051)

This commit is contained in:
Serhiy Storchaka 2017-04-16 10:46:38 +03:00 committed by GitHub
parent fdbd01151d
commit 55fe1ae970
36 changed files with 1538 additions and 1538 deletions

View File

@ -153,7 +153,7 @@ PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(struct _frame *f, int exc);
if (...premature_exit...) {
Py_BLOCK_THREADS
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
@ -161,7 +161,7 @@ PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(struct _frame *f, int exc);
Py_BLOCK_THREADS
if (...premature_exit...) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
Py_UNBLOCK_THREADS

View File

@ -52,7 +52,7 @@ def idle_showwarning_subproc(
try:
file.write(idle_formatwarning(
message, category, filename, lineno, line))
except IOError:
except OSError:
pass # the file (probably stderr) is invalid - this warning gets lost.
_warnings_showwarning = None

View File

@ -689,9 +689,9 @@ class SourceLoader(_LoaderBasics):
"""Optional method that returns the modification time (an int) for the
specified path, where path is a str.
Raises IOError when the path cannot be handled.
Raises OSError when the path cannot be handled.
"""
raise IOError
raise OSError
def path_stats(self, path):
"""Optional method returning a metadata dict for the specified path
@ -702,7 +702,7 @@ class SourceLoader(_LoaderBasics):
- 'size' (optional) is the size in bytes of the source code.
Implementing this method allows the loader to read bytecode files.
Raises IOError when the path cannot be handled.
Raises OSError when the path cannot be handled.
"""
return {'mtime': self.path_mtime(path)}
@ -757,7 +757,7 @@ class SourceLoader(_LoaderBasics):
else:
try:
st = self.path_stats(source_path)
except IOError:
except OSError:
pass
else:
source_mtime = int(st['mtime'])

View File

@ -193,7 +193,7 @@ class ResourceLoader(Loader):
def get_data(self, path):
"""Abstract method which when implemented should return the bytes for
the specified path. The path must be a str."""
raise IOError
raise OSError
class InspectLoader(Loader):
@ -315,7 +315,7 @@ class SourceLoader(_bootstrap_external.SourceLoader, ResourceLoader, ExecutionLo
def path_mtime(self, path):
"""Return the (int) modification time for the path (str)."""
if self.path_stats.__func__ is SourceLoader.path_stats:
raise IOError
raise OSError
return int(self.path_stats(path)['mtime'])
def path_stats(self, path):
@ -326,7 +326,7 @@ class SourceLoader(_bootstrap_external.SourceLoader, ResourceLoader, ExecutionLo
- 'size' (optional) is the size in bytes of the source code.
"""
if self.path_mtime.__func__ is SourceLoader.path_mtime:
raise IOError
raise OSError
return {'mtime': self.path_mtime(path)}
def set_data(self, path, data):

View File

@ -245,7 +245,7 @@ class MimeTypes:
while True:
try:
ctype = _winreg.EnumKey(mimedb, i)
except EnvironmentError:
except OSError:
break
else:
if '\0' not in ctype:
@ -259,13 +259,13 @@ class MimeTypes:
# Only check file extensions
if not subkeyname.startswith("."):
continue
# raises EnvironmentError if no 'Content Type' value
# raises OSError if no 'Content Type' value
mimetype, datatype = _winreg.QueryValueEx(
subkey, 'Content Type')
if datatype != _winreg.REG_SZ:
continue
self.add_type(mimetype, subkeyname, strict)
except EnvironmentError:
except OSError:
continue
def guess_type(url, strict=True):

View File

@ -579,7 +579,7 @@ if __name__ == '__main__':
if self.stats:
try:
self.stats.add(line)
except IOError as e:
except OSError as e:
print("Failed to load statistics for %s: %s" % (line, e), file=self.stream)
else:
print("No statistics object is loaded.", file=self.stream)

View File

@ -416,7 +416,7 @@ def enablerlcompleter():
'.python_history')
try:
readline.read_history_file(history)
except IOError:
except OSError:
pass
atexit.register(readline.write_history_file, history)

View File

@ -741,7 +741,7 @@ def system_must_validate_cert(f):
def dec(*args, **kwargs):
try:
f(*args, **kwargs)
except IOError as e:
except OSError as e:
if "CERTIFICATE_VERIFY_FAILED" in str(e):
raise unittest.SkipTest("system does not contain "
"necessary certificates")

View File

@ -112,8 +112,8 @@ class Test_Assertions(unittest.TestCase):
a = A()
wr = weakref.ref(a)
try:
raise IOError
except IOError:
raise OSError
except OSError:
raise ValueError
def test_functional(self):

View File

@ -19,7 +19,7 @@ __all__ = ['URLError', 'HTTPError', 'ContentTooShortError']
class URLError(OSError):
# URLError is a sub-type of OSError, but it doesn't share any of
# the implementation. need to override __init__ and __str__.
# It sets self.args for compatibility with other EnvironmentError
# It sets self.args for compatibility with other OSError
# subclasses, but args doesn't have the typical format with errno in
# slot 0 and strerror in slot 1. This may be better than nothing.
def __init__(self, reason, filename=None):

View File

@ -96,10 +96,10 @@ catch_bz2_error(int bzerror)
return 1;
case BZ_DATA_ERROR:
case BZ_DATA_ERROR_MAGIC:
PyErr_SetString(PyExc_IOError, "Invalid data stream");
PyErr_SetString(PyExc_OSError, "Invalid data stream");
return 1;
case BZ_IO_ERROR:
PyErr_SetString(PyExc_IOError, "Unknown I/O error");
PyErr_SetString(PyExc_OSError, "Unknown I/O error");
return 1;
case BZ_UNEXPECTED_EOF:
PyErr_SetString(PyExc_EOFError,
@ -112,7 +112,7 @@ catch_bz2_error(int bzerror)
"Invalid sequence of commands sent to libbzip2");
return 1;
default:
PyErr_Format(PyExc_IOError,
PyErr_Format(PyExc_OSError,
"Unrecognized error from libbzip2: %d", bzerror);
return 1;
}

View File

@ -483,7 +483,7 @@ PyInit__dbm(void) {
d = PyModule_GetDict(m);
if (DbmError == NULL)
DbmError = PyErr_NewException("_dbm.error",
PyExc_IOError, NULL);
PyExc_OSError, NULL);
s = PyUnicode_FromString(which_dbm);
if (s != NULL) {
PyDict_SetItemString(d, "library", s);

View File

@ -649,7 +649,7 @@ PyInit__gdbm(void) {
if (m == NULL)
return NULL;
d = PyModule_GetDict(m);
DbmError = PyErr_NewException("_gdbm.error", PyExc_IOError, NULL);
DbmError = PyErr_NewException("_gdbm.error", PyExc_OSError, NULL);
if (DbmError != NULL) {
PyDict_SetItemString(d, "error", DbmError);
s = PyUnicode_FromString(dbmmodule_open_flags);

View File

@ -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);

View File

@ -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.
*/

View File

@ -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;

View File

@ -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]*/

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -64,7 +64,7 @@ multiprocessing_closesocket(PyObject *self, PyObject *args)
Py_END_ALLOW_THREADS
if (ret)
return PyErr_SetExcFromWindowsErr(PyExc_IOError, WSAGetLastError());
return PyErr_SetExcFromWindowsErr(PyExc_OSError, WSAGetLastError());
Py_RETURN_NONE;
}
@ -88,7 +88,7 @@ multiprocessing_recv(PyObject *self, PyObject *args)
if (nread < 0) {
Py_DECREF(buf);
return PyErr_SetExcFromWindowsErr(PyExc_IOError, WSAGetLastError());
return PyErr_SetExcFromWindowsErr(PyExc_OSError, WSAGetLastError());
}
_PyBytes_Resize(&buf, nread);
return buf;
@ -112,7 +112,7 @@ multiprocessing_send(PyObject *self, PyObject *args)
PyBuffer_Release(&buf);
if (ret < 0)
return PyErr_SetExcFromWindowsErr(PyExc_IOError, WSAGetLastError());
return PyErr_SetExcFromWindowsErr(PyExc_OSError, WSAGetLastError());
return PyLong_FromLong(ret);
}

View File

@ -135,7 +135,7 @@ semlock_acquire(SemLockObject *self, PyObject *args, PyObject *kwds)
Py_RETURN_TRUE;
case WAIT_OBJECT_0 + 1:
errno = EINTR;
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
case WAIT_FAILED:
return PyErr_SetFromWindowsErr(0);
default:

View File

@ -3275,7 +3275,7 @@ _ssl__SSLContext_load_cert_chain_impl(PySSLContext *self, PyObject *certfile,
}
else if (errno != 0) {
ERR_clear_error();
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
}
else {
_setSSLError(NULL, 0, __FILE__, __LINE__);
@ -3296,7 +3296,7 @@ _ssl__SSLContext_load_cert_chain_impl(PySSLContext *self, PyObject *certfile,
}
else if (errno != 0) {
ERR_clear_error();
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
}
else {
_setSSLError(NULL, 0, __FILE__, __LINE__);
@ -3504,7 +3504,7 @@ _ssl__SSLContext_load_verify_locations_impl(PySSLContext *self,
ok = 0;
if (errno != 0) {
ERR_clear_error();
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
}
else {
_setSSLError(NULL, 0, __FILE__, __LINE__);

View File

@ -224,7 +224,7 @@ _winapi_Overlapped_GetOverlappedResult_impl(OverlappedObject *self, int wait)
break;
default:
self->pending = 0;
return PyErr_SetExcFromWindowsErr(PyExc_IOError, err);
return PyErr_SetExcFromWindowsErr(PyExc_OSError, err);
}
if (self->completed && self->read_buffer != NULL) {
assert(PyBytes_CheckExact(self->read_buffer));
@ -276,7 +276,7 @@ _winapi_Overlapped_cancel_impl(OverlappedObject *self)
/* CancelIoEx returns ERROR_NOT_FOUND if the I/O completed in-between */
if (!res && GetLastError() != ERROR_NOT_FOUND)
return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0);
return PyErr_SetExcFromWindowsErr(PyExc_OSError, 0);
self->pending = 0;
Py_RETURN_NONE;
}
@ -1139,7 +1139,7 @@ _winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size)
Py_END_ALLOW_THREADS
if (!ret) {
Py_DECREF(buf);
return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0);
return PyErr_SetExcFromWindowsErr(PyExc_OSError, 0);
}
if (_PyBytes_Resize(&buf, nread))
return NULL;
@ -1150,7 +1150,7 @@ _winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size)
ret = PeekNamedPipe(handle, NULL, 0, NULL, &navail, &nleft);
Py_END_ALLOW_THREADS
if (!ret) {
return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0);
return PyErr_SetExcFromWindowsErr(PyExc_OSError, 0);
}
return Py_BuildValue("ii", navail, nleft);
}
@ -1201,7 +1201,7 @@ _winapi_ReadFile_impl(PyObject *module, HANDLE handle, int size,
overlapped->pending = 1;
else if (err != ERROR_MORE_DATA) {
Py_DECREF(overlapped);
return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0);
return PyErr_SetExcFromWindowsErr(PyExc_OSError, 0);
}
}
return Py_BuildValue("NI", (PyObject *) overlapped, err);
@ -1209,7 +1209,7 @@ _winapi_ReadFile_impl(PyObject *module, HANDLE handle, int size,
if (!ret && err != ERROR_MORE_DATA) {
Py_DECREF(buf);
return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0);
return PyErr_SetExcFromWindowsErr(PyExc_OSError, 0);
}
if (_PyBytes_Resize(&buf, nread))
return NULL;
@ -1366,10 +1366,10 @@ _winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq,
Py_END_ALLOW_THREADS
if (result == WAIT_FAILED)
return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0);
return PyErr_SetExcFromWindowsErr(PyExc_OSError, 0);
else if (sigint_event != NULL && result == WAIT_OBJECT_0 + nhandles - 1) {
errno = EINTR;
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
}
return PyLong_FromLong((int) result);
@ -1455,7 +1455,7 @@ _winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer,
overlapped->pending = 1;
else {
Py_DECREF(overlapped);
return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0);
return PyErr_SetExcFromWindowsErr(PyExc_OSError, 0);
}
}
return Py_BuildValue("NI", (PyObject *) overlapped, err);
@ -1463,7 +1463,7 @@ _winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer,
PyBuffer_Release(buf);
if (!ret)
return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0);
return PyErr_SetExcFromWindowsErr(PyExc_OSError, 0);
return Py_BuildValue("II", written, err);
}

View File

@ -79,7 +79,7 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
ret = fcntl(fd, code, buf);
Py_END_ALLOW_THREADS
if (ret < 0) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
return PyBytes_FromStringAndSize(buf, len);
@ -99,7 +99,7 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
ret = fcntl(fd, code, (int)int_arg);
Py_END_ALLOW_THREADS
if (ret < 0) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
return PyLong_FromLong((long)ret);
@ -210,7 +210,7 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code,
}
PyBuffer_Release(&pstr); /* No further access to str below this point */
if (ret < 0) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
if (mutate_arg) {
@ -238,7 +238,7 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code,
Py_END_ALLOW_THREADS
if (ret < 0) {
PyBuffer_Release(&pstr);
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
PyBuffer_Release(&pstr);
@ -258,7 +258,7 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code,
ret = ioctl(fd, code, arg);
Py_END_ALLOW_THREADS
if (ret < 0) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
return PyLong_FromLong((long)ret);
@ -316,7 +316,7 @@ fcntl_flock_impl(PyObject *module, int fd, int code)
}
#endif /* HAVE_FLOCK */
if (ret < 0) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
Py_RETURN_NONE;
@ -412,7 +412,7 @@ fcntl_lockf_impl(PyObject *module, int fd, int code, PyObject *lenobj,
Py_END_ALLOW_THREADS
}
if (ret < 0) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
Py_RETURN_NONE;

View File

@ -141,7 +141,7 @@ static void RunStartupFile(PyCompilerFlags *cf)
save_errno = errno;
PySys_WriteStderr("Could not open PYTHONSTARTUP\n");
errno = save_errno;
PyErr_SetFromErrnoWithFilename(PyExc_IOError,
PyErr_SetFromErrnoWithFilename(PyExc_OSError,
startup);
PyErr_Print();
PyErr_Clear();

View File

@ -128,13 +128,13 @@ newossobject(PyObject *arg)
expected write() semantics. */
if (fcntl(fd, F_SETFL, 0) == -1) {
close(fd);
PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
PyErr_SetFromErrnoWithFilename(PyExc_OSError, devicename);
return NULL;
}
if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
close(fd);
PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
PyErr_SetFromErrnoWithFilename(PyExc_OSError, devicename);
return NULL;
}
/* Create and initialize the object */
@ -253,7 +253,7 @@ _do_ioctl_1(int fd, PyObject *args, char *fname, int cmd)
return NULL;
if (ioctl(fd, cmd, &arg) == -1)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
return PyLong_FromLong(arg);
}
@ -278,7 +278,7 @@ _do_ioctl_1_internal(int fd, PyObject *args, char *fname, int cmd)
return NULL;
if (ioctl(fd, cmd, &arg) == -1)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
return PyLong_FromLong(arg);
}
@ -306,7 +306,7 @@ _do_ioctl_0(int fd, PyObject *args, char *fname, int cmd)
Py_END_ALLOW_THREADS
if (rv == -1)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
Py_RETURN_NONE;
}
@ -324,7 +324,7 @@ oss_nonblock(oss_audio_t *self, PyObject *unused)
/* Hmmm: it doesn't appear to be possible to return to blocking
mode once we're in non-blocking mode! */
if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
Py_RETURN_NONE;
}
@ -346,7 +346,7 @@ oss_getfmts(oss_audio_t *self, PyObject *unused)
return NULL;
if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
return PyLong_FromLong(mask);
}
@ -491,7 +491,7 @@ oss_writeall(oss_audio_t *self, PyObject *args)
assert(select_rv != 0); /* no timeout, can't expire */
if (select_rv == -1) {
PyBuffer_Release(&data);
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
}
rv = _Py_write(self->fd, cp, Py_MIN(size, INT_MAX));
@ -575,7 +575,7 @@ oss_setparameters(oss_audio_t *self, PyObject *args)
fmt = wanted_fmt;
if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) == -1) {
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
}
if (strict && fmt != wanted_fmt) {
return PyErr_Format
@ -586,7 +586,7 @@ oss_setparameters(oss_audio_t *self, PyObject *args)
channels = wanted_channels;
if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
}
if (strict && channels != wanted_channels) {
return PyErr_Format
@ -597,7 +597,7 @@ oss_setparameters(oss_audio_t *self, PyObject *args)
rate = wanted_rate;
if (ioctl(self->fd, SNDCTL_DSP_SPEED, &rate) == -1) {
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
}
if (strict && rate != wanted_rate) {
return PyErr_Format
@ -656,11 +656,11 @@ oss_bufsize(oss_audio_t *self, PyObject *unused)
return NULL;
if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
return PyLong_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
@ -678,11 +678,11 @@ oss_obufcount(oss_audio_t *self, PyObject *unused)
return NULL;
if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
return PyLong_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
@ -701,11 +701,11 @@ oss_obuffree(oss_audio_t *self, PyObject *unused)
return NULL;
if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
return PyLong_FromLong(ai.bytes / (ssize * nchannels));
@ -725,7 +725,7 @@ oss_getptr(oss_audio_t *self, PyObject *unused)
else
req = SNDCTL_DSP_GETOPTR;
if (ioctl(self->fd, req, &info) == -1) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
@ -805,7 +805,7 @@ oss_mixer_get(oss_mixer_t *self, PyObject *args)
}
if (ioctl(self->fd, MIXER_READ(channel), &volume) == -1)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
}
@ -835,7 +835,7 @@ oss_mixer_set(oss_mixer_t *self, PyObject *args)
volume = (rightVol << 8) | leftVol;
if (ioctl(self->fd, MIXER_WRITE(channel), &volume) == -1)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
}

View File

@ -188,7 +188,7 @@ read_init_file(PyObject *self, PyObject *args)
} else
errno = rl_read_init_file(NULL);
if (errno)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
Py_RETURN_NONE;
}
@ -214,7 +214,7 @@ read_history_file(PyObject *self, PyObject *args)
} else
errno = read_history(NULL);
if (errno)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
Py_RETURN_NONE;
}
@ -249,7 +249,7 @@ write_history_file(PyObject *self, PyObject *args)
Py_XDECREF(filename_bytes);
errno = err;
if (errno)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
Py_RETURN_NONE;
}
@ -285,7 +285,7 @@ append_history_file(PyObject *self, PyObject *args)
Py_XDECREF(filename_bytes);
errno = err;
if (errno)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
Py_RETURN_NONE;
}

View File

@ -768,7 +768,7 @@ static int devpoll_flush(devpollObject *self)
** the wild.
** See http://bugs.python.org/issue6397.
*/
PyErr_Format(PyExc_IOError, "failed to write all pollfds. "
PyErr_Format(PyExc_OSError, "failed to write all pollfds. "
"Please, report at http://bugs.python.org/. "
"Data to report: Size tried: %d, actual size written: %d.",
size, n);
@ -948,7 +948,7 @@ devpoll_poll(devpollObject *self, PyObject *args)
} while (1);
if (poll_result < 0) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}

View File

@ -1438,7 +1438,7 @@ PyInit__signal(void)
#if defined (HAVE_SETITIMER) || defined (HAVE_GETITIMER)
ItimerError = PyErr_NewException("signal.ItimerError",
PyExc_IOError, NULL);
PyExc_OSError, NULL);
if (ItimerError != NULL)
PyDict_SetItemString(d, "ItimerError", ItimerError);
#endif

View File

@ -603,7 +603,7 @@ zipimporter_get_data(PyObject *obj, PyObject *args)
goto error;
toc_entry = PyDict_GetItem(self->files, key);
if (toc_entry == NULL) {
PyErr_SetFromErrnoWithFilenameObject(PyExc_IOError, key);
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, key);
Py_DECREF(key);
goto error;
}
@ -709,7 +709,7 @@ module, or raises ZipImportError if it wasn't found.");
PyDoc_STRVAR(doc_get_data,
"get_data(pathname) -> string with file data.\n\
\n\
Return the data associated with 'pathname'. Raise IOError if\n\
Return the data associated with 'pathname'. Raise OSError if\n\
the file wasn't found.");
PyDoc_STRVAR(doc_is_package,
@ -1193,7 +1193,7 @@ get_data(PyObject *archive, PyObject *toc_entry)
goto file_error;
}
if (fread(buf, 1, data_size, fp) != (size_t)data_size) {
PyErr_SetString(PyExc_IOError,
PyErr_SetString(PyExc_OSError,
"zipimport: can't read data");
goto error;
}

View File

@ -406,7 +406,7 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
}
if (ret == 0) {
if (ferror(fp)) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
clearerr(fp);
ret = -1;
}

View File

@ -29,7 +29,7 @@ PyDoc_STRVAR(msvcrt_locking__doc__,
"\n"
"Lock part of a file based on file descriptor fd from the C runtime.\n"
"\n"
"Raises IOError on failure. The locked region of the file extends from\n"
"Raises OSError on failure. The locked region of the file extends from\n"
"the current file position for nbytes bytes, and may continue beyond\n"
"the end of the file. mode must be one of the LK_* constants listed\n"
"below. Multiple regions in a file may be locked at the same time, but\n"
@ -155,7 +155,7 @@ PyDoc_STRVAR(msvcrt_get_osfhandle__doc__,
"\n"
"Return the file handle for the file descriptor fd.\n"
"\n"
"Raises IOError if fd is not recognized.");
"Raises OSError if fd is not recognized.");
#define MSVCRT_GET_OSFHANDLE_METHODDEF \
{"get_osfhandle", (PyCFunction)msvcrt_get_osfhandle, METH_O, msvcrt_get_osfhandle__doc__},
@ -589,4 +589,4 @@ exit:
#ifndef MSVCRT_SET_ERROR_MODE_METHODDEF
#define MSVCRT_SET_ERROR_MODE_METHODDEF
#endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */
/*[clinic end generated code: output=36f1e78ca8bd3944 input=a9049054013a1b77]*/
/*[clinic end generated code: output=be516d0e78532ba3 input=a9049054013a1b77]*/

View File

@ -82,7 +82,7 @@ msvcrt_heapmin_impl(PyObject *module)
/*[clinic end generated code: output=1ba00f344782dc19 input=82e1771d21bde2d8]*/
{
if (_heapmin() != 0)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
Py_RETURN_NONE;
}
@ -96,7 +96,7 @@ msvcrt.locking
Lock part of a file based on file descriptor fd from the C runtime.
Raises IOError on failure. The locked region of the file extends from
Raises OSError on failure. The locked region of the file extends from
the current file position for nbytes bytes, and may continue beyond
the end of the file. mode must be one of the LK_* constants listed
below. Multiple regions in a file may be locked at the same time, but
@ -106,7 +106,7 @@ individually.
static PyObject *
msvcrt_locking_impl(PyObject *module, int fd, int mode, long nbytes)
/*[clinic end generated code: output=a4a90deca9785a03 input=d9f13f0f6a713ba7]*/
/*[clinic end generated code: output=a4a90deca9785a03 input=e97bd15fc4a04fef]*/
{
int err;
@ -116,7 +116,7 @@ msvcrt_locking_impl(PyObject *module, int fd, int mode, long nbytes)
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
if (err != 0)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
Py_RETURN_NONE;
}
@ -144,7 +144,7 @@ msvcrt_setmode_impl(PyObject *module, int fd, int flags)
flags = _setmode(fd, flags);
_Py_END_SUPPRESS_IPH
if (flags == -1)
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return flags;
}
@ -173,7 +173,7 @@ msvcrt_open_osfhandle_impl(PyObject *module, intptr_t handle, int flags)
fd = _open_osfhandle(handle, flags);
_Py_END_SUPPRESS_IPH
if (fd == -1)
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return fd;
}
@ -186,12 +186,12 @@ msvcrt.get_osfhandle -> handle
Return the file handle for the file descriptor fd.
Raises IOError if fd is not recognized.
Raises OSError if fd is not recognized.
[clinic start generated code]*/
static intptr_t
msvcrt_get_osfhandle_impl(PyObject *module, int fd)
/*[clinic end generated code: output=7ce761dd0de2b503 input=c7d18d02c8017ec1]*/
/*[clinic end generated code: output=7ce761dd0de2b503 input=305900f4bfab76c7]*/
{
intptr_t handle = -1;
@ -199,7 +199,7 @@ msvcrt_get_osfhandle_impl(PyObject *module, int fd)
handle = _get_osfhandle(fd);
_Py_END_SUPPRESS_IPH
if (handle == -1)
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return handle;
}
@ -359,7 +359,7 @@ msvcrt_ungetch_impl(PyObject *module, char char_value)
_Py_END_SUPPRESS_IPH
if (res == EOF)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
Py_RETURN_NONE;
}
@ -383,7 +383,7 @@ msvcrt_ungetwch_impl(PyObject *module, int unicode_char)
_Py_END_SUPPRESS_IPH
if (res == WEOF)
return PyErr_SetFromErrno(PyExc_IOError);
return PyErr_SetFromErrno(PyExc_OSError);
Py_RETURN_NONE;
}
@ -435,7 +435,7 @@ msvcrt_CrtSetReportMode_impl(PyObject *module, int type, int mode)
res = _CrtSetReportMode(type, mode);
_Py_END_SUPPRESS_IPH
if (res == -1)
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return res;
}

File diff suppressed because it is too large Load Diff