Skip to content

Commit

Permalink
Replace IOError with OSError (python#16715)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Dec 25, 2012
1 parent 16bdd41 commit f7a17b4
Show file tree
Hide file tree
Showing 121 changed files with 381 additions and 386 deletions.
2 changes: 1 addition & 1 deletion Lib/_osx_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _get_system_version():
_SYSTEM_VERSION = ''
try:
f = open('/System/Library/CoreServices/SystemVersion.plist')
except IOError:
except OSError:
# We're on a plain darwin box, fall back to the default
# behaviour.
pass
Expand Down
32 changes: 16 additions & 16 deletions Lib/_pyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
def open(file, mode="r", buffering=-1, encoding=None, errors=None,
newline=None, closefd=True, opener=None):

r"""Open file and return a stream. Raise IOError upon failure.
r"""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 @@ -254,7 +254,7 @@ def __new__(cls, *args, **kwargs):
try:
UnsupportedOperation = io.UnsupportedOperation
except AttributeError:
class UnsupportedOperation(ValueError, IOError):
class UnsupportedOperation(ValueError, OSError):
pass


Expand All @@ -278,7 +278,7 @@ class IOBase(metaclass=abc.ABCMeta):
readinto) needed. Text I/O classes work with str data.
Note that calling any method (even inquiries) on a closed stream is
undefined. Implementations may raise IOError in this case.
undefined. Implementations may raise OSError in this case.
IOBase (and its subclasses) support the iterator protocol, meaning
that an IOBase object can be iterated over yielding the lines in a
Expand All @@ -294,7 +294,7 @@ class IOBase(metaclass=abc.ABCMeta):
### Internal ###

def _unsupported(self, name):
"""Internal: raise an IOError exception for unsupported operations."""
"""Internal: raise an OSError exception for unsupported operations."""
raise UnsupportedOperation("%s.%s() not supported" %
(self.__class__.__name__, name))

Expand Down Expand Up @@ -441,7 +441,7 @@ def __exit__(self, *args):
def fileno(self):
"""Returns underlying file descriptor (an int) if one exists.
An IOError is raised if the IO object does not use a file descriptor.
An OSError is raised if the IO object does not use a file descriptor.
"""
self._unsupported("fileno")

Expand Down Expand Up @@ -699,13 +699,13 @@ def __init__(self, raw):
def seek(self, pos, whence=0):
new_position = self.raw.seek(pos, whence)
if new_position < 0:
raise IOError("seek() returned an invalid position")
raise OSError("seek() returned an invalid position")
return new_position

def tell(self):
pos = self.raw.tell()
if pos < 0:
raise IOError("tell() returned an invalid position")
raise OSError("tell() returned an invalid position")
return pos

def truncate(self, pos=None):
Expand Down Expand Up @@ -927,7 +927,7 @@ def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE):
"""Create a new buffered reader using the given readable raw IO object.
"""
if not raw.readable():
raise IOError('"raw" argument must be readable.')
raise OSError('"raw" argument must be readable.')

_BufferedIOMixin.__init__(self, raw)
if buffer_size <= 0:
Expand Down Expand Up @@ -1074,7 +1074,7 @@ class BufferedWriter(_BufferedIOMixin):

def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE):
if not raw.writable():
raise IOError('"raw" argument must be writable.')
raise OSError('"raw" argument must be writable.')

_BufferedIOMixin.__init__(self, raw)
if buffer_size <= 0:
Expand Down Expand Up @@ -1138,7 +1138,7 @@ def _flush_unlocked(self):
errno.EAGAIN,
"write could not complete without blocking", 0)
if n > len(self._write_buf) or n < 0:
raise IOError("write() returned incorrect number of bytes")
raise OSError("write() returned incorrect number of bytes")
del self._write_buf[:n]

