Skip to content

Commit

Permalink
bpo-30022: Get rid of using EnvironmentError and IOError (except test… (
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka authored Apr 16, 2017
1 parent fdbd011 commit 55fe1ae
Show file tree
Hide file tree
Showing 36 changed files with 1,530 additions and 1,530 deletions.
4 changes: 2 additions & 2 deletions Include/ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ 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;
}
An alternative is:
Py_BLOCK_THREADS
if (...premature_exit...) {
PyErr_SetFromErrno(PyExc_IOError);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
Py_UNBLOCK_THREADS
Expand Down
2 changes: 1 addition & 1 deletion Lib/idlelib/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,9 @@ def path_mtime(self, path):
"""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
Expand All @@ -702,7 +702,7 @@ def path_stats(self, path):
- '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)}

Expand Down Expand Up @@ -757,7 +757,7 @@ def get_code(self, fullname):
else:
try:
st = self.path_stats(source_path)
except IOError:
except OSError:
pass
else:
source_mtime = int(st['mtime'])
Expand Down
6 changes: 3 additions & 3 deletions Lib/importlib/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -326,7 +326,7 @@ def path_stats(self, path):
- '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):
Expand Down
6 changes: 3 additions & 3 deletions Lib/mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def enum_types(mimedb):
while True:
try:
ctype = _winreg.EnumKey(mimedb, i)
except EnvironmentError:
except OSError:
break
else:
if '\0' not in ctype:
Expand All @@ -259,13 +259,13 @@ def enum_types(mimedb):
# 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):
Expand Down
2 changes: 1 addition & 1 deletion Lib/pstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def do_add(self, line):
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)
Expand Down
2 changes: 1 addition & 1 deletion Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def register_readline():
'.python_history')
try:
readline.read_history_file(history)
except IOError:
except OSError:
pass
atexit.register(readline.write_history_file, history)

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions Lib/unittest/test/test_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def foo(self):
a = A()
wr = weakref.ref(a)
try:
raise IOError
except IOError:
raise OSError
except OSError:
raise ValueError

def test_functional(self):
Expand Down
2 changes: 1 addition & 1 deletion Lib/urllib/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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):
Expand Down
6 changes: 3 additions & 3 deletions Modules/_bz2module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_dbmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Modules/_gdbmmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions Modules/_io/_iomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Modules/_io/_iomodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
18 changes: 9 additions & 9 deletions Modules/_io/bufferedio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Modules/_io/clinic/_iomodule.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]*/
8 changes: 4 additions & 4 deletions Modules/_io/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/_io/iobase.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 55fe1ae

Please sign in to comment.