def tell(self):
Expand Down Expand Up @@ -1174,10 +1174,10 @@ def __init__(self, reader, writer, buffer_size=DEFAULT_BUFFER_SIZE):
The arguments are two RawIO instances.
"""
if not reader.readable():
raise IOError('"reader" argument must be readable.')
raise OSError('"reader" argument must be readable.')

if not writer.writable():
raise IOError('"writer" argument must be writable.')
raise OSError('"writer" argument must be writable.')

self.reader = BufferedReader(reader, buffer_size)
self.writer = BufferedWriter(writer, buffer_size)
Expand Down Expand Up @@ -1248,7 +1248,7 @@ def seek(self, pos, whence=0):
with self._read_lock:
self._reset_read_buf()
if pos < 0:
raise IOError("seek() returned invalid position")
raise OSError("seek() returned invalid position")
return pos

def tell(self):
Expand Down Expand Up @@ -1727,7 +1727,7 @@ def tell(self):
if not self._seekable:
raise UnsupportedOperation("underlying stream is not seekable")
if not self._telling:
raise IOError("telling position disabled by next() call")
raise OSError("telling position disabled by next() call")
self.flush()
position = self.buffer.tell()
decoder = self._decoder
Expand Down Expand Up @@ -1814,7 +1814,7 @@ def tell(self):
chars_decoded += len(decoder.decode(b'', final=True))
need_eof = 1
if chars_decoded < chars_to_skip:
raise IOError("can't reconstruct logical file position")
raise OSError("can't reconstruct logical file position")

# The returned cookie corresponds to the last safe start point.
return self._pack_cookie(
Expand Down Expand Up @@ -1891,7 +1891,7 @@ def seek(self, cookie, whence=0):

# Skip chars_to_skip of the decoded characters.
if len(self._decoded_chars) < chars_to_skip:
raise IOError("can't restore logical file position")
raise OSError("can't restore logical file position")
self._decoded_chars_used = chars_to_skip

# Finally, reset the encoder (merely useful for proper BOM handling)
Expand Down
4 changes: 2 additions & 2 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ def __call__(self, string):
try:
return open(string, self._mode, self._bufsize, self._encoding,
self._errors)
except IOError as e:
except OSError as e:
message = _("can't open '%s': %s")
raise ArgumentTypeError(message % (string, e))

Expand Down Expand Up @@ -2020,7 +2020,7 @@ def _read_args_from_files(self, arg_strings):
new_arg_strings.extend(arg_strings)
finally:
args_file.close()
except IOError:
except OSError:
err = _sys.exc_info()[1]
self.error(str(err))

Expand Down
2 changes: 1 addition & 1 deletion Lib/cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def initlog(*allargs):
if logfile and not logfp:
try:
logfp = open(logfile, "a")
except IOError:
except OSError:
pass
if not logfp:
log = nolog
Expand Down
6 changes: 3 additions & 3 deletions Lib/chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, file, align=True, bigendian=True, inclheader=False):
self.size_read = 0
try:
self.offset = self.file.tell()
except (AttributeError, IOError):
except (AttributeError, OSError):
self.seekable = False
else:
self.seekable = True
Expand Down Expand Up @@ -102,7 +102,7 @@ def seek(self, pos, whence=0):
if self.closed:
raise ValueError("I/O operation on closed file")
if not self.seekable:
raise IOError("cannot seek")
raise OSError("cannot seek")
if whence == 1:
pos = pos + self.size_read
elif whence == 2:
Expand Down Expand Up @@ -158,7 +158,7 @@ def skip(self):
self.file.seek(n, 1)
self.size_read = self.size_read + n
return
except IOError:
except OSError:
pass
while self.size_read < self.chunksize:
n = min(8192, self.chunksize - self.size_read)
Expand Down
4 changes: 2 additions & 2 deletions Lib/compileall.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=False,
actual = chandle.read(8)
if expect == actual:
return success
except IOError:
except OSError:
pass
if not quiet:
print('Compiling {!r}...'.format(fullname))
Expand All @@ -124,7 +124,7 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=False,
msg = msg.decode(sys.stdout.encoding)
print(msg)
success = 0
except (SyntaxError, UnicodeError, IOError) as e:
except (SyntaxError, UnicodeError, OSError) as e:
if quiet:
print('*** Error compiling {!r}...'.format(fullname))
else:
Expand Down
2 changes: 1 addition & 1 deletion Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def read(self, filenames, encoding=None):
try:
with open(filename, encoding=encoding) as fp:
self._read(fp, filename)
except IOError:
except OSError:
continue
read_ok.append(filename)
return read_ok
Expand Down
10 changes: 5 additions & 5 deletions Lib/dbm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class error(Exception):
_defaultmod = None
_modules = {}

error = (error, IOError)
error = (error, OSError)


def open(file, flag='r', mode=0o666):
Expand Down Expand Up @@ -109,7 +109,7 @@ def whichdb(filename):
f = io.open(filename + ".dir", "rb")
f.close()
return "dbm.ndbm"
except IOError:
except OSError:
# some dbm emulations based on Berkeley DB generate a .db file
# some do not, but they should be caught by the bsd checks
try:
Expand All @@ -122,7 +122,7 @@ def whichdb(filename):
d = ndbm.open(filename)
d.close()
return "dbm.ndbm"
except IOError:
except OSError:
pass

# Check for dumbdbm next -- this has a .dir and a .dat file
Expand All @@ -139,13 +139,13 @@ def whichdb(filename):
return "dbm.dumb"
finally:
f.close()
except (OSError, IOError):
except OSError:
pass

# See if the file exists, return None if not
try:
f = io.open(filename, "rb")
except IOError:
except OSError:
return None

# Read the start of the file -- the magic number
Expand Down
6 changes: 3 additions & 3 deletions Lib/dbm/dumb.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

_BLOCKSIZE = 512

error = IOError
error = OSError

class _Database(collections.MutableMapping):

Expand Down Expand Up @@ -67,7 +67,7 @@ def __init__(self, filebasename, mode):
# Mod by Jack: create data file if needed
try:
f = _io.open(self._datfile, 'r', encoding="Latin-1")
except IOError:
except OSError:
f = _io.open(self._datfile, 'w', encoding="Latin-1")
self._chmod(self._datfile)
f.close()
Expand All @@ -78,7 +78,7 @@ def _update(self):
self._index = {}
try:
f = _io.open(self._dirfile, 'r', encoding="Latin-1")
except IOError:
except OSError:
pass
else:
for line in f:
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/command/build_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def copy_scripts(self):
# script.
try:
f = open(script, "rb")
except IOError:
except OSError:
if not self.dry_run:
raise
f = None
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class found in 'cmdclass' is used in place of the default, which is
dist.run_commands()
except KeyboardInterrupt:
raise SystemExit("interrupted")
except (IOError, OSError) as exc:
except OSError as exc:
error = grok_environment_error(exc)

if DEBUG:
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/cygwinccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def check_config_h():
return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn
finally:
config_h.close()
except IOError as exc:
except OSError as exc:
return (CONFIG_H_UNCERTAIN,
"couldn't read '%s': %s" % (fn, exc.strerror))

Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/dir_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def remove_tree(directory, verbose=1, dry_run=0):
abspath = os.path.abspath(cmd[1])
if abspath in _path_created:
del _path_created[abspath]
except (IOError, OSError) as exc:
except OSError as exc:
log.warn(grok_environment_error(
exc, "error removing %s: " % directory))

Expand Down
4 changes: 2 additions & 2 deletions Lib/distutils/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class DistutilsArgError (DistutilsError):

class DistutilsFileError (DistutilsError):
"""Any problems in the filesystem: expected file not found, etc.
Typically this is for problems that we detect before IOError or
OSError could be raised."""
Typically this is for problems that we detect before OSError
could be raised."""
pass

class DistutilsOptionError (DistutilsError):
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/msvc9compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ def _remove_visual_c_ref(self, manifest_file):
return manifest_file
finally:
manifest_f.close()
except IOError:
except OSError:
pass

# -- Miscellaneous methods -----------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions Lib/distutils/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def _init_posix():
try:
filename = get_makefile_filename()
parse_makefile(filename, g)
except IOError as msg:
except OSError as msg:
my_msg = "invalid Python installation: unable to open %s" % filename
if hasattr(msg, "strerror"):
my_msg = my_msg + " (%s)" % msg.strerror
Expand All @@ -438,7 +438,7 @@ def _init_posix():
filename = get_config_h_filename()
with open(filename) as file:
parse_config_h(file, g)
except IOError as msg:
except OSError as msg:
my_msg = "invalid Python installation: unable to open %s" % filename
if hasattr(msg, "strerror"):
my_msg = my_msg + " (%s)" % msg.strerror
Expand Down
4 changes: 2 additions & 2 deletions Lib/distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ def _subst (match, local_vars=local_vars):


def grok_environment_error (exc, prefix="error: "):
"""Generate a useful error message from an EnvironmentError (IOError or
OSError) exception object. Handles Python 1.5.1 and 1.5.2 styles, and
"""Generate a useful error message from an OSError
exception object. Handles Python 1.5.1 and 1.5.2 styles, and
does what it can to deal with exception objects that don't have a
filename (which happens when the error is due to a two-file operation,
such as 'rename()' or 'link()'. Returns the error message as a string
Expand Down
Loading

0 comments on commit f7a17b4

Please sign in to comment.