mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
Replace IOError with OSError (#16715)
This commit is contained in:
parent
16bdd4120d
commit
f7a17b48d7
121 changed files with 381 additions and 386 deletions
|
@ -94,7 +94,7 @@ def _get_system_version():
|
||||||
_SYSTEM_VERSION = ''
|
_SYSTEM_VERSION = ''
|
||||||
try:
|
try:
|
||||||
f = open('/System/Library/CoreServices/SystemVersion.plist')
|
f = open('/System/Library/CoreServices/SystemVersion.plist')
|
||||||
except IOError:
|
except OSError:
|
||||||
# We're on a plain darwin box, fall back to the default
|
# We're on a plain darwin box, fall back to the default
|
||||||
# behaviour.
|
# behaviour.
|
||||||
pass
|
pass
|
||||||
|
|
32
Lib/_pyio.py
32
Lib/_pyio.py
|
@ -34,7 +34,7 @@ BlockingIOError = BlockingIOError
|
||||||
def open(file, mode="r", buffering=-1, encoding=None, errors=None,
|
def open(file, mode="r", buffering=-1, encoding=None, errors=None,
|
||||||
newline=None, closefd=True, opener=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
|
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
|
if the file isn't in the current working directory) of the file to
|
||||||
|
@ -254,7 +254,7 @@ class OpenWrapper:
|
||||||
try:
|
try:
|
||||||
UnsupportedOperation = io.UnsupportedOperation
|
UnsupportedOperation = io.UnsupportedOperation
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
class UnsupportedOperation(ValueError, IOError):
|
class UnsupportedOperation(ValueError, OSError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ class IOBase(metaclass=abc.ABCMeta):
|
||||||
readinto) needed. Text I/O classes work with str data.
|
readinto) needed. Text I/O classes work with str data.
|
||||||
|
|
||||||
Note that calling any method (even inquiries) on a closed stream is
|
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
|
IOBase (and its subclasses) support the iterator protocol, meaning
|
||||||
that an IOBase object can be iterated over yielding the lines in a
|
that an IOBase object can be iterated over yielding the lines in a
|
||||||
|
@ -294,7 +294,7 @@ class IOBase(metaclass=abc.ABCMeta):
|
||||||
### Internal ###
|
### Internal ###
|
||||||
|
|
||||||
def _unsupported(self, name):
|
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" %
|
raise UnsupportedOperation("%s.%s() not supported" %
|
||||||
(self.__class__.__name__, name))
|
(self.__class__.__name__, name))
|
||||||
|
|
||||||
|
@ -441,7 +441,7 @@ class IOBase(metaclass=abc.ABCMeta):
|
||||||
def fileno(self):
|
def fileno(self):
|
||||||
"""Returns underlying file descriptor (an int) if one exists.
|
"""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")
|
self._unsupported("fileno")
|
||||||
|
|
||||||
|
@ -699,13 +699,13 @@ class _BufferedIOMixin(BufferedIOBase):
|
||||||
def seek(self, pos, whence=0):
|
def seek(self, pos, whence=0):
|
||||||
new_position = self.raw.seek(pos, whence)
|
new_position = self.raw.seek(pos, whence)
|
||||||
if new_position < 0:
|
if new_position < 0:
|
||||||
raise IOError("seek() returned an invalid position")
|
raise OSError("seek() returned an invalid position")
|
||||||
return new_position
|
return new_position
|
||||||
|
|
||||||
def tell(self):
|
def tell(self):
|
||||||
pos = self.raw.tell()
|
pos = self.raw.tell()
|
||||||
if pos < 0:
|
if pos < 0:
|
||||||
raise IOError("tell() returned an invalid position")
|
raise OSError("tell() returned an invalid position")
|
||||||
return pos
|
return pos
|
||||||
|
|
||||||
def truncate(self, pos=None):
|
def truncate(self, pos=None):
|
||||||
|
@ -927,7 +927,7 @@ class BufferedReader(_BufferedIOMixin):
|
||||||
"""Create a new buffered reader using the given readable raw IO object.
|
"""Create a new buffered reader using the given readable raw IO object.
|
||||||
"""
|
"""
|
||||||
if not raw.readable():
|
if not raw.readable():
|
||||||
raise IOError('"raw" argument must be readable.')
|
raise OSError('"raw" argument must be readable.')
|
||||||
|
|
||||||
_BufferedIOMixin.__init__(self, raw)
|
_BufferedIOMixin.__init__(self, raw)
|
||||||
if buffer_size <= 0:
|
if buffer_size <= 0:
|
||||||
|
@ -1074,7 +1074,7 @@ class BufferedWriter(_BufferedIOMixin):
|
||||||
|
|
||||||
def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE):
|
def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE):
|
||||||
if not raw.writable():
|
if not raw.writable():
|
||||||
raise IOError('"raw" argument must be writable.')
|
raise OSError('"raw" argument must be writable.')
|
||||||
|
|
||||||
_BufferedIOMixin.__init__(self, raw)
|
_BufferedIOMixin.__init__(self, raw)
|
||||||
if buffer_size <= 0:
|
if buffer_size <= 0:
|
||||||
|
@ -1138,7 +1138,7 @@ class BufferedWriter(_BufferedIOMixin):
|
||||||
errno.EAGAIN,
|
errno.EAGAIN,
|
||||||
"write could not complete without blocking", 0)
|
"write could not complete without blocking", 0)
|
||||||
if n > len(self._write_buf) or n < 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]
|
del self._write_buf[:n]
|
||||||
|
|
||||||
def tell(self):
|
def tell(self):
|
||||||
|
@ -1174,10 +1174,10 @@ class BufferedRWPair(BufferedIOBase):
|
||||||
The arguments are two RawIO instances.
|
The arguments are two RawIO instances.
|
||||||
"""
|
"""
|
||||||
if not reader.readable():
|
if not reader.readable():
|
||||||
raise IOError('"reader" argument must be readable.')
|
raise OSError('"reader" argument must be readable.')
|
||||||
|
|
||||||
if not writer.writable():
|
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.reader = BufferedReader(reader, buffer_size)
|
||||||
self.writer = BufferedWriter(writer, buffer_size)
|
self.writer = BufferedWriter(writer, buffer_size)
|
||||||
|
@ -1248,7 +1248,7 @@ class BufferedRandom(BufferedWriter, BufferedReader):
|
||||||
with self._read_lock:
|
with self._read_lock:
|
||||||
self._reset_read_buf()
|
self._reset_read_buf()
|
||||||
if pos < 0:
|
if pos < 0:
|
||||||
raise IOError("seek() returned invalid position")
|
raise OSError("seek() returned invalid position")
|
||||||
return pos
|
return pos
|
||||||
|
|
||||||
def tell(self):
|
def tell(self):
|
||||||
|
@ -1727,7 +1727,7 @@ class TextIOWrapper(TextIOBase):
|
||||||
if not self._seekable:
|
if not self._seekable:
|
||||||
raise UnsupportedOperation("underlying stream is not seekable")
|
raise UnsupportedOperation("underlying stream is not seekable")
|
||||||
if not self._telling:
|
if not self._telling:
|
||||||
raise IOError("telling position disabled by next() call")
|
raise OSError("telling position disabled by next() call")
|
||||||
self.flush()
|
self.flush()
|
||||||
position = self.buffer.tell()
|
position = self.buffer.tell()
|
||||||
decoder = self._decoder
|
decoder = self._decoder
|
||||||
|
@ -1814,7 +1814,7 @@ class TextIOWrapper(TextIOBase):
|
||||||
chars_decoded += len(decoder.decode(b'', final=True))
|
chars_decoded += len(decoder.decode(b'', final=True))
|
||||||
need_eof = 1
|
need_eof = 1
|
||||||
if chars_decoded < chars_to_skip:
|
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.
|
# The returned cookie corresponds to the last safe start point.
|
||||||
return self._pack_cookie(
|
return self._pack_cookie(
|
||||||
|
@ -1891,7 +1891,7 @@ class TextIOWrapper(TextIOBase):
|
||||||
|
|
||||||
# Skip chars_to_skip of the decoded characters.
|
# Skip chars_to_skip of the decoded characters.
|
||||||
if len(self._decoded_chars) < chars_to_skip:
|
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
|
self._decoded_chars_used = chars_to_skip
|
||||||
|
|
||||||
# Finally, reset the encoder (merely useful for proper BOM handling)
|
# Finally, reset the encoder (merely useful for proper BOM handling)
|
||||||
|
|
|
@ -1167,7 +1167,7 @@ class FileType(object):
|
||||||
try:
|
try:
|
||||||
return open(string, self._mode, self._bufsize, self._encoding,
|
return open(string, self._mode, self._bufsize, self._encoding,
|
||||||
self._errors)
|
self._errors)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
message = _("can't open '%s': %s")
|
message = _("can't open '%s': %s")
|
||||||
raise ArgumentTypeError(message % (string, e))
|
raise ArgumentTypeError(message % (string, e))
|
||||||
|
|
||||||
|
@ -2020,7 +2020,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||||
new_arg_strings.extend(arg_strings)
|
new_arg_strings.extend(arg_strings)
|
||||||
finally:
|
finally:
|
||||||
args_file.close()
|
args_file.close()
|
||||||
except IOError:
|
except OSError:
|
||||||
err = _sys.exc_info()[1]
|
err = _sys.exc_info()[1]
|
||||||
self.error(str(err))
|
self.error(str(err))
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ def initlog(*allargs):
|
||||||
if logfile and not logfp:
|
if logfile and not logfp:
|
||||||
try:
|
try:
|
||||||
logfp = open(logfile, "a")
|
logfp = open(logfile, "a")
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
if not logfp:
|
if not logfp:
|
||||||
log = nolog
|
log = nolog
|
||||||
|
|
|
@ -70,7 +70,7 @@ class Chunk:
|
||||||
self.size_read = 0
|
self.size_read = 0
|
||||||
try:
|
try:
|
||||||
self.offset = self.file.tell()
|
self.offset = self.file.tell()
|
||||||
except (AttributeError, IOError):
|
except (AttributeError, OSError):
|
||||||
self.seekable = False
|
self.seekable = False
|
||||||
else:
|
else:
|
||||||
self.seekable = True
|
self.seekable = True
|
||||||
|
@ -102,7 +102,7 @@ class Chunk:
|
||||||
if self.closed:
|
if self.closed:
|
||||||
raise ValueError("I/O operation on closed file")
|
raise ValueError("I/O operation on closed file")
|
||||||
if not self.seekable:
|
if not self.seekable:
|
||||||
raise IOError("cannot seek")
|
raise OSError("cannot seek")
|
||||||
if whence == 1:
|
if whence == 1:
|
||||||
pos = pos + self.size_read
|
pos = pos + self.size_read
|
||||||
elif whence == 2:
|
elif whence == 2:
|
||||||
|
@ -158,7 +158,7 @@ class Chunk:
|
||||||
self.file.seek(n, 1)
|
self.file.seek(n, 1)
|
||||||
self.size_read = self.size_read + n
|
self.size_read = self.size_read + n
|
||||||
return
|
return
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
while self.size_read < self.chunksize:
|
while self.size_read < self.chunksize:
|
||||||
n = min(8192, self.chunksize - self.size_read)
|
n = min(8192, self.chunksize - self.size_read)
|
||||||
|
|
|
@ -106,7 +106,7 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=False,
|
||||||
actual = chandle.read(8)
|
actual = chandle.read(8)
|
||||||
if expect == actual:
|
if expect == actual:
|
||||||
return success
|
return success
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print('Compiling {!r}...'.format(fullname))
|
print('Compiling {!r}...'.format(fullname))
|
||||||
|
@ -124,7 +124,7 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=False,
|
||||||
msg = msg.decode(sys.stdout.encoding)
|
msg = msg.decode(sys.stdout.encoding)
|
||||||
print(msg)
|
print(msg)
|
||||||
success = 0
|
success = 0
|
||||||
except (SyntaxError, UnicodeError, IOError) as e:
|
except (SyntaxError, UnicodeError, OSError) as e:
|
||||||
if quiet:
|
if quiet:
|
||||||
print('*** Error compiling {!r}...'.format(fullname))
|
print('*** Error compiling {!r}...'.format(fullname))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -688,7 +688,7 @@ class RawConfigParser(MutableMapping):
|
||||||
try:
|
try:
|
||||||
with open(filename, encoding=encoding) as fp:
|
with open(filename, encoding=encoding) as fp:
|
||||||
self._read(fp, filename)
|
self._read(fp, filename)
|
||||||
except IOError:
|
except OSError:
|
||||||
continue
|
continue
|
||||||
read_ok.append(filename)
|
read_ok.append(filename)
|
||||||
return read_ok
|
return read_ok
|
||||||
|
|
|
@ -42,7 +42,7 @@ _names = ['dbm.gnu', 'dbm.ndbm', 'dbm.dumb']
|
||||||
_defaultmod = None
|
_defaultmod = None
|
||||||
_modules = {}
|
_modules = {}
|
||||||
|
|
||||||
error = (error, IOError)
|
error = (error, OSError)
|
||||||
|
|
||||||
|
|
||||||
def open(file, flag='r', mode=0o666):
|
def open(file, flag='r', mode=0o666):
|
||||||
|
@ -109,7 +109,7 @@ def whichdb(filename):
|
||||||
f = io.open(filename + ".dir", "rb")
|
f = io.open(filename + ".dir", "rb")
|
||||||
f.close()
|
f.close()
|
||||||
return "dbm.ndbm"
|
return "dbm.ndbm"
|
||||||
except IOError:
|
except OSError:
|
||||||
# some dbm emulations based on Berkeley DB generate a .db file
|
# some dbm emulations based on Berkeley DB generate a .db file
|
||||||
# some do not, but they should be caught by the bsd checks
|
# some do not, but they should be caught by the bsd checks
|
||||||
try:
|
try:
|
||||||
|
@ -122,7 +122,7 @@ def whichdb(filename):
|
||||||
d = ndbm.open(filename)
|
d = ndbm.open(filename)
|
||||||
d.close()
|
d.close()
|
||||||
return "dbm.ndbm"
|
return "dbm.ndbm"
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Check for dumbdbm next -- this has a .dir and a .dat file
|
# Check for dumbdbm next -- this has a .dir and a .dat file
|
||||||
|
@ -139,13 +139,13 @@ def whichdb(filename):
|
||||||
return "dbm.dumb"
|
return "dbm.dumb"
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
except (OSError, IOError):
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# See if the file exists, return None if not
|
# See if the file exists, return None if not
|
||||||
try:
|
try:
|
||||||
f = io.open(filename, "rb")
|
f = io.open(filename, "rb")
|
||||||
except IOError:
|
except OSError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Read the start of the file -- the magic number
|
# Read the start of the file -- the magic number
|
||||||
|
|
|
@ -29,7 +29,7 @@ __all__ = ["error", "open"]
|
||||||
|
|
||||||
_BLOCKSIZE = 512
|
_BLOCKSIZE = 512
|
||||||
|
|
||||||
error = IOError
|
error = OSError
|
||||||
|
|
||||||
class _Database(collections.MutableMapping):
|
class _Database(collections.MutableMapping):
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ class _Database(collections.MutableMapping):
|
||||||
# Mod by Jack: create data file if needed
|
# Mod by Jack: create data file if needed
|
||||||
try:
|
try:
|
||||||
f = _io.open(self._datfile, 'r', encoding="Latin-1")
|
f = _io.open(self._datfile, 'r', encoding="Latin-1")
|
||||||
except IOError:
|
except OSError:
|
||||||
f = _io.open(self._datfile, 'w', encoding="Latin-1")
|
f = _io.open(self._datfile, 'w', encoding="Latin-1")
|
||||||
self._chmod(self._datfile)
|
self._chmod(self._datfile)
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -78,7 +78,7 @@ class _Database(collections.MutableMapping):
|
||||||
self._index = {}
|
self._index = {}
|
||||||
try:
|
try:
|
||||||
f = _io.open(self._dirfile, 'r', encoding="Latin-1")
|
f = _io.open(self._dirfile, 'r', encoding="Latin-1")
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
for line in f:
|
for line in f:
|
||||||
|
|
|
@ -74,7 +74,7 @@ class build_scripts(Command):
|
||||||
# script.
|
# script.
|
||||||
try:
|
try:
|
||||||
f = open(script, "rb")
|
f = open(script, "rb")
|
||||||
except IOError:
|
except OSError:
|
||||||
if not self.dry_run:
|
if not self.dry_run:
|
||||||
raise
|
raise
|
||||||
f = None
|
f = None
|
||||||
|
|
|
@ -148,7 +148,7 @@ def setup (**attrs):
|
||||||
dist.run_commands()
|
dist.run_commands()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise SystemExit("interrupted")
|
raise SystemExit("interrupted")
|
||||||
except (IOError, OSError) as exc:
|
except OSError as exc:
|
||||||
error = grok_environment_error(exc)
|
error = grok_environment_error(exc)
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
|
|
|
@ -359,7 +359,7 @@ def check_config_h():
|
||||||
return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn
|
return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn
|
||||||
finally:
|
finally:
|
||||||
config_h.close()
|
config_h.close()
|
||||||
except IOError as exc:
|
except OSError as exc:
|
||||||
return (CONFIG_H_UNCERTAIN,
|
return (CONFIG_H_UNCERTAIN,
|
||||||
"couldn't read '%s': %s" % (fn, exc.strerror))
|
"couldn't read '%s': %s" % (fn, exc.strerror))
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ def remove_tree(directory, verbose=1, dry_run=0):
|
||||||
abspath = os.path.abspath(cmd[1])
|
abspath = os.path.abspath(cmd[1])
|
||||||
if abspath in _path_created:
|
if abspath in _path_created:
|
||||||
del _path_created[abspath]
|
del _path_created[abspath]
|
||||||
except (IOError, OSError) as exc:
|
except OSError as exc:
|
||||||
log.warn(grok_environment_error(
|
log.warn(grok_environment_error(
|
||||||
exc, "error removing %s: " % directory))
|
exc, "error removing %s: " % directory))
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,8 @@ class DistutilsArgError (DistutilsError):
|
||||||
|
|
||||||
class DistutilsFileError (DistutilsError):
|
class DistutilsFileError (DistutilsError):
|
||||||
"""Any problems in the filesystem: expected file not found, etc.
|
"""Any problems in the filesystem: expected file not found, etc.
|
||||||
Typically this is for problems that we detect before IOError or
|
Typically this is for problems that we detect before OSError
|
||||||
OSError could be raised."""
|
could be raised."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class DistutilsOptionError (DistutilsError):
|
class DistutilsOptionError (DistutilsError):
|
||||||
|
|
|
@ -729,7 +729,7 @@ class MSVCCompiler(CCompiler) :
|
||||||
return manifest_file
|
return manifest_file
|
||||||
finally:
|
finally:
|
||||||
manifest_f.close()
|
manifest_f.close()
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# -- Miscellaneous methods -----------------------------------------
|
# -- Miscellaneous methods -----------------------------------------
|
||||||
|
|
|
@ -426,7 +426,7 @@ def _init_posix():
|
||||||
try:
|
try:
|
||||||
filename = get_makefile_filename()
|
filename = get_makefile_filename()
|
||||||
parse_makefile(filename, g)
|
parse_makefile(filename, g)
|
||||||
except IOError as msg:
|
except OSError as msg:
|
||||||
my_msg = "invalid Python installation: unable to open %s" % filename
|
my_msg = "invalid Python installation: unable to open %s" % filename
|
||||||
if hasattr(msg, "strerror"):
|
if hasattr(msg, "strerror"):
|
||||||
my_msg = my_msg + " (%s)" % msg.strerror
|
my_msg = my_msg + " (%s)" % msg.strerror
|
||||||
|
@ -438,7 +438,7 @@ def _init_posix():
|
||||||
filename = get_config_h_filename()
|
filename = get_config_h_filename()
|
||||||
with open(filename) as file:
|
with open(filename) as file:
|
||||||
parse_config_h(file, g)
|
parse_config_h(file, g)
|
||||||
except IOError as msg:
|
except OSError as msg:
|
||||||
my_msg = "invalid Python installation: unable to open %s" % filename
|
my_msg = "invalid Python installation: unable to open %s" % filename
|
||||||
if hasattr(msg, "strerror"):
|
if hasattr(msg, "strerror"):
|
||||||
my_msg = my_msg + " (%s)" % msg.strerror
|
my_msg = my_msg + " (%s)" % msg.strerror
|
||||||
|
|
|
@ -207,8 +207,8 @@ def subst_vars (s, local_vars):
|
||||||
|
|
||||||
|
|
||||||
def grok_environment_error (exc, prefix="error: "):
|
def grok_environment_error (exc, prefix="error: "):
|
||||||
"""Generate a useful error message from an EnvironmentError (IOError or
|
"""Generate a useful error message from an OSError
|
||||||
OSError) exception object. Handles Python 1.5.1 and 1.5.2 styles, and
|
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
|
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,
|
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
|
such as 'rename()' or 'link()'. Returns the error message as a string
|
||||||
|
|
|
@ -30,7 +30,7 @@ pertaining to the last line read; nextfile() has no effect.
|
||||||
|
|
||||||
All files are opened in text mode by default, you can override this by
|
All files are opened in text mode by default, you can override this by
|
||||||
setting the mode parameter to input() or FileInput.__init__().
|
setting the mode parameter to input() or FileInput.__init__().
|
||||||
If an I/O error occurs during opening or reading a file, the IOError
|
If an I/O error occurs during opening or reading a file, the OSError
|
||||||
exception is raised.
|
exception is raised.
|
||||||
|
|
||||||
If sys.stdin is used more than once, the second and further use will
|
If sys.stdin is used more than once, the second and further use will
|
||||||
|
@ -328,7 +328,7 @@ class FileInput:
|
||||||
os.unlink(self._backupfilename)
|
os.unlink(self._backupfilename)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
# The next few lines may raise IOError
|
# The next few lines may raise OSError
|
||||||
os.rename(self._filename, self._backupfilename)
|
os.rename(self._filename, self._backupfilename)
|
||||||
self._file = open(self._backupfilename, self._mode)
|
self._file = open(self._backupfilename, self._mode)
|
||||||
try:
|
try:
|
||||||
|
@ -350,7 +350,7 @@ class FileInput:
|
||||||
self._savestdout = sys.stdout
|
self._savestdout = sys.stdout
|
||||||
sys.stdout = self._output
|
sys.stdout = self._output
|
||||||
else:
|
else:
|
||||||
# This may raise IOError
|
# This may raise OSError
|
||||||
if self._openhook:
|
if self._openhook:
|
||||||
self._file = self._openhook(self._filename, self._mode)
|
self._file = self._openhook(self._filename, self._mode)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -61,7 +61,7 @@ class error_proto(Error): pass # response does not begin with [1-5]
|
||||||
|
|
||||||
# All exceptions (hopefully) that may be raised here and that aren't
|
# All exceptions (hopefully) that may be raised here and that aren't
|
||||||
# (always) programming errors on our side
|
# (always) programming errors on our side
|
||||||
all_errors = (Error, IOError, EOFError)
|
all_errors = (Error, OSError, EOFError)
|
||||||
|
|
||||||
|
|
||||||
# Line terminators (we always output CRLF, but accept any of CRLF, CR, LF)
|
# Line terminators (we always output CRLF, but accept any of CRLF, CR, LF)
|
||||||
|
@ -826,7 +826,7 @@ else:
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
__all__.append('FTP_TLS')
|
__all__.append('FTP_TLS')
|
||||||
all_errors = (Error, IOError, EOFError, ssl.SSLError)
|
all_errors = (Error, OSError, EOFError, ssl.SSLError)
|
||||||
|
|
||||||
|
|
||||||
_150_re = None
|
_150_re = None
|
||||||
|
@ -958,7 +958,7 @@ class Netrc:
|
||||||
filename = os.path.join(os.environ["HOME"],
|
filename = os.path.join(os.environ["HOME"],
|
||||||
".netrc")
|
".netrc")
|
||||||
else:
|
else:
|
||||||
raise IOError("specify file to load or set $HOME")
|
raise OSError("specify file to load or set $HOME")
|
||||||
self.__hosts = {}
|
self.__hosts = {}
|
||||||
self.__macros = {}
|
self.__macros = {}
|
||||||
fp = open(filename, "r")
|
fp = open(filename, "r")
|
||||||
|
@ -1074,7 +1074,7 @@ def test():
|
||||||
userid = passwd = acct = ''
|
userid = passwd = acct = ''
|
||||||
try:
|
try:
|
||||||
netrc = Netrc(rcfile)
|
netrc = Netrc(rcfile)
|
||||||
except IOError:
|
except OSError:
|
||||||
if rcfile is not None:
|
if rcfile is not None:
|
||||||
sys.stderr.write("Could not open account file"
|
sys.stderr.write("Could not open account file"
|
||||||
" -- using anonymous login.")
|
" -- using anonymous login.")
|
||||||
|
|
|
@ -244,7 +244,7 @@ class GNUTranslations(NullTranslations):
|
||||||
version, msgcount, masteridx, transidx = unpack('>4I', buf[4:20])
|
version, msgcount, masteridx, transidx = unpack('>4I', buf[4:20])
|
||||||
ii = '>II'
|
ii = '>II'
|
||||||
else:
|
else:
|
||||||
raise IOError(0, 'Bad magic number', filename)
|
raise OSError(0, 'Bad magic number', filename)
|
||||||
# Now put all messages from the .mo file buffer into the catalog
|
# Now put all messages from the .mo file buffer into the catalog
|
||||||
# dictionary.
|
# dictionary.
|
||||||
for i in range(0, msgcount):
|
for i in range(0, msgcount):
|
||||||
|
@ -256,7 +256,7 @@ class GNUTranslations(NullTranslations):
|
||||||
msg = buf[moff:mend]
|
msg = buf[moff:mend]
|
||||||
tmsg = buf[toff:tend]
|
tmsg = buf[toff:tend]
|
||||||
else:
|
else:
|
||||||
raise IOError(0, 'File is corrupt', filename)
|
raise OSError(0, 'File is corrupt', filename)
|
||||||
# See if we're looking at GNU .mo conventions for metadata
|
# See if we're looking at GNU .mo conventions for metadata
|
||||||
if mlen == 0:
|
if mlen == 0:
|
||||||
# Catalog description
|
# Catalog description
|
||||||
|
@ -398,7 +398,7 @@ def translation(domain, localedir=None, languages=None,
|
||||||
if not mofiles:
|
if not mofiles:
|
||||||
if fallback:
|
if fallback:
|
||||||
return NullTranslations()
|
return NullTranslations()
|
||||||
raise IOError(ENOENT, 'No translation file found for domain', domain)
|
raise OSError(ENOENT, 'No translation file found for domain', domain)
|
||||||
# Avoid opening, reading, and parsing the .mo file after it's been done
|
# Avoid opening, reading, and parsing the .mo file after it's been done
|
||||||
# once.
|
# once.
|
||||||
result = None
|
result = None
|
||||||
|
@ -460,7 +460,7 @@ def dgettext(domain, message):
|
||||||
try:
|
try:
|
||||||
t = translation(domain, _localedirs.get(domain, None),
|
t = translation(domain, _localedirs.get(domain, None),
|
||||||
codeset=_localecodesets.get(domain))
|
codeset=_localecodesets.get(domain))
|
||||||
except IOError:
|
except OSError:
|
||||||
return message
|
return message
|
||||||
return t.gettext(message)
|
return t.gettext(message)
|
||||||
|
|
||||||
|
@ -468,7 +468,7 @@ def ldgettext(domain, message):
|
||||||
try:
|
try:
|
||||||
t = translation(domain, _localedirs.get(domain, None),
|
t = translation(domain, _localedirs.get(domain, None),
|
||||||
codeset=_localecodesets.get(domain))
|
codeset=_localecodesets.get(domain))
|
||||||
except IOError:
|
except OSError:
|
||||||
return message
|
return message
|
||||||
return t.lgettext(message)
|
return t.lgettext(message)
|
||||||
|
|
||||||
|
@ -476,7 +476,7 @@ def dngettext(domain, msgid1, msgid2, n):
|
||||||
try:
|
try:
|
||||||
t = translation(domain, _localedirs.get(domain, None),
|
t = translation(domain, _localedirs.get(domain, None),
|
||||||
codeset=_localecodesets.get(domain))
|
codeset=_localecodesets.get(domain))
|
||||||
except IOError:
|
except OSError:
|
||||||
if n == 1:
|
if n == 1:
|
||||||
return msgid1
|
return msgid1
|
||||||
else:
|
else:
|
||||||
|
@ -487,7 +487,7 @@ def ldngettext(domain, msgid1, msgid2, n):
|
||||||
try:
|
try:
|
||||||
t = translation(domain, _localedirs.get(domain, None),
|
t = translation(domain, _localedirs.get(domain, None),
|
||||||
codeset=_localecodesets.get(domain))
|
codeset=_localecodesets.get(domain))
|
||||||
except IOError:
|
except OSError:
|
||||||
if n == 1:
|
if n == 1:
|
||||||
return msgid1
|
return msgid1
|
||||||
else:
|
else:
|
||||||
|
|
20
Lib/gzip.py
20
Lib/gzip.py
|
@ -287,10 +287,10 @@ class GzipFile(io.BufferedIOBase):
|
||||||
raise EOFError("Reached EOF")
|
raise EOFError("Reached EOF")
|
||||||
|
|
||||||
if magic != b'\037\213':
|
if magic != b'\037\213':
|
||||||
raise IOError('Not a gzipped file')
|
raise OSError('Not a gzipped file')
|
||||||
method = ord( self.fileobj.read(1) )
|
method = ord( self.fileobj.read(1) )
|
||||||
if method != 8:
|
if method != 8:
|
||||||
raise IOError('Unknown compression method')
|
raise OSError('Unknown compression method')
|
||||||
flag = ord( self.fileobj.read(1) )
|
flag = ord( self.fileobj.read(1) )
|
||||||
self.mtime = read32(self.fileobj)
|
self.mtime = read32(self.fileobj)
|
||||||
# extraflag = self.fileobj.read(1)
|
# extraflag = self.fileobj.read(1)
|
||||||
|
@ -326,7 +326,7 @@ class GzipFile(io.BufferedIOBase):
|
||||||
self._check_closed()
|
self._check_closed()
|
||||||
if self.mode != WRITE:
|
if self.mode != WRITE:
|
||||||
import errno
|
import errno
|
||||||
raise IOError(errno.EBADF, "write() on read-only GzipFile object")
|
raise OSError(errno.EBADF, "write() on read-only GzipFile object")
|
||||||
|
|
||||||
if self.fileobj is None:
|
if self.fileobj is None:
|
||||||
raise ValueError("write() on closed GzipFile object")
|
raise ValueError("write() on closed GzipFile object")
|
||||||
|
@ -347,7 +347,7 @@ class GzipFile(io.BufferedIOBase):
|
||||||
self._check_closed()
|
self._check_closed()
|
||||||
if self.mode != READ:
|
if self.mode != READ:
|
||||||
import errno
|
import errno
|
||||||
raise IOError(errno.EBADF, "read() on write-only GzipFile object")
|
raise OSError(errno.EBADF, "read() on write-only GzipFile object")
|
||||||
|
|
||||||
if self.extrasize <= 0 and self.fileobj is None:
|
if self.extrasize <= 0 and self.fileobj is None:
|
||||||
return b''
|
return b''
|
||||||
|
@ -380,7 +380,7 @@ class GzipFile(io.BufferedIOBase):
|
||||||
self._check_closed()
|
self._check_closed()
|
||||||
if self.mode != READ:
|
if self.mode != READ:
|
||||||
import errno
|
import errno
|
||||||
raise IOError(errno.EBADF, "read1() on write-only GzipFile object")
|
raise OSError(errno.EBADF, "read1() on write-only GzipFile object")
|
||||||
|
|
||||||
if self.extrasize <= 0 and self.fileobj is None:
|
if self.extrasize <= 0 and self.fileobj is None:
|
||||||
return b''
|
return b''
|
||||||
|
@ -404,7 +404,7 @@ class GzipFile(io.BufferedIOBase):
|
||||||
def peek(self, n):
|
def peek(self, n):
|
||||||
if self.mode != READ:
|
if self.mode != READ:
|
||||||
import errno
|
import errno
|
||||||
raise IOError(errno.EBADF, "peek() on write-only GzipFile object")
|
raise OSError(errno.EBADF, "peek() on write-only GzipFile object")
|
||||||
|
|
||||||
# Do not return ridiculously small buffers, for one common idiom
|
# Do not return ridiculously small buffers, for one common idiom
|
||||||
# is to call peek(1) and expect more bytes in return.
|
# is to call peek(1) and expect more bytes in return.
|
||||||
|
@ -487,10 +487,10 @@ class GzipFile(io.BufferedIOBase):
|
||||||
crc32 = read32(self.fileobj)
|
crc32 = read32(self.fileobj)
|
||||||
isize = read32(self.fileobj) # may exceed 2GB
|
isize = read32(self.fileobj) # may exceed 2GB
|
||||||
if crc32 != self.crc:
|
if crc32 != self.crc:
|
||||||
raise IOError("CRC check failed %s != %s" % (hex(crc32),
|
raise OSError("CRC check failed %s != %s" % (hex(crc32),
|
||||||
hex(self.crc)))
|
hex(self.crc)))
|
||||||
elif isize != (self.size & 0xffffffff):
|
elif isize != (self.size & 0xffffffff):
|
||||||
raise IOError("Incorrect length of data produced")
|
raise OSError("Incorrect length of data produced")
|
||||||
|
|
||||||
# Gzip files can be padded with zeroes and still have archives.
|
# Gzip files can be padded with zeroes and still have archives.
|
||||||
# Consume all zero bytes and set the file position to the first
|
# Consume all zero bytes and set the file position to the first
|
||||||
|
@ -539,7 +539,7 @@ class GzipFile(io.BufferedIOBase):
|
||||||
'''Return the uncompressed stream file position indicator to the
|
'''Return the uncompressed stream file position indicator to the
|
||||||
beginning of the file'''
|
beginning of the file'''
|
||||||
if self.mode != READ:
|
if self.mode != READ:
|
||||||
raise IOError("Can't rewind in write mode")
|
raise OSError("Can't rewind in write mode")
|
||||||
self.fileobj.seek(0)
|
self.fileobj.seek(0)
|
||||||
self._new_member = True
|
self._new_member = True
|
||||||
self.extrabuf = b""
|
self.extrabuf = b""
|
||||||
|
@ -564,7 +564,7 @@ class GzipFile(io.BufferedIOBase):
|
||||||
raise ValueError('Seek from end not supported')
|
raise ValueError('Seek from end not supported')
|
||||||
if self.mode == WRITE:
|
if self.mode == WRITE:
|
||||||
if offset < self.offset:
|
if offset < self.offset:
|
||||||
raise IOError('Negative seek in write mode')
|
raise OSError('Negative seek in write mode')
|
||||||
count = offset - self.offset
|
count = offset - self.offset
|
||||||
chunk = bytes(1024)
|
chunk = bytes(1024)
|
||||||
for i in range(count // 1024):
|
for i in range(count // 1024):
|
||||||
|
|
|
@ -1730,8 +1730,8 @@ class CookieJar:
|
||||||
return "<%s[%s]>" % (self.__class__, ", ".join(r))
|
return "<%s[%s]>" % (self.__class__, ", ".join(r))
|
||||||
|
|
||||||
|
|
||||||
# derives from IOError for backwards-compatibility with Python 2.4.0
|
# derives from OSError for backwards-compatibility with Python 2.4.0
|
||||||
class LoadError(IOError): pass
|
class LoadError(OSError): pass
|
||||||
|
|
||||||
class FileCookieJar(CookieJar):
|
class FileCookieJar(CookieJar):
|
||||||
"""CookieJar that can be loaded from and saved to a file."""
|
"""CookieJar that can be loaded from and saved to a file."""
|
||||||
|
@ -1771,7 +1771,7 @@ class FileCookieJar(CookieJar):
|
||||||
ignore_discard=False, ignore_expires=False):
|
ignore_discard=False, ignore_expires=False):
|
||||||
"""Clear all cookies and reload cookies from a saved file.
|
"""Clear all cookies and reload cookies from a saved file.
|
||||||
|
|
||||||
Raises LoadError (or IOError) if reversion is not successful; the
|
Raises LoadError (or OSError) if reversion is not successful; the
|
||||||
object's state will not be altered if this happens.
|
object's state will not be altered if this happens.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -1786,7 +1786,7 @@ class FileCookieJar(CookieJar):
|
||||||
self._cookies = {}
|
self._cookies = {}
|
||||||
try:
|
try:
|
||||||
self.load(filename, ignore_discard, ignore_expires)
|
self.load(filename, ignore_discard, ignore_expires)
|
||||||
except (LoadError, IOError):
|
except OSError:
|
||||||
self._cookies = old_state
|
self._cookies = old_state
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -1937,8 +1937,7 @@ class LWPCookieJar(FileCookieJar):
|
||||||
if not ignore_expires and c.is_expired(now):
|
if not ignore_expires and c.is_expired(now):
|
||||||
continue
|
continue
|
||||||
self.set_cookie(c)
|
self.set_cookie(c)
|
||||||
|
except OSError:
|
||||||
except IOError:
|
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
_warn_unhandled_exception()
|
_warn_unhandled_exception()
|
||||||
|
@ -2044,7 +2043,7 @@ class MozillaCookieJar(FileCookieJar):
|
||||||
continue
|
continue
|
||||||
self.set_cookie(c)
|
self.set_cookie(c)
|
||||||
|
|
||||||
except IOError:
|
except OSError:
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
_warn_unhandled_exception()
|
_warn_unhandled_exception()
|
||||||
|
|
|
@ -711,7 +711,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||||
ctype = self.guess_type(path)
|
ctype = self.guess_type(path)
|
||||||
try:
|
try:
|
||||||
f = open(path, 'rb')
|
f = open(path, 'rb')
|
||||||
except IOError:
|
except OSError:
|
||||||
self.send_error(404, "File not found")
|
self.send_error(404, "File not found")
|
||||||
return None
|
return None
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
|
|
|
@ -886,7 +886,7 @@ class EditorWindow(object):
|
||||||
with open(self.recent_files_path, 'w',
|
with open(self.recent_files_path, 'w',
|
||||||
encoding='utf_8', errors='replace') as rf_file:
|
encoding='utf_8', errors='replace') as rf_file:
|
||||||
rf_file.writelines(rf_list)
|
rf_file.writelines(rf_list)
|
||||||
except IOError as err:
|
except OSError as err:
|
||||||
if not getattr(self.root, "recentfilelist_error_displayed", False):
|
if not getattr(self.root, "recentfilelist_error_displayed", False):
|
||||||
self.root.recentfilelist_error_displayed = True
|
self.root.recentfilelist_error_displayed = True
|
||||||
tkMessageBox.showerror(title='IDLE Error',
|
tkMessageBox.showerror(title='IDLE Error',
|
||||||
|
|
|
@ -82,7 +82,7 @@ class GrepDialog(SearchDialogBase):
|
||||||
for fn in list:
|
for fn in list:
|
||||||
try:
|
try:
|
||||||
f = open(fn, errors='replace')
|
f = open(fn, errors='replace')
|
||||||
except IOError as msg:
|
except OSError as msg:
|
||||||
print(msg)
|
print(msg)
|
||||||
continue
|
continue
|
||||||
lineno = 0
|
lineno = 0
|
||||||
|
|
|
@ -212,7 +212,7 @@ class IOBinding:
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
bytes = f.read()
|
bytes = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
except IOError as msg:
|
except OSError as msg:
|
||||||
tkMessageBox.showerror("I/O Error", str(msg), master=self.text)
|
tkMessageBox.showerror("I/O Error", str(msg), master=self.text)
|
||||||
return False
|
return False
|
||||||
chars, converted = self._decode(two_lines, bytes)
|
chars, converted = self._decode(two_lines, bytes)
|
||||||
|
@ -377,7 +377,7 @@ class IOBinding:
|
||||||
f.flush()
|
f.flush()
|
||||||
f.close()
|
f.close()
|
||||||
return True
|
return True
|
||||||
except IOError as msg:
|
except OSError as msg:
|
||||||
tkMessageBox.showerror("I/O Error", str(msg),
|
tkMessageBox.showerror("I/O Error", str(msg),
|
||||||
master=self.text)
|
master=self.text)
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -106,7 +106,7 @@ class OutputWindow(EditorWindow):
|
||||||
f = open(filename, "r")
|
f = open(filename, "r")
|
||||||
f.close()
|
f.close()
|
||||||
break
|
break
|
||||||
except IOError:
|
except OSError:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -58,7 +58,7 @@ else:
|
||||||
try:
|
try:
|
||||||
file.write(warnings.formatwarning(message, category, filename,
|
file.write(warnings.formatwarning(message, category, filename,
|
||||||
lineno, line=line))
|
lineno, line=line))
|
||||||
except IOError:
|
except OSError:
|
||||||
pass ## file (probably __stderr__) is invalid, warning dropped.
|
pass ## file (probably __stderr__) is invalid, warning dropped.
|
||||||
warnings.showwarning = idle_showwarning
|
warnings.showwarning = idle_showwarning
|
||||||
def idle_formatwarning(message, category, filename, lineno, line=None):
|
def idle_formatwarning(message, category, filename, lineno, line=None):
|
||||||
|
@ -211,7 +211,7 @@ class PyShellEditorWindow(EditorWindow):
|
||||||
try:
|
try:
|
||||||
with open(self.breakpointPath, "r") as fp:
|
with open(self.breakpointPath, "r") as fp:
|
||||||
lines = fp.readlines()
|
lines = fp.readlines()
|
||||||
except IOError:
|
except OSError:
|
||||||
lines = []
|
lines = []
|
||||||
try:
|
try:
|
||||||
with open(self.breakpointPath, "w") as new_file:
|
with open(self.breakpointPath, "w") as new_file:
|
||||||
|
@ -222,7 +222,7 @@ class PyShellEditorWindow(EditorWindow):
|
||||||
breaks = self.breakpoints
|
breaks = self.breakpoints
|
||||||
if breaks:
|
if breaks:
|
||||||
new_file.write(filename + '=' + str(breaks) + '\n')
|
new_file.write(filename + '=' + str(breaks) + '\n')
|
||||||
except IOError as err:
|
except OSError as err:
|
||||||
if not getattr(self.root, "breakpoint_error_displayed", False):
|
if not getattr(self.root, "breakpoint_error_displayed", False):
|
||||||
self.root.breakpoint_error_displayed = True
|
self.root.breakpoint_error_displayed = True
|
||||||
tkMessageBox.showerror(title='IDLE Error',
|
tkMessageBox.showerror(title='IDLE Error',
|
||||||
|
@ -528,7 +528,7 @@ class ModifiedInterpreter(InteractiveInterpreter):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
response = clt.pollresponse(self.active_seq, wait=0.05)
|
response = clt.pollresponse(self.active_seq, wait=0.05)
|
||||||
except (EOFError, IOError, KeyboardInterrupt):
|
except (EOFError, OSError, KeyboardInterrupt):
|
||||||
# lost connection or subprocess terminated itself, restart
|
# lost connection or subprocess terminated itself, restart
|
||||||
# [the KBI is from rpc.SocketIO.handle_EOF()]
|
# [the KBI is from rpc.SocketIO.handle_EOF()]
|
||||||
if self.tkconsole.closing:
|
if self.tkconsole.closing:
|
||||||
|
|
|
@ -142,7 +142,7 @@ class IdleUserConfParser(IdleConfParser):
|
||||||
fname = self.file
|
fname = self.file
|
||||||
try:
|
try:
|
||||||
cfgFile = open(fname, 'w')
|
cfgFile = open(fname, 'w')
|
||||||
except IOError:
|
except OSError:
|
||||||
os.unlink(fname)
|
os.unlink(fname)
|
||||||
cfgFile = open(fname, 'w')
|
cfgFile = open(fname, 'w')
|
||||||
with cfgFile:
|
with cfgFile:
|
||||||
|
@ -207,7 +207,7 @@ class IdleConf:
|
||||||
userDir+',\n but the path does not exist.\n')
|
userDir+',\n but the path does not exist.\n')
|
||||||
try:
|
try:
|
||||||
sys.stderr.write(warn)
|
sys.stderr.write(warn)
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
userDir = '~'
|
userDir = '~'
|
||||||
if userDir == "~": # still no path to home!
|
if userDir == "~": # still no path to home!
|
||||||
|
@ -217,7 +217,7 @@ class IdleConf:
|
||||||
if not os.path.exists(userDir):
|
if not os.path.exists(userDir):
|
||||||
try:
|
try:
|
||||||
os.mkdir(userDir)
|
os.mkdir(userDir)
|
||||||
except (OSError, IOError):
|
except OSError:
|
||||||
warn = ('\n Warning: unable to create user config directory\n'+
|
warn = ('\n Warning: unable to create user config directory\n'+
|
||||||
userDir+'\n Check path and permissions.\n Exiting!\n\n')
|
userDir+'\n Check path and permissions.\n Exiting!\n\n')
|
||||||
sys.stderr.write(warn)
|
sys.stderr.write(warn)
|
||||||
|
@ -251,7 +251,7 @@ class IdleConf:
|
||||||
raw=raw)))
|
raw=raw)))
|
||||||
try:
|
try:
|
||||||
sys.stderr.write(warning)
|
sys.stderr.write(warning)
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
if self.defaultCfg[configType].has_option(section,option):
|
if self.defaultCfg[configType].has_option(section,option):
|
||||||
|
@ -268,7 +268,7 @@ class IdleConf:
|
||||||
(option, section, default))
|
(option, section, default))
|
||||||
try:
|
try:
|
||||||
sys.stderr.write(warning)
|
sys.stderr.write(warning)
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
@ -380,7 +380,7 @@ class IdleConf:
|
||||||
(element, themeName, theme[element]))
|
(element, themeName, theme[element]))
|
||||||
try:
|
try:
|
||||||
sys.stderr.write(warning)
|
sys.stderr.write(warning)
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
colour=cfgParser.Get(themeName,element,default=theme[element])
|
colour=cfgParser.Get(themeName,element,default=theme[element])
|
||||||
theme[element]=colour
|
theme[element]=colour
|
||||||
|
@ -637,7 +637,7 @@ class IdleConf:
|
||||||
(event, keySetName, keyBindings[event]))
|
(event, keySetName, keyBindings[event]))
|
||||||
try:
|
try:
|
||||||
sys.stderr.write(warning)
|
sys.stderr.write(warning)
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
return keyBindings
|
return keyBindings
|
||||||
|
|
||||||
|
|
|
@ -339,7 +339,7 @@ class SocketIO(object):
|
||||||
r, w, x = select.select([], [self.sock], [])
|
r, w, x = select.select([], [self.sock], [])
|
||||||
n = self.sock.send(s[:BUFSIZE])
|
n = self.sock.send(s[:BUFSIZE])
|
||||||
except (AttributeError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
raise IOError("socket no longer exists")
|
raise OSError("socket no longer exists")
|
||||||
except OSError:
|
except OSError:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -66,7 +66,7 @@ def view_file(parent, title, filename, encoding=None, modal=True):
|
||||||
try:
|
try:
|
||||||
with open(filename, 'r', encoding=encoding) as file:
|
with open(filename, 'r', encoding=encoding) as file:
|
||||||
contents = file.read()
|
contents = file.read()
|
||||||
except IOError:
|
except OSError:
|
||||||
import tkinter.messagebox as tkMessageBox
|
import tkinter.messagebox as tkMessageBox
|
||||||
tkMessageBox.showerror(title='File Load Error',
|
tkMessageBox.showerror(title='File Load Error',
|
||||||
message='Unable to load file %r .' % filename,
|
message='Unable to load file %r .' % filename,
|
||||||
|
|
|
@ -149,7 +149,7 @@ def testall(list, recursive, toplevel):
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
try:
|
try:
|
||||||
print(what(filename))
|
print(what(filename))
|
||||||
except IOError:
|
except OSError:
|
||||||
print('*** not found ***')
|
print('*** not found ***')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -915,7 +915,7 @@ class SourceLoader(_LoaderBasics):
|
||||||
path = self.get_filename(fullname)
|
path = self.get_filename(fullname)
|
||||||
try:
|
try:
|
||||||
source_bytes = self.get_data(path)
|
source_bytes = self.get_data(path)
|
||||||
except IOError as exc:
|
except OSError as exc:
|
||||||
raise ImportError("source not available through get_data()",
|
raise ImportError("source not available through get_data()",
|
||||||
name=fullname) from exc
|
name=fullname) from exc
|
||||||
readsource = _io.BytesIO(source_bytes).readline
|
readsource = _io.BytesIO(source_bytes).readline
|
||||||
|
@ -961,7 +961,7 @@ class SourceLoader(_LoaderBasics):
|
||||||
source_mtime = int(st['mtime'])
|
source_mtime = int(st['mtime'])
|
||||||
try:
|
try:
|
||||||
data = self.get_data(bytecode_path)
|
data = self.get_data(bytecode_path)
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -545,13 +545,13 @@ def findsource(object):
|
||||||
|
|
||||||
The argument may be a module, class, method, function, traceback, frame,
|
The argument may be a module, class, method, function, traceback, frame,
|
||||||
or code object. The source code is returned as a list of all the lines
|
or code object. The source code is returned as a list of all the lines
|
||||||
in the file and the line number indexes a line in that list. An IOError
|
in the file and the line number indexes a line in that list. An OSError
|
||||||
is raised if the source code cannot be retrieved."""
|
is raised if the source code cannot be retrieved."""
|
||||||
|
|
||||||
file = getfile(object)
|
file = getfile(object)
|
||||||
sourcefile = getsourcefile(object)
|
sourcefile = getsourcefile(object)
|
||||||
if not sourcefile and file[0] + file[-1] != '<>':
|
if not sourcefile and file[0] + file[-1] != '<>':
|
||||||
raise IOError('source code not available')
|
raise OSError('source code not available')
|
||||||
file = sourcefile if sourcefile else file
|
file = sourcefile if sourcefile else file
|
||||||
|
|
||||||
module = getmodule(object, file)
|
module = getmodule(object, file)
|
||||||
|
@ -560,7 +560,7 @@ def findsource(object):
|
||||||
else:
|
else:
|
||||||
lines = linecache.getlines(file)
|
lines = linecache.getlines(file)
|
||||||
if not lines:
|
if not lines:
|
||||||
raise IOError('could not get source code')
|
raise OSError('could not get source code')
|
||||||
|
|
||||||
if ismodule(object):
|
if ismodule(object):
|
||||||
return lines, 0
|
return lines, 0
|
||||||
|
@ -586,7 +586,7 @@ def findsource(object):
|
||||||
candidates.sort()
|
candidates.sort()
|
||||||
return lines, candidates[0][1]
|
return lines, candidates[0][1]
|
||||||
else:
|
else:
|
||||||
raise IOError('could not find class definition')
|
raise OSError('could not find class definition')
|
||||||
|
|
||||||
if ismethod(object):
|
if ismethod(object):
|
||||||
object = object.__func__
|
object = object.__func__
|
||||||
|
@ -598,14 +598,14 @@ def findsource(object):
|
||||||
object = object.f_code
|
object = object.f_code
|
||||||
if iscode(object):
|
if iscode(object):
|
||||||
if not hasattr(object, 'co_firstlineno'):
|
if not hasattr(object, 'co_firstlineno'):
|
||||||
raise IOError('could not find function definition')
|
raise OSError('could not find function definition')
|
||||||
lnum = object.co_firstlineno - 1
|
lnum = object.co_firstlineno - 1
|
||||||
pat = re.compile(r'^(\s*def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)')
|
pat = re.compile(r'^(\s*def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)')
|
||||||
while lnum > 0:
|
while lnum > 0:
|
||||||
if pat.match(lines[lnum]): break
|
if pat.match(lines[lnum]): break
|
||||||
lnum = lnum - 1
|
lnum = lnum - 1
|
||||||
return lines, lnum
|
return lines, lnum
|
||||||
raise IOError('could not find code object')
|
raise OSError('could not find code object')
|
||||||
|
|
||||||
def getcomments(object):
|
def getcomments(object):
|
||||||
"""Get lines of comments immediately preceding an object's source code.
|
"""Get lines of comments immediately preceding an object's source code.
|
||||||
|
@ -614,7 +614,7 @@ def getcomments(object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
lines, lnum = findsource(object)
|
lines, lnum = findsource(object)
|
||||||
except (IOError, TypeError):
|
except (OSError, TypeError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if ismodule(object):
|
if ismodule(object):
|
||||||
|
@ -710,7 +710,7 @@ def getsourcelines(object):
|
||||||
The argument may be a module, class, method, function, traceback, frame,
|
The argument may be a module, class, method, function, traceback, frame,
|
||||||
or code object. The source code is returned as a list of the lines
|
or code object. The source code is returned as a list of the lines
|
||||||
corresponding to the object and the line number indicates where in the
|
corresponding to the object and the line number indicates where in the
|
||||||
original source file the first line of code was found. An IOError is
|
original source file the first line of code was found. An OSError is
|
||||||
raised if the source code cannot be retrieved."""
|
raised if the source code cannot be retrieved."""
|
||||||
lines, lnum = findsource(object)
|
lines, lnum = findsource(object)
|
||||||
|
|
||||||
|
@ -722,7 +722,7 @@ def getsource(object):
|
||||||
|
|
||||||
The argument may be a module, class, method, function, traceback, frame,
|
The argument may be a module, class, method, function, traceback, frame,
|
||||||
or code object. The source code is returned as a single string. An
|
or code object. The source code is returned as a single string. An
|
||||||
IOError is raised if the source code cannot be retrieved."""
|
OSError is raised if the source code cannot be retrieved."""
|
||||||
lines, lnum = getsourcelines(object)
|
lines, lnum = getsourcelines(object)
|
||||||
return ''.join(lines)
|
return ''.join(lines)
|
||||||
|
|
||||||
|
@ -1122,7 +1122,7 @@ def getframeinfo(frame, context=1):
|
||||||
start = lineno - 1 - context//2
|
start = lineno - 1 - context//2
|
||||||
try:
|
try:
|
||||||
lines, lnum = findsource(frame)
|
lines, lnum = findsource(frame)
|
||||||
except IOError:
|
except OSError:
|
||||||
lines = index = None
|
lines = index = None
|
||||||
else:
|
else:
|
||||||
start = max(start, 1)
|
start = max(start, 1)
|
||||||
|
|
|
@ -4,7 +4,7 @@ builtin open function is defined in this module.
|
||||||
At the top of the I/O hierarchy is the abstract base class IOBase. It
|
At the top of the I/O hierarchy is the abstract base class IOBase. It
|
||||||
defines the basic interface to a stream. Note, however, that there is no
|
defines the basic interface to a stream. Note, however, that there is no
|
||||||
separation between reading and writing to streams; implementations are
|
separation between reading and writing to streams; implementations are
|
||||||
allowed to raise an IOError if they do not support a given operation.
|
allowed to raise an OSError if they do not support a given operation.
|
||||||
|
|
||||||
Extending IOBase is RawIOBase which deals simply with the reading and
|
Extending IOBase is RawIOBase which deals simply with the reading and
|
||||||
writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide
|
writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Converter(grammar.Grammar):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
f = open(filename)
|
f = open(filename)
|
||||||
except IOError as err:
|
except OSError as err:
|
||||||
print("Can't open %s: %s" % (filename, err))
|
print("Can't open %s: %s" % (filename, err))
|
||||||
return False
|
return False
|
||||||
self.symbol2number = {}
|
self.symbol2number = {}
|
||||||
|
@ -111,7 +111,7 @@ class Converter(grammar.Grammar):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
f = open(filename)
|
f = open(filename)
|
||||||
except IOError as err:
|
except OSError as err:
|
||||||
print("Can't open %s: %s" % (filename, err))
|
print("Can't open %s: %s" % (filename, err))
|
||||||
return False
|
return False
|
||||||
# The code below essentially uses f's iterator-ness!
|
# The code below essentially uses f's iterator-ness!
|
||||||
|
|
|
@ -123,7 +123,7 @@ def load_grammar(gt="Grammar.txt", gp=None,
|
||||||
logger.info("Writing grammar tables to %s", gp)
|
logger.info("Writing grammar tables to %s", gp)
|
||||||
try:
|
try:
|
||||||
g.dump(gp)
|
g.dump(gp)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
logger.info("Writing failed:"+str(e))
|
logger.info("Writing failed:"+str(e))
|
||||||
else:
|
else:
|
||||||
g = grammar.Grammar()
|
g = grammar.Grammar()
|
||||||
|
|
|
@ -326,7 +326,7 @@ class RefactoringTool(object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
f = open(filename, "rb")
|
f = open(filename, "rb")
|
||||||
except IOError as err:
|
except OSError as err:
|
||||||
self.log_error("Can't open %s: %s", filename, err)
|
self.log_error("Can't open %s: %s", filename, err)
|
||||||
return None, None
|
return None, None
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -91,7 +91,7 @@ def updatecache(filename, module_globals=None):
|
||||||
if name and get_source:
|
if name and get_source:
|
||||||
try:
|
try:
|
||||||
data = get_source(name)
|
data = get_source(name)
|
||||||
except (ImportError, IOError):
|
except (ImportError, OSError):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if data is None:
|
if data is None:
|
||||||
|
@ -125,7 +125,7 @@ def updatecache(filename, module_globals=None):
|
||||||
try:
|
try:
|
||||||
with tokenize.open(fullname) as fp:
|
with tokenize.open(fullname) as fp:
|
||||||
lines = fp.readlines()
|
lines = fp.readlines()
|
||||||
except IOError:
|
except OSError:
|
||||||
return []
|
return []
|
||||||
if lines and not lines[-1].endswith('\n'):
|
if lines and not lines[-1].endswith('\n'):
|
||||||
lines[-1] += '\n'
|
lines[-1] += '\n'
|
||||||
|
|
|
@ -896,7 +896,7 @@ class Handler(Filterer):
|
||||||
# couldn't find the right stack frame, for some reason
|
# couldn't find the right stack frame, for some reason
|
||||||
sys.stderr.write('Logged from file %s, line %s\n' % (
|
sys.stderr.write('Logged from file %s, line %s\n' % (
|
||||||
record.filename, record.lineno))
|
record.filename, record.lineno))
|
||||||
except IOError: #pragma: no cover
|
except OSError: #pragma: no cover
|
||||||
pass # see issue 5971
|
pass # see issue 5971
|
||||||
finally:
|
finally:
|
||||||
del t, v, tb
|
del t, v, tb
|
||||||
|
@ -1838,7 +1838,7 @@ def shutdown(handlerList=_handlerList):
|
||||||
h.acquire()
|
h.acquire()
|
||||||
h.flush()
|
h.flush()
|
||||||
h.close()
|
h.close()
|
||||||
except (IOError, ValueError):
|
except (OSError, ValueError):
|
||||||
# Ignore errors which might be caused
|
# Ignore errors which might be caused
|
||||||
# because handlers have been closed but
|
# because handlers have been closed but
|
||||||
# references to them are still around at
|
# references to them are still around at
|
||||||
|
|
|
@ -585,7 +585,7 @@ class _singlefileMailbox(Mailbox):
|
||||||
Mailbox.__init__(self, path, factory, create)
|
Mailbox.__init__(self, path, factory, create)
|
||||||
try:
|
try:
|
||||||
f = open(self._path, 'rb+')
|
f = open(self._path, 'rb+')
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
if create:
|
if create:
|
||||||
f = open(self._path, 'wb+')
|
f = open(self._path, 'wb+')
|
||||||
|
@ -988,7 +988,7 @@ class MH(Mailbox):
|
||||||
path = os.path.join(self._path, str(key))
|
path = os.path.join(self._path, str(key))
|
||||||
try:
|
try:
|
||||||
f = open(path, 'rb+')
|
f = open(path, 'rb+')
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
raise KeyError('No message with key: %s' % key)
|
raise KeyError('No message with key: %s' % key)
|
||||||
else:
|
else:
|
||||||
|
@ -1002,7 +1002,7 @@ class MH(Mailbox):
|
||||||
path = os.path.join(self._path, str(key))
|
path = os.path.join(self._path, str(key))
|
||||||
try:
|
try:
|
||||||
f = open(path, 'rb+')
|
f = open(path, 'rb+')
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
raise KeyError('No message with key: %s' % key)
|
raise KeyError('No message with key: %s' % key)
|
||||||
else:
|
else:
|
||||||
|
@ -1028,7 +1028,7 @@ class MH(Mailbox):
|
||||||
f = open(os.path.join(self._path, str(key)), 'rb+')
|
f = open(os.path.join(self._path, str(key)), 'rb+')
|
||||||
else:
|
else:
|
||||||
f = open(os.path.join(self._path, str(key)), 'rb')
|
f = open(os.path.join(self._path, str(key)), 'rb')
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
raise KeyError('No message with key: %s' % key)
|
raise KeyError('No message with key: %s' % key)
|
||||||
else:
|
else:
|
||||||
|
@ -1055,7 +1055,7 @@ class MH(Mailbox):
|
||||||
f = open(os.path.join(self._path, str(key)), 'rb+')
|
f = open(os.path.join(self._path, str(key)), 'rb+')
|
||||||
else:
|
else:
|
||||||
f = open(os.path.join(self._path, str(key)), 'rb')
|
f = open(os.path.join(self._path, str(key)), 'rb')
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
raise KeyError('No message with key: %s' % key)
|
raise KeyError('No message with key: %s' % key)
|
||||||
else:
|
else:
|
||||||
|
@ -1075,7 +1075,7 @@ class MH(Mailbox):
|
||||||
"""Return a file-like representation or raise a KeyError."""
|
"""Return a file-like representation or raise a KeyError."""
|
||||||
try:
|
try:
|
||||||
f = open(os.path.join(self._path, str(key)), 'rb')
|
f = open(os.path.join(self._path, str(key)), 'rb')
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
raise KeyError('No message with key: %s' % key)
|
raise KeyError('No message with key: %s' % key)
|
||||||
else:
|
else:
|
||||||
|
@ -2068,7 +2068,7 @@ def _lock_file(f, dotlock=True):
|
||||||
if fcntl:
|
if fcntl:
|
||||||
try:
|
try:
|
||||||
fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno in (errno.EAGAIN, errno.EACCES, errno.EROFS):
|
if e.errno in (errno.EAGAIN, errno.EACCES, errno.EROFS):
|
||||||
raise ExternalClashError('lockf: lock unavailable: %s' %
|
raise ExternalClashError('lockf: lock unavailable: %s' %
|
||||||
f.name)
|
f.name)
|
||||||
|
@ -2078,7 +2078,7 @@ def _lock_file(f, dotlock=True):
|
||||||
try:
|
try:
|
||||||
pre_lock = _create_temporary(f.name + '.lock')
|
pre_lock = _create_temporary(f.name + '.lock')
|
||||||
pre_lock.close()
|
pre_lock.close()
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno in (errno.EACCES, errno.EROFS):
|
if e.errno in (errno.EACCES, errno.EROFS):
|
||||||
return # Without write access, just skip dotlocking.
|
return # Without write access, just skip dotlocking.
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -20,7 +20,7 @@ def getcaps():
|
||||||
for mailcap in listmailcapfiles():
|
for mailcap in listmailcapfiles():
|
||||||
try:
|
try:
|
||||||
fp = open(mailcap, 'r')
|
fp = open(mailcap, 'r')
|
||||||
except IOError:
|
except OSError:
|
||||||
continue
|
continue
|
||||||
morecaps = readmailcapfile(fp)
|
morecaps = readmailcapfile(fp)
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
|
@ -359,7 +359,7 @@ def init(files=None):
|
||||||
def read_mime_types(file):
|
def read_mime_types(file):
|
||||||
try:
|
try:
|
||||||
f = open(file)
|
f = open(file)
|
||||||
except IOError:
|
except OSError:
|
||||||
return None
|
return None
|
||||||
db = MimeTypes()
|
db = MimeTypes()
|
||||||
db.readfp(f, True)
|
db.readfp(f, True)
|
||||||
|
|
|
@ -132,22 +132,22 @@ class _ConnectionBase:
|
||||||
|
|
||||||
def _check_closed(self):
|
def _check_closed(self):
|
||||||
if self._handle is None:
|
if self._handle is None:
|
||||||
raise IOError("handle is closed")
|
raise OSError("handle is closed")
|
||||||
|
|
||||||
def _check_readable(self):
|
def _check_readable(self):
|
||||||
if not self._readable:
|
if not self._readable:
|
||||||
raise IOError("connection is write-only")
|
raise OSError("connection is write-only")
|
||||||
|
|
||||||
def _check_writable(self):
|
def _check_writable(self):
|
||||||
if not self._writable:
|
if not self._writable:
|
||||||
raise IOError("connection is read-only")
|
raise OSError("connection is read-only")
|
||||||
|
|
||||||
def _bad_message_length(self):
|
def _bad_message_length(self):
|
||||||
if self._writable:
|
if self._writable:
|
||||||
self._readable = False
|
self._readable = False
|
||||||
else:
|
else:
|
||||||
self.close()
|
self.close()
|
||||||
raise IOError("bad message length")
|
raise OSError("bad message length")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def closed(self):
|
def closed(self):
|
||||||
|
@ -317,7 +317,7 @@ if _winapi:
|
||||||
return f
|
return f
|
||||||
elif err == _winapi.ERROR_MORE_DATA:
|
elif err == _winapi.ERROR_MORE_DATA:
|
||||||
return self._get_more_data(ov, maxsize)
|
return self._get_more_data(ov, maxsize)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.winerror == _winapi.ERROR_BROKEN_PIPE:
|
if e.winerror == _winapi.ERROR_BROKEN_PIPE:
|
||||||
raise EOFError
|
raise EOFError
|
||||||
else:
|
else:
|
||||||
|
@ -383,7 +383,7 @@ class Connection(_ConnectionBase):
|
||||||
if remaining == size:
|
if remaining == size:
|
||||||
raise EOFError
|
raise EOFError
|
||||||
else:
|
else:
|
||||||
raise IOError("got end of file during message")
|
raise OSError("got end of file during message")
|
||||||
buf.write(chunk)
|
buf.write(chunk)
|
||||||
remaining -= n
|
remaining -= n
|
||||||
return buf
|
return buf
|
||||||
|
@ -443,7 +443,7 @@ class Listener(object):
|
||||||
Returns a `Connection` object.
|
Returns a `Connection` object.
|
||||||
'''
|
'''
|
||||||
if self._listener is None:
|
if self._listener is None:
|
||||||
raise IOError('listener is closed')
|
raise OSError('listener is closed')
|
||||||
c = self._listener.accept()
|
c = self._listener.accept()
|
||||||
if self._authkey:
|
if self._authkey:
|
||||||
deliver_challenge(c, self._authkey)
|
deliver_challenge(c, self._authkey)
|
||||||
|
|
|
@ -167,7 +167,7 @@ class Server(object):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
c = self.listener.accept()
|
c = self.listener.accept()
|
||||||
except (OSError, IOError):
|
except OSError:
|
||||||
continue
|
continue
|
||||||
t = threading.Thread(target=self.handle_request, args=(c,))
|
t = threading.Thread(target=self.handle_request, args=(c,))
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
|
|
|
@ -78,8 +78,8 @@ def worker(inqueue, outqueue, initializer=None, initargs=(), maxtasks=None):
|
||||||
while maxtasks is None or (maxtasks and completed < maxtasks):
|
while maxtasks is None or (maxtasks and completed < maxtasks):
|
||||||
try:
|
try:
|
||||||
task = get()
|
task = get()
|
||||||
except (EOFError, IOError):
|
except (EOFError, OSError):
|
||||||
debug('worker got EOFError or IOError -- exiting')
|
debug('worker got EOFError or OSError -- exiting')
|
||||||
break
|
break
|
||||||
|
|
||||||
if task is None:
|
if task is None:
|
||||||
|
@ -349,7 +349,7 @@ class Pool(object):
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
put(task)
|
put(task)
|
||||||
except IOError:
|
except OSError:
|
||||||
debug('could not put task on queue')
|
debug('could not put task on queue')
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -371,8 +371,8 @@ class Pool(object):
|
||||||
debug('task handler sending sentinel to workers')
|
debug('task handler sending sentinel to workers')
|
||||||
for p in pool:
|
for p in pool:
|
||||||
put(None)
|
put(None)
|
||||||
except IOError:
|
except OSError:
|
||||||
debug('task handler got IOError when sending sentinels')
|
debug('task handler got OSError when sending sentinels')
|
||||||
|
|
||||||
debug('task handler exiting')
|
debug('task handler exiting')
|
||||||
|
|
||||||
|
@ -383,8 +383,8 @@ class Pool(object):
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
task = get()
|
task = get()
|
||||||
except (IOError, EOFError):
|
except (OSError, EOFError):
|
||||||
debug('result handler got EOFError/IOError -- exiting')
|
debug('result handler got EOFError/OSError -- exiting')
|
||||||
return
|
return
|
||||||
|
|
||||||
if thread._state:
|
if thread._state:
|
||||||
|
@ -405,8 +405,8 @@ class Pool(object):
|
||||||
while cache and thread._state != TERMINATE:
|
while cache and thread._state != TERMINATE:
|
||||||
try:
|
try:
|
||||||
task = get()
|
task = get()
|
||||||
except (IOError, EOFError):
|
except (OSError, EOFError):
|
||||||
debug('result handler got EOFError/IOError -- exiting')
|
debug('result handler got EOFError/OSError -- exiting')
|
||||||
return
|
return
|
||||||
|
|
||||||
if task is None:
|
if task is None:
|
||||||
|
@ -428,7 +428,7 @@ class Pool(object):
|
||||||
if not outqueue._reader.poll():
|
if not outqueue._reader.poll():
|
||||||
break
|
break
|
||||||
get()
|
get()
|
||||||
except (IOError, EOFError):
|
except (OSError, EOFError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
debug('result handler exiting: len(cache)=%s, thread._state=%s',
|
debug('result handler exiting: len(cache)=%s, thread._state=%s',
|
||||||
|
|
|
@ -25,7 +25,7 @@ class netrc:
|
||||||
try:
|
try:
|
||||||
file = os.path.join(os.environ['HOME'], ".netrc")
|
file = os.path.join(os.environ['HOME'], ".netrc")
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise IOError("Could not find .netrc: $HOME is not set")
|
raise OSError("Could not find .netrc: $HOME is not set")
|
||||||
self.hosts = {}
|
self.hosts = {}
|
||||||
self.macros = {}
|
self.macros = {}
|
||||||
with open(file) as fp:
|
with open(file) as fp:
|
||||||
|
|
|
@ -947,7 +947,7 @@ class _NNTPBase:
|
||||||
if auth:
|
if auth:
|
||||||
user = auth[0]
|
user = auth[0]
|
||||||
password = auth[2]
|
password = auth[2]
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
# Perform NNTP authentication if needed.
|
# Perform NNTP authentication if needed.
|
||||||
if not user:
|
if not user:
|
||||||
|
|
|
@ -23,7 +23,7 @@ def url2pathname(url):
|
||||||
comp = url.split('|')
|
comp = url.split('|')
|
||||||
if len(comp) != 2 or comp[0][-1] not in string.ascii_letters:
|
if len(comp) != 2 or comp[0][-1] not in string.ascii_letters:
|
||||||
error = 'Bad URL: ' + url
|
error = 'Bad URL: ' + url
|
||||||
raise IOError(error)
|
raise OSError(error)
|
||||||
drive = comp[0][-1].upper()
|
drive = comp[0][-1].upper()
|
||||||
components = comp[1].split('/')
|
components = comp[1].split('/')
|
||||||
path = drive + ':'
|
path = drive + ':'
|
||||||
|
@ -55,7 +55,7 @@ def pathname2url(p):
|
||||||
comp = p.split(':')
|
comp = p.split(':')
|
||||||
if len(comp) != 2 or len(comp[0]) > 1:
|
if len(comp) != 2 or len(comp[0]) > 1:
|
||||||
error = 'Bad path: ' + p
|
error = 'Bad path: ' + p
|
||||||
raise IOError(error)
|
raise OSError(error)
|
||||||
|
|
||||||
drive = urllib.parse.quote(comp[0].upper())
|
drive = urllib.parse.quote(comp[0].upper())
|
||||||
components = comp[1].split('\\')
|
components = comp[1].split('\\')
|
||||||
|
|
10
Lib/pdb.py
10
Lib/pdb.py
|
@ -92,7 +92,7 @@ def find_function(funcname, filename):
|
||||||
cre = re.compile(r'def\s+%s\s*[(]' % re.escape(funcname))
|
cre = re.compile(r'def\s+%s\s*[(]' % re.escape(funcname))
|
||||||
try:
|
try:
|
||||||
fp = open(filename)
|
fp = open(filename)
|
||||||
except IOError:
|
except OSError:
|
||||||
return None
|
return None
|
||||||
# consumer of this info expects the first line to be 1
|
# consumer of this info expects the first line to be 1
|
||||||
lineno = 1
|
lineno = 1
|
||||||
|
@ -170,12 +170,12 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(envHome, ".pdbrc")) as rcFile:
|
with open(os.path.join(envHome, ".pdbrc")) as rcFile:
|
||||||
self.rcLines.extend(rcFile)
|
self.rcLines.extend(rcFile)
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
with open(".pdbrc") as rcFile:
|
with open(".pdbrc") as rcFile:
|
||||||
self.rcLines.extend(rcFile)
|
self.rcLines.extend(rcFile)
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.commands = {} # associates a command list to breakpoint numbers
|
self.commands = {} # associates a command list to breakpoint numbers
|
||||||
|
@ -1241,7 +1241,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
breaklist = self.get_file_breaks(filename)
|
breaklist = self.get_file_breaks(filename)
|
||||||
try:
|
try:
|
||||||
lines, lineno = getsourcelines(self.curframe)
|
lines, lineno = getsourcelines(self.curframe)
|
||||||
except IOError as err:
|
except OSError as err:
|
||||||
self.error(err)
|
self.error(err)
|
||||||
return
|
return
|
||||||
self._print_lines(lines, lineno, breaklist, self.curframe)
|
self._print_lines(lines, lineno, breaklist, self.curframe)
|
||||||
|
@ -1257,7 +1257,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
lines, lineno = getsourcelines(obj)
|
lines, lineno = getsourcelines(obj)
|
||||||
except (IOError, TypeError) as err:
|
except (OSError, TypeError) as err:
|
||||||
self.error(err)
|
self.error(err)
|
||||||
return
|
return
|
||||||
self._print_lines(lines, lineno)
|
self._print_lines(lines, lineno)
|
||||||
|
|
|
@ -587,7 +587,7 @@ def extend_path(path, name):
|
||||||
if os.path.isfile(pkgfile):
|
if os.path.isfile(pkgfile):
|
||||||
try:
|
try:
|
||||||
f = open(pkgfile)
|
f = open(pkgfile)
|
||||||
except IOError as msg:
|
except OSError as msg:
|
||||||
sys.stderr.write("Can't open %s: %s\n" %
|
sys.stderr.write("Can't open %s: %s\n" %
|
||||||
(pkgfile, msg))
|
(pkgfile, msg))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -430,9 +430,6 @@ def _syscmd_ver(system='', release='', version='',
|
||||||
except OSError as why:
|
except OSError as why:
|
||||||
#print 'Command %s failed: %s' % (cmd,why)
|
#print 'Command %s failed: %s' % (cmd,why)
|
||||||
continue
|
continue
|
||||||
except IOError as why:
|
|
||||||
#print 'Command %s failed: %s' % (cmd,why)
|
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -612,7 +612,7 @@ if __name__ == '__main__':
|
||||||
if line:
|
if line:
|
||||||
try:
|
try:
|
||||||
self.stats = Stats(line)
|
self.stats = Stats(line)
|
||||||
except IOError as err:
|
except OSError as err:
|
||||||
print(err.args[1], file=self.stream)
|
print(err.args[1], file=self.stream)
|
||||||
return
|
return
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
|
|
@ -56,7 +56,7 @@ def _open_terminal():
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
tty_name, master_fd = sgi._getpty(os.O_RDWR, 0o666, 0)
|
tty_name, master_fd = sgi._getpty(os.O_RDWR, 0o666, 0)
|
||||||
except IOError as msg:
|
except OSError as msg:
|
||||||
raise OSError(msg)
|
raise OSError(msg)
|
||||||
return master_fd, tty_name
|
return master_fd, tty_name
|
||||||
for x in 'pqrstuvwxyzPQRST':
|
for x in 'pqrstuvwxyzPQRST':
|
||||||
|
@ -83,7 +83,7 @@ def slave_open(tty_name):
|
||||||
try:
|
try:
|
||||||
ioctl(result, I_PUSH, "ptem")
|
ioctl(result, I_PUSH, "ptem")
|
||||||
ioctl(result, I_PUSH, "ldterm")
|
ioctl(result, I_PUSH, "ldterm")
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ def spawn(argv, master_read=_read, stdin_read=_read):
|
||||||
restore = 0
|
restore = 0
|
||||||
try:
|
try:
|
||||||
_copy(master_fd, master_read, stdin_read)
|
_copy(master_fd, master_read, stdin_read)
|
||||||
except (IOError, OSError):
|
except OSError:
|
||||||
if restore:
|
if restore:
|
||||||
tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode)
|
tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode)
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@ def main(args=None):
|
||||||
except PyCompileError as error:
|
except PyCompileError as error:
|
||||||
rv = 1
|
rv = 1
|
||||||
sys.stderr.write("%s\n" % error.msg)
|
sys.stderr.write("%s\n" % error.msg)
|
||||||
except IOError as error:
|
except OSError as error:
|
||||||
rv = 1
|
rv = 1
|
||||||
sys.stderr.write("%s\n" % error)
|
sys.stderr.write("%s\n" % error)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -223,7 +223,7 @@ def synopsis(filename, cache={}):
|
||||||
if lastupdate is None or lastupdate < mtime:
|
if lastupdate is None or lastupdate < mtime:
|
||||||
try:
|
try:
|
||||||
file = tokenize.open(filename)
|
file = tokenize.open(filename)
|
||||||
except IOError:
|
except OSError:
|
||||||
# module can't be opened, so skip it
|
# module can't be opened, so skip it
|
||||||
return None
|
return None
|
||||||
binary_suffixes = importlib.machinery.BYTECODE_SUFFIXES[:]
|
binary_suffixes = importlib.machinery.BYTECODE_SUFFIXES[:]
|
||||||
|
@ -1419,7 +1419,7 @@ def pipepager(text, cmd):
|
||||||
try:
|
try:
|
||||||
pipe.write(text)
|
pipe.write(text)
|
||||||
pipe.close()
|
pipe.close()
|
||||||
except IOError:
|
except OSError:
|
||||||
pass # Ignore broken pipes caused by quitting the pager program.
|
pass # Ignore broken pipes caused by quitting the pager program.
|
||||||
|
|
||||||
def tempfilepager(text, cmd):
|
def tempfilepager(text, cmd):
|
||||||
|
|
|
@ -223,7 +223,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
fp = open(file, "rb")
|
fp = open(file, "rb")
|
||||||
except IOError as msg:
|
except OSError as msg:
|
||||||
sys.stderr.write("%s: can't open (%s)\n" % (file, msg))
|
sys.stderr.write("%s: can't open (%s)\n" % (file, msg))
|
||||||
sts = 1
|
sts = 1
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -153,7 +153,7 @@ def addpackage(sitedir, name, known_paths):
|
||||||
fullname = os.path.join(sitedir, name)
|
fullname = os.path.join(sitedir, name)
|
||||||
try:
|
try:
|
||||||
f = open(fullname, "r")
|
f = open(fullname, "r")
|
||||||
except IOError:
|
except OSError:
|
||||||
return
|
return
|
||||||
with f:
|
with f:
|
||||||
for n, line in enumerate(f):
|
for n, line in enumerate(f):
|
||||||
|
@ -388,7 +388,7 @@ class _Printer(object):
|
||||||
data = fp.read()
|
data = fp.read()
|
||||||
fp.close()
|
fp.close()
|
||||||
break
|
break
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
if data:
|
if data:
|
||||||
break
|
break
|
||||||
|
|
|
@ -11,7 +11,7 @@ The return tuple contains the following items, in this order:
|
||||||
- number of bits/sample, or 'U' for U-LAW, or 'A' for A-LAW
|
- number of bits/sample, or 'U' for U-LAW, or 'A' for A-LAW
|
||||||
|
|
||||||
If the file doesn't have a recognizable type, it returns None.
|
If the file doesn't have a recognizable type, it returns None.
|
||||||
If the file can't be opened, IOError is raised.
|
If the file can't be opened, OSError is raised.
|
||||||
|
|
||||||
To compute the total time, divide the number of frames by the
|
To compute the total time, divide the number of frames by the
|
||||||
sampling rate (a frame contains a sample for each channel).
|
sampling rate (a frame contains a sample for each channel).
|
||||||
|
@ -230,7 +230,7 @@ def testall(list, recursive, toplevel):
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
try:
|
try:
|
||||||
print(what(filename))
|
print(what(filename))
|
||||||
except IOError:
|
except OSError:
|
||||||
print('*** not found ***')
|
print('*** not found ***')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -291,7 +291,7 @@ class SocketIO(io.RawIOBase):
|
||||||
self._checkClosed()
|
self._checkClosed()
|
||||||
self._checkReadable()
|
self._checkReadable()
|
||||||
if self._timeout_occurred:
|
if self._timeout_occurred:
|
||||||
raise IOError("cannot read from timed out object")
|
raise OSError("cannot read from timed out object")
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
return self._sock.recv_into(b)
|
return self._sock.recv_into(b)
|
||||||
|
|
|
@ -897,7 +897,7 @@ class Popen(object):
|
||||||
if input:
|
if input:
|
||||||
try:
|
try:
|
||||||
self.stdin.write(input)
|
self.stdin.write(input)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.EPIPE and e.errno != errno.EINVAL:
|
if e.errno != errno.EPIPE and e.errno != errno.EINVAL:
|
||||||
raise
|
raise
|
||||||
self.stdin.close()
|
self.stdin.close()
|
||||||
|
@ -1152,7 +1152,7 @@ class Popen(object):
|
||||||
if input is not None:
|
if input is not None:
|
||||||
try:
|
try:
|
||||||
self.stdin.write(input)
|
self.stdin.write(input)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.EPIPE:
|
if e.errno != errno.EPIPE:
|
||||||
raise
|
raise
|
||||||
self.stdin.close()
|
self.stdin.close()
|
||||||
|
|
|
@ -349,21 +349,21 @@ def _generate_posix_vars():
|
||||||
makefile = get_makefile_filename()
|
makefile = get_makefile_filename()
|
||||||
try:
|
try:
|
||||||
_parse_makefile(makefile, vars)
|
_parse_makefile(makefile, vars)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
msg = "invalid Python installation: unable to open %s" % makefile
|
msg = "invalid Python installation: unable to open %s" % makefile
|
||||||
if hasattr(e, "strerror"):
|
if hasattr(e, "strerror"):
|
||||||
msg = msg + " (%s)" % e.strerror
|
msg = msg + " (%s)" % e.strerror
|
||||||
raise IOError(msg)
|
raise OSError(msg)
|
||||||
# load the installed pyconfig.h:
|
# load the installed pyconfig.h:
|
||||||
config_h = get_config_h_filename()
|
config_h = get_config_h_filename()
|
||||||
try:
|
try:
|
||||||
with open(config_h) as f:
|
with open(config_h) as f:
|
||||||
parse_config_h(f, vars)
|
parse_config_h(f, vars)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
msg = "invalid Python installation: unable to open %s" % config_h
|
msg = "invalid Python installation: unable to open %s" % config_h
|
||||||
if hasattr(e, "strerror"):
|
if hasattr(e, "strerror"):
|
||||||
msg = msg + " (%s)" % e.strerror
|
msg = msg + " (%s)" % e.strerror
|
||||||
raise IOError(msg)
|
raise OSError(msg)
|
||||||
# On AIX, there are wrong paths to the linker scripts in the Makefile
|
# On AIX, there are wrong paths to the linker scripts in the Makefile
|
||||||
# -- these paths are relative to the Python source, but when installed
|
# -- these paths are relative to the Python source, but when installed
|
||||||
# the scripts are in another directory.
|
# the scripts are in another directory.
|
||||||
|
|
|
@ -95,7 +95,7 @@ def check(file):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = tokenize.open(file)
|
f = tokenize.open(file)
|
||||||
except IOError as msg:
|
except OSError as msg:
|
||||||
errprint("%r: I/O Error: %s" % (file, msg))
|
errprint("%r: I/O Error: %s" % (file, msg))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -264,13 +264,13 @@ def copyfileobj(src, dst, length=None):
|
||||||
for b in range(blocks):
|
for b in range(blocks):
|
||||||
buf = src.read(BUFSIZE)
|
buf = src.read(BUFSIZE)
|
||||||
if len(buf) < BUFSIZE:
|
if len(buf) < BUFSIZE:
|
||||||
raise IOError("end of file reached")
|
raise OSError("end of file reached")
|
||||||
dst.write(buf)
|
dst.write(buf)
|
||||||
|
|
||||||
if remainder != 0:
|
if remainder != 0:
|
||||||
buf = src.read(remainder)
|
buf = src.read(remainder)
|
||||||
if len(buf) < remainder:
|
if len(buf) < remainder:
|
||||||
raise IOError("end of file reached")
|
raise OSError("end of file reached")
|
||||||
dst.write(buf)
|
dst.write(buf)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ class _Stream:
|
||||||
if mode == "r":
|
if mode == "r":
|
||||||
self.dbuf = b""
|
self.dbuf = b""
|
||||||
self.cmp = bz2.BZ2Decompressor()
|
self.cmp = bz2.BZ2Decompressor()
|
||||||
self.exception = IOError
|
self.exception = OSError
|
||||||
else:
|
else:
|
||||||
self.cmp = bz2.BZ2Compressor()
|
self.cmp = bz2.BZ2Compressor()
|
||||||
|
|
||||||
|
@ -1631,7 +1631,7 @@ class TarFile(object):
|
||||||
try:
|
try:
|
||||||
fileobj = gzip.GzipFile(name, mode + "b", compresslevel, fileobj)
|
fileobj = gzip.GzipFile(name, mode + "b", compresslevel, fileobj)
|
||||||
t = cls.taropen(name, mode, fileobj, **kwargs)
|
t = cls.taropen(name, mode, fileobj, **kwargs)
|
||||||
except IOError:
|
except OSError:
|
||||||
if not extfileobj and fileobj is not None:
|
if not extfileobj and fileobj is not None:
|
||||||
fileobj.close()
|
fileobj.close()
|
||||||
if fileobj is None:
|
if fileobj is None:
|
||||||
|
@ -1662,7 +1662,7 @@ class TarFile(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
t = cls.taropen(name, mode, fileobj, **kwargs)
|
t = cls.taropen(name, mode, fileobj, **kwargs)
|
||||||
except (IOError, EOFError):
|
except (OSError, EOFError):
|
||||||
fileobj.close()
|
fileobj.close()
|
||||||
raise ReadError("not a bzip2 file")
|
raise ReadError("not a bzip2 file")
|
||||||
t._extfileobj = False
|
t._extfileobj = False
|
||||||
|
@ -2322,9 +2322,9 @@ class TarFile(object):
|
||||||
corresponds to TarFile's mode.
|
corresponds to TarFile's mode.
|
||||||
"""
|
"""
|
||||||
if self.closed:
|
if self.closed:
|
||||||
raise IOError("%s is closed" % self.__class__.__name__)
|
raise OSError("%s is closed" % self.__class__.__name__)
|
||||||
if mode is not None and self.mode not in mode:
|
if mode is not None and self.mode not in mode:
|
||||||
raise IOError("bad operation for mode %r" % self.mode)
|
raise OSError("bad operation for mode %r" % self.mode)
|
||||||
|
|
||||||
def _find_link_target(self, tarinfo):
|
def _find_link_target(self, tarinfo):
|
||||||
"""Find the target member of a symlink or hardlink member in the
|
"""Find the target member of a symlink or hardlink member in the
|
||||||
|
|
|
@ -28,7 +28,7 @@ class ForkWait(unittest.TestCase):
|
||||||
self.alive[id] = os.getpid()
|
self.alive[id] = os.getpid()
|
||||||
try:
|
try:
|
||||||
time.sleep(SHORTSLEEP)
|
time.sleep(SHORTSLEEP)
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def wait_impl(self, cpid):
|
def wait_impl(self, cpid):
|
||||||
|
|
|
@ -282,7 +282,7 @@ class TestBase_Mapping(unittest.TestCase):
|
||||||
unittest.TestCase.__init__(self, *args, **kw)
|
unittest.TestCase.__init__(self, *args, **kw)
|
||||||
try:
|
try:
|
||||||
self.open_mapping_file().close() # test it to report the error early
|
self.open_mapping_file().close() # test it to report the error early
|
||||||
except (IOError, HTTPException):
|
except (OSError, HTTPException):
|
||||||
self.skipTest("Could not retrieve "+self.mapfileurl)
|
self.skipTest("Could not retrieve "+self.mapfileurl)
|
||||||
|
|
||||||
def open_mapping_file(self):
|
def open_mapping_file(self):
|
||||||
|
|
|
@ -506,7 +506,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
|
||||||
next_test = fp.read().strip()
|
next_test = fp.read().strip()
|
||||||
tests = [next_test]
|
tests = [next_test]
|
||||||
fp.close()
|
fp.close()
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if fromfile:
|
if fromfile:
|
||||||
|
|
|
@ -22,7 +22,7 @@ def randfloats(n):
|
||||||
fn = os.path.join(td, "rr%06d" % n)
|
fn = os.path.join(td, "rr%06d" % n)
|
||||||
try:
|
try:
|
||||||
fp = open(fn, "rb")
|
fp = open(fn, "rb")
|
||||||
except IOError:
|
except OSError:
|
||||||
r = random.random
|
r = random.random
|
||||||
result = [r() for i in range(n)]
|
result = [r() for i in range(n)]
|
||||||
try:
|
try:
|
||||||
|
@ -37,7 +37,7 @@ def randfloats(n):
|
||||||
os.unlink(fn)
|
os.unlink(fn)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
except IOError as msg:
|
except OSError as msg:
|
||||||
print("can't write", fn, ":", msg)
|
print("can't write", fn, ":", msg)
|
||||||
else:
|
else:
|
||||||
result = marshal.load(fp)
|
result = marshal.load(fp)
|
||||||
|
|
|
@ -1097,9 +1097,9 @@ class TransientResource(object):
|
||||||
# Context managers that raise ResourceDenied when various issues
|
# Context managers that raise ResourceDenied when various issues
|
||||||
# with the Internet connection manifest themselves as exceptions.
|
# with the Internet connection manifest themselves as exceptions.
|
||||||
# XXX deprecate these and use transient_internet() instead
|
# XXX deprecate these and use transient_internet() instead
|
||||||
time_out = TransientResource(IOError, errno=errno.ETIMEDOUT)
|
time_out = TransientResource(OSError, errno=errno.ETIMEDOUT)
|
||||||
socket_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET)
|
socket_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET)
|
||||||
ioerror_peer_reset = TransientResource(IOError, errno=errno.ECONNRESET)
|
ioerror_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET)
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
|
@ -1145,17 +1145,17 @@ def transient_internet(resource_name, *, timeout=30.0, errnos=()):
|
||||||
if timeout is not None:
|
if timeout is not None:
|
||||||
socket.setdefaulttimeout(timeout)
|
socket.setdefaulttimeout(timeout)
|
||||||
yield
|
yield
|
||||||
except IOError as err:
|
except OSError as err:
|
||||||
# urllib can wrap original socket errors multiple times (!), we must
|
# urllib can wrap original socket errors multiple times (!), we must
|
||||||
# unwrap to get at the original error.
|
# unwrap to get at the original error.
|
||||||
while True:
|
while True:
|
||||||
a = err.args
|
a = err.args
|
||||||
if len(a) >= 1 and isinstance(a[0], IOError):
|
if len(a) >= 1 and isinstance(a[0], OSError):
|
||||||
err = a[0]
|
err = a[0]
|
||||||
# The error can also be wrapped as args[1]:
|
# The error can also be wrapped as args[1]:
|
||||||
# except socket.error as msg:
|
# except socket.error as msg:
|
||||||
# raise IOError('socket error', msg).with_traceback(sys.exc_info()[2])
|
# raise OSError('socket error', msg).with_traceback(sys.exc_info()[2])
|
||||||
elif len(a) >= 2 and isinstance(a[1], IOError):
|
elif len(a) >= 2 and isinstance(a[1], OSError):
|
||||||
err = a[1]
|
err = a[1]
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
|
@ -355,12 +355,12 @@ class BaseTest(unittest.TestCase):
|
||||||
support.unlink(support.TESTFN)
|
support.unlink(support.TESTFN)
|
||||||
|
|
||||||
def test_fromfile_ioerror(self):
|
def test_fromfile_ioerror(self):
|
||||||
# Issue #5395: Check if fromfile raises a proper IOError
|
# Issue #5395: Check if fromfile raises a proper OSError
|
||||||
# instead of EOFError.
|
# instead of EOFError.
|
||||||
a = array.array(self.typecode)
|
a = array.array(self.typecode)
|
||||||
f = open(support.TESTFN, 'wb')
|
f = open(support.TESTFN, 'wb')
|
||||||
try:
|
try:
|
||||||
self.assertRaises(IOError, a.fromfile, f, len(self.example))
|
self.assertRaises(OSError, a.fromfile, f, len(self.example))
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
support.unlink(support.TESTFN)
|
support.unlink(support.TESTFN)
|
||||||
|
|
|
@ -253,8 +253,8 @@ class BZ2FileTest(BaseTest):
|
||||||
bz2f.write(b"abc")
|
bz2f.write(b"abc")
|
||||||
|
|
||||||
with BZ2File(self.filename, "r") as bz2f:
|
with BZ2File(self.filename, "r") as bz2f:
|
||||||
self.assertRaises(IOError, bz2f.write, b"a")
|
self.assertRaises(OSError, bz2f.write, b"a")
|
||||||
self.assertRaises(IOError, bz2f.writelines, [b"a"])
|
self.assertRaises(OSError, bz2f.writelines, [b"a"])
|
||||||
|
|
||||||
def testAppend(self):
|
def testAppend(self):
|
||||||
with BZ2File(self.filename, "w") as bz2f:
|
with BZ2File(self.filename, "w") as bz2f:
|
||||||
|
@ -429,7 +429,7 @@ class BZ2FileTest(BaseTest):
|
||||||
del o
|
del o
|
||||||
|
|
||||||
def testOpenNonexistent(self):
|
def testOpenNonexistent(self):
|
||||||
self.assertRaises(IOError, BZ2File, "/non/existent")
|
self.assertRaises(OSError, BZ2File, "/non/existent")
|
||||||
|
|
||||||
def testReadlinesNoNewline(self):
|
def testReadlinesNoNewline(self):
|
||||||
# Issue #1191043: readlines() fails on a file containing no newline.
|
# Issue #1191043: readlines() fails on a file containing no newline.
|
||||||
|
|
|
@ -136,12 +136,12 @@ class Test_Csv(unittest.TestCase):
|
||||||
return 10;
|
return 10;
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, i):
|
||||||
if i > 2:
|
if i > 2:
|
||||||
raise IOError
|
raise OSError
|
||||||
self.assertRaises(IOError, self._write_test, BadList(), '')
|
self.assertRaises(OSError, self._write_test, BadList(), '')
|
||||||
class BadItem:
|
class BadItem:
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
raise IOError
|
raise OSError
|
||||||
self.assertRaises(IOError, self._write_test, [BadItem()], '')
|
self.assertRaises(OSError, self._write_test, [BadItem()], '')
|
||||||
|
|
||||||
def test_write_bigfield(self):
|
def test_write_bigfield(self):
|
||||||
# This exercises the buffer realloc functionality
|
# This exercises the buffer realloc functionality
|
||||||
|
@ -186,9 +186,9 @@ class Test_Csv(unittest.TestCase):
|
||||||
def test_writerows(self):
|
def test_writerows(self):
|
||||||
class BrokenFile:
|
class BrokenFile:
|
||||||
def write(self, buf):
|
def write(self, buf):
|
||||||
raise IOError
|
raise OSError
|
||||||
writer = csv.writer(BrokenFile())
|
writer = csv.writer(BrokenFile())
|
||||||
self.assertRaises(IOError, writer.writerows, [['a']])
|
self.assertRaises(OSError, writer.writerows, [['a']])
|
||||||
|
|
||||||
with TemporaryFile("w+", newline='') as fileobj:
|
with TemporaryFile("w+", newline='') as fileobj:
|
||||||
writer = csv.writer(fileobj)
|
writer = csv.writer(fileobj)
|
||||||
|
|
|
@ -57,7 +57,7 @@ class AnyDBMTestCase(unittest.TestCase):
|
||||||
return keys
|
return keys
|
||||||
|
|
||||||
def test_error(self):
|
def test_error(self):
|
||||||
self.assertTrue(issubclass(self.module.error, IOError))
|
self.assertTrue(issubclass(self.module.error, OSError))
|
||||||
|
|
||||||
def test_anydbm_not_existing(self):
|
def test_anydbm_not_existing(self):
|
||||||
self.assertRaises(dbm.error, dbm.open, _fname)
|
self.assertRaises(dbm.error, dbm.open, _fname)
|
||||||
|
|
|
@ -27,7 +27,7 @@ def openfile(filename):
|
||||||
# Prevent this test from running in the Python distro
|
# Prevent this test from running in the Python distro
|
||||||
try:
|
try:
|
||||||
openfile('crispin-torture.txt')
|
openfile('crispin-torture.txt')
|
||||||
except IOError:
|
except OSError:
|
||||||
raise TestSkipped
|
raise TestSkipped
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ if not hasattr(select, "epoll"):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
select.epoll()
|
select.epoll()
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOSYS:
|
if e.errno == errno.ENOSYS:
|
||||||
raise unittest.SkipTest("kernel doesn't support epoll()")
|
raise unittest.SkipTest("kernel doesn't support epoll()")
|
||||||
raise
|
raise
|
||||||
|
@ -122,12 +122,12 @@ class TestEPoll(unittest.TestCase):
|
||||||
# ValueError: file descriptor cannot be a negative integer (-1)
|
# ValueError: file descriptor cannot be a negative integer (-1)
|
||||||
self.assertRaises(ValueError, ep.register, -1,
|
self.assertRaises(ValueError, ep.register, -1,
|
||||||
select.EPOLLIN | select.EPOLLOUT)
|
select.EPOLLIN | select.EPOLLOUT)
|
||||||
# IOError: [Errno 9] Bad file descriptor
|
# OSError: [Errno 9] Bad file descriptor
|
||||||
self.assertRaises(IOError, ep.register, 10000,
|
self.assertRaises(OSError, ep.register, 10000,
|
||||||
select.EPOLLIN | select.EPOLLOUT)
|
select.EPOLLIN | select.EPOLLOUT)
|
||||||
# registering twice also raises an exception
|
# registering twice also raises an exception
|
||||||
ep.register(server, select.EPOLLIN | select.EPOLLOUT)
|
ep.register(server, select.EPOLLIN | select.EPOLLOUT)
|
||||||
self.assertRaises(IOError, ep.register, server,
|
self.assertRaises(OSError, ep.register, server,
|
||||||
select.EPOLLIN | select.EPOLLOUT)
|
select.EPOLLIN | select.EPOLLOUT)
|
||||||
finally:
|
finally:
|
||||||
ep.close()
|
ep.close()
|
||||||
|
@ -149,7 +149,7 @@ class TestEPoll(unittest.TestCase):
|
||||||
ep.close()
|
ep.close()
|
||||||
try:
|
try:
|
||||||
ep2.poll(1, 4)
|
ep2.poll(1, 4)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
self.assertEqual(e.args[0], errno.EBADF, e)
|
self.assertEqual(e.args[0], errno.EBADF, e)
|
||||||
else:
|
else:
|
||||||
self.fail("epoll on closed fd didn't raise EBADF")
|
self.fail("epoll on closed fd didn't raise EBADF")
|
||||||
|
|
|
@ -244,16 +244,16 @@ class ExceptionTests(unittest.TestCase):
|
||||||
{'args' : ('foo', 1)}),
|
{'args' : ('foo', 1)}),
|
||||||
(SystemExit, ('foo',),
|
(SystemExit, ('foo',),
|
||||||
{'args' : ('foo',), 'code' : 'foo'}),
|
{'args' : ('foo',), 'code' : 'foo'}),
|
||||||
(IOError, ('foo',),
|
(OSError, ('foo',),
|
||||||
{'args' : ('foo',), 'filename' : None,
|
{'args' : ('foo',), 'filename' : None,
|
||||||
'errno' : None, 'strerror' : None}),
|
'errno' : None, 'strerror' : None}),
|
||||||
(IOError, ('foo', 'bar'),
|
(OSError, ('foo', 'bar'),
|
||||||
{'args' : ('foo', 'bar'), 'filename' : None,
|
{'args' : ('foo', 'bar'), 'filename' : None,
|
||||||
'errno' : 'foo', 'strerror' : 'bar'}),
|
'errno' : 'foo', 'strerror' : 'bar'}),
|
||||||
(IOError, ('foo', 'bar', 'baz'),
|
(OSError, ('foo', 'bar', 'baz'),
|
||||||
{'args' : ('foo', 'bar'), 'filename' : 'baz',
|
{'args' : ('foo', 'bar'), 'filename' : 'baz',
|
||||||
'errno' : 'foo', 'strerror' : 'bar'}),
|
'errno' : 'foo', 'strerror' : 'bar'}),
|
||||||
(IOError, ('foo', 'bar', 'baz', 'quux'),
|
(OSError, ('foo', 'bar', 'baz', 'quux'),
|
||||||
{'args' : ('foo', 'bar', 'baz', 'quux')}),
|
{'args' : ('foo', 'bar', 'baz', 'quux')}),
|
||||||
(OSError, ('errnoStr', 'strErrorStr', 'filenameStr'),
|
(OSError, ('errnoStr', 'strErrorStr', 'filenameStr'),
|
||||||
{'args' : ('errnoStr', 'strErrorStr'),
|
{'args' : ('errnoStr', 'strErrorStr'),
|
||||||
|
|
|
@ -87,7 +87,7 @@ class AutoFileTests(unittest.TestCase):
|
||||||
self.assertTrue(not f.closed)
|
self.assertTrue(not f.closed)
|
||||||
|
|
||||||
if hasattr(f, "readinto"):
|
if hasattr(f, "readinto"):
|
||||||
self.assertRaises((IOError, TypeError), f.readinto, "")
|
self.assertRaises((OSError, TypeError), f.readinto, "")
|
||||||
f.close()
|
f.close()
|
||||||
self.assertTrue(f.closed)
|
self.assertTrue(f.closed)
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ class AutoFileTests(unittest.TestCase):
|
||||||
self.assertEqual(self.f.__exit__(*sys.exc_info()), None)
|
self.assertEqual(self.f.__exit__(*sys.exc_info()), None)
|
||||||
|
|
||||||
def testReadWhenWriting(self):
|
def testReadWhenWriting(self):
|
||||||
self.assertRaises(IOError, self.f.read)
|
self.assertRaises(OSError, self.f.read)
|
||||||
|
|
||||||
class CAutoFileTests(AutoFileTests):
|
class CAutoFileTests(AutoFileTests):
|
||||||
open = io.open
|
open = io.open
|
||||||
|
@ -151,12 +151,12 @@ class OtherFileTests(unittest.TestCase):
|
||||||
def testStdin(self):
|
def testStdin(self):
|
||||||
# This causes the interpreter to exit on OSF1 v5.1.
|
# This causes the interpreter to exit on OSF1 v5.1.
|
||||||
if sys.platform != 'osf1V5':
|
if sys.platform != 'osf1V5':
|
||||||
self.assertRaises((IOError, ValueError), sys.stdin.seek, -1)
|
self.assertRaises((OSError, ValueError), sys.stdin.seek, -1)
|
||||||
else:
|
else:
|
||||||
print((
|
print((
|
||||||
' Skipping sys.stdin.seek(-1), it may crash the interpreter.'
|
' Skipping sys.stdin.seek(-1), it may crash the interpreter.'
|
||||||
' Test manually.'), file=sys.__stdout__)
|
' Test manually.'), file=sys.__stdout__)
|
||||||
self.assertRaises((IOError, ValueError), sys.stdin.truncate)
|
self.assertRaises((OSError, ValueError), sys.stdin.truncate)
|
||||||
|
|
||||||
def testBadModeArgument(self):
|
def testBadModeArgument(self):
|
||||||
# verify that we get a sensible error message for bad mode argument
|
# verify that we get a sensible error message for bad mode argument
|
||||||
|
@ -187,7 +187,7 @@ class OtherFileTests(unittest.TestCase):
|
||||||
d = int(f.read().decode("ascii"))
|
d = int(f.read().decode("ascii"))
|
||||||
f.close()
|
f.close()
|
||||||
f.close()
|
f.close()
|
||||||
except IOError as msg:
|
except OSError as msg:
|
||||||
self.fail('error setting buffer size %d: %s' % (s, str(msg)))
|
self.fail('error setting buffer size %d: %s' % (s, str(msg)))
|
||||||
self.assertEqual(d, s)
|
self.assertEqual(d, s)
|
||||||
|
|
||||||
|
|
|
@ -275,8 +275,8 @@ class FileInputTests(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
t1 = writeTmp(1, [""])
|
t1 = writeTmp(1, [""])
|
||||||
with FileInput(files=t1) as fi:
|
with FileInput(files=t1) as fi:
|
||||||
raise IOError
|
raise OSError
|
||||||
except IOError:
|
except OSError:
|
||||||
self.assertEqual(fi._files, ())
|
self.assertEqual(fi._files, ())
|
||||||
finally:
|
finally:
|
||||||
remove_tempfiles(t1)
|
remove_tempfiles(t1)
|
||||||
|
|
|
@ -144,16 +144,16 @@ class AutoFileTests(unittest.TestCase):
|
||||||
# Unix calls dircheck() and returns "[Errno 21]: Is a directory"
|
# Unix calls dircheck() and returns "[Errno 21]: Is a directory"
|
||||||
try:
|
try:
|
||||||
_FileIO('.', 'r')
|
_FileIO('.', 'r')
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
self.assertNotEqual(e.errno, 0)
|
self.assertNotEqual(e.errno, 0)
|
||||||
self.assertEqual(e.filename, ".")
|
self.assertEqual(e.filename, ".")
|
||||||
else:
|
else:
|
||||||
self.fail("Should have raised IOError")
|
self.fail("Should have raised OSError")
|
||||||
|
|
||||||
@unittest.skipIf(os.name == 'nt', "test only works on a POSIX-like system")
|
@unittest.skipIf(os.name == 'nt', "test only works on a POSIX-like system")
|
||||||
def testOpenDirFD(self):
|
def testOpenDirFD(self):
|
||||||
fd = os.open('.', os.O_RDONLY)
|
fd = os.open('.', os.O_RDONLY)
|
||||||
with self.assertRaises(IOError) as cm:
|
with self.assertRaises(OSError) as cm:
|
||||||
_FileIO(fd, 'r')
|
_FileIO(fd, 'r')
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
self.assertEqual(cm.exception.errno, errno.EISDIR)
|
self.assertEqual(cm.exception.errno, errno.EISDIR)
|
||||||
|
@ -171,7 +171,7 @@ class AutoFileTests(unittest.TestCase):
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
self.f.close()
|
self.f.close()
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
@ -183,14 +183,14 @@ class AutoFileTests(unittest.TestCase):
|
||||||
os.close(f.fileno())
|
os.close(f.fileno())
|
||||||
try:
|
try:
|
||||||
func(self, f)
|
func(self, f)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
self.assertEqual(e.errno, errno.EBADF)
|
self.assertEqual(e.errno, errno.EBADF)
|
||||||
else:
|
else:
|
||||||
self.fail("Should have raised IOError")
|
self.fail("Should have raised OSError")
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
self.f.close()
|
self.f.close()
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ class AutoFileTests(unittest.TestCase):
|
||||||
def ReopenForRead(self):
|
def ReopenForRead(self):
|
||||||
try:
|
try:
|
||||||
self.f.close()
|
self.f.close()
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
self.f = _FileIO(TESTFN, 'r')
|
self.f = _FileIO(TESTFN, 'r')
|
||||||
os.close(self.f.fileno())
|
os.close(self.f.fileno())
|
||||||
|
@ -346,7 +346,7 @@ class OtherFileTests(unittest.TestCase):
|
||||||
self.assertRaises(OSError, _FileIO, make_bad_fd())
|
self.assertRaises(OSError, _FileIO, make_bad_fd())
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
import msvcrt
|
import msvcrt
|
||||||
self.assertRaises(IOError, msvcrt.get_osfhandle, make_bad_fd())
|
self.assertRaises(OSError, msvcrt.get_osfhandle, make_bad_fd())
|
||||||
|
|
||||||
def testBadModeArgument(self):
|
def testBadModeArgument(self):
|
||||||
# verify that we get a sensible error message for bad mode argument
|
# verify that we get a sensible error message for bad mode argument
|
||||||
|
|
|
@ -482,7 +482,7 @@ class TestFTPClass(TestCase):
|
||||||
|
|
||||||
def test_all_errors(self):
|
def test_all_errors(self):
|
||||||
exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
|
exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
|
||||||
ftplib.error_proto, ftplib.Error, IOError, EOFError)
|
ftplib.error_proto, ftplib.Error, OSError, EOFError)
|
||||||
for x in exceptions:
|
for x in exceptions:
|
||||||
try:
|
try:
|
||||||
raise x('exception not included in all_errors set')
|
raise x('exception not included in all_errors set')
|
||||||
|
@ -721,7 +721,7 @@ class TestFTPClass(TestCase):
|
||||||
source_address=(HOST, port))
|
source_address=(HOST, port))
|
||||||
self.assertEqual(self.client.sock.getsockname()[1], port)
|
self.assertEqual(self.client.sock.getsockname()[1], port)
|
||||||
self.client.quit()
|
self.client.quit()
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.EADDRINUSE:
|
if e.errno == errno.EADDRINUSE:
|
||||||
self.skipTest("couldn't bind to port %d" % port)
|
self.skipTest("couldn't bind to port %d" % port)
|
||||||
raise
|
raise
|
||||||
|
@ -732,7 +732,7 @@ class TestFTPClass(TestCase):
|
||||||
try:
|
try:
|
||||||
with self.client.transfercmd('list') as sock:
|
with self.client.transfercmd('list') as sock:
|
||||||
self.assertEqual(sock.getsockname()[1], port)
|
self.assertEqual(sock.getsockname()[1], port)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.EADDRINUSE:
|
if e.errno == errno.EADDRINUSE:
|
||||||
self.skipTest("couldn't bind to port %d" % port)
|
self.skipTest("couldn't bind to port %d" % port)
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -114,7 +114,7 @@ class SimpleIMAPHandler(socketserver.StreamRequestHandler):
|
||||||
# Naked sockets return empty strings..
|
# Naked sockets return empty strings..
|
||||||
return
|
return
|
||||||
line += part
|
line += part
|
||||||
except IOError:
|
except OSError:
|
||||||
# ..but SSLSockets raise exceptions.
|
# ..but SSLSockets raise exceptions.
|
||||||
return
|
return
|
||||||
if line.endswith(b'\r\n'):
|
if line.endswith(b'\r\n'):
|
||||||
|
|
|
@ -59,7 +59,7 @@ class SourceLoaderMock(SourceOnlyLoaderMock):
|
||||||
elif path == self.bytecode_path:
|
elif path == self.bytecode_path:
|
||||||
return self.bytecode
|
return self.bytecode
|
||||||
else:
|
else:
|
||||||
raise IOError
|
raise OSError
|
||||||
|
|
||||||
def path_stats(self, path):
|
def path_stats(self, path):
|
||||||
assert path == self.path
|
assert path == self.path
|
||||||
|
@ -125,12 +125,12 @@ class SourceOnlyLoaderTests(SourceLoaderTestHarness):
|
||||||
|
|
||||||
def test_get_source(self):
|
def test_get_source(self):
|
||||||
# Verify the source code is returned as a string.
|
# Verify the source code is returned as a string.
|
||||||
# If an IOError is raised by get_data then raise ImportError.
|
# If an OSError is raised by get_data then raise ImportError.
|
||||||
expected_source = self.loader.source.decode('utf-8')
|
expected_source = self.loader.source.decode('utf-8')
|
||||||
self.assertEqual(self.loader.get_source(self.name), expected_source)
|
self.assertEqual(self.loader.get_source(self.name), expected_source)
|
||||||
def raise_IOError(path):
|
def raise_OSError(path):
|
||||||
raise IOError
|
raise OSError
|
||||||
self.loader.get_data = raise_IOError
|
self.loader.get_data = raise_OSError
|
||||||
with self.assertRaises(ImportError) as cm:
|
with self.assertRaises(ImportError) as cm:
|
||||||
self.loader.get_source(self.name)
|
self.loader.get_source(self.name)
|
||||||
self.assertEqual(cm.exception.name, self.name)
|
self.assertEqual(cm.exception.name, self.name)
|
||||||
|
@ -216,7 +216,7 @@ class SourceLoaderBytecodeTests(SourceLoaderTestHarness):
|
||||||
# If no bytecode exists then move on to the source.
|
# If no bytecode exists then move on to the source.
|
||||||
self.loader.bytecode_path = "<does not exist>"
|
self.loader.bytecode_path = "<does not exist>"
|
||||||
# Sanity check
|
# Sanity check
|
||||||
with self.assertRaises(IOError):
|
with self.assertRaises(OSError):
|
||||||
bytecode_path = imp.cache_from_source(self.path)
|
bytecode_path = imp.cache_from_source(self.path)
|
||||||
self.loader.get_data(bytecode_path)
|
self.loader.get_data(bytecode_path)
|
||||||
code_object = self.loader.get_code(self.name)
|
code_object = self.loader.get_code(self.name)
|
||||||
|
@ -265,7 +265,7 @@ class SourceLoaderBytecodeTests(SourceLoaderTestHarness):
|
||||||
self.loader.__class__.set_data = original_set_data
|
self.loader.__class__.set_data = original_set_data
|
||||||
|
|
||||||
def test_set_data_raises_exceptions(self):
|
def test_set_data_raises_exceptions(self):
|
||||||
# Raising NotImplementedError or IOError is okay for set_data.
|
# Raising NotImplementedError or OSError is okay for set_data.
|
||||||
def raise_exception(exc):
|
def raise_exception(exc):
|
||||||
def closure(*args, **kwargs):
|
def closure(*args, **kwargs):
|
||||||
raise exc
|
raise exc
|
||||||
|
|
|
@ -407,7 +407,7 @@ class SourceLoaderBadBytecodeTest(BadBytecodeTest):
|
||||||
os.chmod(bytecode_path,
|
os.chmod(bytecode_path,
|
||||||
stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
|
stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
|
||||||
try:
|
try:
|
||||||
# Should not raise IOError!
|
# Should not raise OSError!
|
||||||
self.import_(mapping['_temp'], '_temp')
|
self.import_(mapping['_temp'], '_temp')
|
||||||
finally:
|
finally:
|
||||||
# Make writable for eventual clean-up.
|
# Make writable for eventual clean-up.
|
||||||
|
|
|
@ -401,14 +401,14 @@ class TestBuggyCases(GetSourceBase):
|
||||||
unicodedata.__file__[-4:] in (".pyc", ".pyo"),
|
unicodedata.__file__[-4:] in (".pyc", ".pyo"),
|
||||||
"unicodedata is not an external binary module")
|
"unicodedata is not an external binary module")
|
||||||
def test_findsource_binary(self):
|
def test_findsource_binary(self):
|
||||||
self.assertRaises(IOError, inspect.getsource, unicodedata)
|
self.assertRaises(OSError, inspect.getsource, unicodedata)
|
||||||
self.assertRaises(IOError, inspect.findsource, unicodedata)
|
self.assertRaises(OSError, inspect.findsource, unicodedata)
|
||||||
|
|
||||||
def test_findsource_code_in_linecache(self):
|
def test_findsource_code_in_linecache(self):
|
||||||
lines = ["x=1"]
|
lines = ["x=1"]
|
||||||
co = compile(lines[0], "_dynamically_created_file", "exec")
|
co = compile(lines[0], "_dynamically_created_file", "exec")
|
||||||
self.assertRaises(IOError, inspect.findsource, co)
|
self.assertRaises(OSError, inspect.findsource, co)
|
||||||
self.assertRaises(IOError, inspect.getsource, co)
|
self.assertRaises(OSError, inspect.getsource, co)
|
||||||
linecache.cache[co.co_filename] = (1, None, lines, co.co_filename)
|
linecache.cache[co.co_filename] = (1, None, lines, co.co_filename)
|
||||||
try:
|
try:
|
||||||
self.assertEqual(inspect.findsource(co), (lines,0))
|
self.assertEqual(inspect.findsource(co), (lines,0))
|
||||||
|
|
|
@ -164,7 +164,7 @@ class CloseFailureIO(MockRawIO):
|
||||||
def close(self):
|
def close(self):
|
||||||
if not self.closed:
|
if not self.closed:
|
||||||
self.closed = 1
|
self.closed = 1
|
||||||
raise IOError
|
raise OSError
|
||||||
|
|
||||||
class CCloseFailureIO(CloseFailureIO, io.RawIOBase):
|
class CCloseFailureIO(CloseFailureIO, io.RawIOBase):
|
||||||
pass
|
pass
|
||||||
|
@ -600,9 +600,9 @@ class IOTest(unittest.TestCase):
|
||||||
def test_flush_error_on_close(self):
|
def test_flush_error_on_close(self):
|
||||||
f = self.open(support.TESTFN, "wb", buffering=0)
|
f = self.open(support.TESTFN, "wb", buffering=0)
|
||||||
def bad_flush():
|
def bad_flush():
|
||||||
raise IOError()
|
raise OSError()
|
||||||
f.flush = bad_flush
|
f.flush = bad_flush
|
||||||
self.assertRaises(IOError, f.close) # exception not swallowed
|
self.assertRaises(OSError, f.close) # exception not swallowed
|
||||||
self.assertTrue(f.closed)
|
self.assertTrue(f.closed)
|
||||||
|
|
||||||
def test_multi_close(self):
|
def test_multi_close(self):
|
||||||
|
@ -761,7 +761,7 @@ class CommonBufferedTests:
|
||||||
if s:
|
if s:
|
||||||
# The destructor *may* have printed an unraisable error, check it
|
# The destructor *may* have printed an unraisable error, check it
|
||||||
self.assertEqual(len(s.splitlines()), 1)
|
self.assertEqual(len(s.splitlines()), 1)
|
||||||
self.assertTrue(s.startswith("Exception IOError: "), s)
|
self.assertTrue(s.startswith("Exception OSError: "), s)
|
||||||
self.assertTrue(s.endswith(" ignored"), s)
|
self.assertTrue(s.endswith(" ignored"), s)
|
||||||
|
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
|
@ -777,22 +777,22 @@ class CommonBufferedTests:
|
||||||
def test_flush_error_on_close(self):
|
def test_flush_error_on_close(self):
|
||||||
raw = self.MockRawIO()
|
raw = self.MockRawIO()
|
||||||
def bad_flush():
|
def bad_flush():
|
||||||
raise IOError()
|
raise OSError()
|
||||||
raw.flush = bad_flush
|
raw.flush = bad_flush
|
||||||
b = self.tp(raw)
|
b = self.tp(raw)
|
||||||
self.assertRaises(IOError, b.close) # exception not swallowed
|
self.assertRaises(OSError, b.close) # exception not swallowed
|
||||||
self.assertTrue(b.closed)
|
self.assertTrue(b.closed)
|
||||||
|
|
||||||
def test_close_error_on_close(self):
|
def test_close_error_on_close(self):
|
||||||
raw = self.MockRawIO()
|
raw = self.MockRawIO()
|
||||||
def bad_flush():
|
def bad_flush():
|
||||||
raise IOError('flush')
|
raise OSError('flush')
|
||||||
def bad_close():
|
def bad_close():
|
||||||
raise IOError('close')
|
raise OSError('close')
|
||||||
raw.close = bad_close
|
raw.close = bad_close
|
||||||
b = self.tp(raw)
|
b = self.tp(raw)
|
||||||
b.flush = bad_flush
|
b.flush = bad_flush
|
||||||
with self.assertRaises(IOError) as err: # exception not swallowed
|
with self.assertRaises(OSError) as err: # exception not swallowed
|
||||||
b.close()
|
b.close()
|
||||||
self.assertEqual(err.exception.args, ('close',))
|
self.assertEqual(err.exception.args, ('close',))
|
||||||
self.assertEqual(err.exception.__context__.args, ('flush',))
|
self.assertEqual(err.exception.__context__.args, ('flush',))
|
||||||
|
@ -1014,8 +1014,8 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
|
||||||
def test_misbehaved_io(self):
|
def test_misbehaved_io(self):
|
||||||
rawio = self.MisbehavedRawIO((b"abc", b"d", b"efg"))
|
rawio = self.MisbehavedRawIO((b"abc", b"d", b"efg"))
|
||||||
bufio = self.tp(rawio)
|
bufio = self.tp(rawio)
|
||||||
self.assertRaises(IOError, bufio.seek, 0)
|
self.assertRaises(OSError, bufio.seek, 0)
|
||||||
self.assertRaises(IOError, bufio.tell)
|
self.assertRaises(OSError, bufio.tell)
|
||||||
|
|
||||||
def test_no_extraneous_read(self):
|
def test_no_extraneous_read(self):
|
||||||
# Issue #9550; when the raw IO object has satisfied the read request,
|
# Issue #9550; when the raw IO object has satisfied the read request,
|
||||||
|
@ -1066,7 +1066,7 @@ class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
|
||||||
bufio = self.tp(rawio)
|
bufio = self.tp(rawio)
|
||||||
# _pyio.BufferedReader seems to implement reading different, so that
|
# _pyio.BufferedReader seems to implement reading different, so that
|
||||||
# checking this is not so easy.
|
# checking this is not so easy.
|
||||||
self.assertRaises(IOError, bufio.read, 10)
|
self.assertRaises(OSError, bufio.read, 10)
|
||||||
|
|
||||||
def test_garbage_collection(self):
|
def test_garbage_collection(self):
|
||||||
# C BufferedReader objects are collected.
|
# C BufferedReader objects are collected.
|
||||||
|
@ -1313,9 +1313,9 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests):
|
||||||
def test_misbehaved_io(self):
|
def test_misbehaved_io(self):
|
||||||
rawio = self.MisbehavedRawIO()
|
rawio = self.MisbehavedRawIO()
|
||||||
bufio = self.tp(rawio, 5)
|
bufio = self.tp(rawio, 5)
|
||||||
self.assertRaises(IOError, bufio.seek, 0)
|
self.assertRaises(OSError, bufio.seek, 0)
|
||||||
self.assertRaises(IOError, bufio.tell)
|
self.assertRaises(OSError, bufio.tell)
|
||||||
self.assertRaises(IOError, bufio.write, b"abcdef")
|
self.assertRaises(OSError, bufio.write, b"abcdef")
|
||||||
|
|
||||||
def test_max_buffer_size_removal(self):
|
def test_max_buffer_size_removal(self):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
|
@ -1324,11 +1324,11 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests):
|
||||||
def test_write_error_on_close(self):
|
def test_write_error_on_close(self):
|
||||||
raw = self.MockRawIO()
|
raw = self.MockRawIO()
|
||||||
def bad_write(b):
|
def bad_write(b):
|
||||||
raise IOError()
|
raise OSError()
|
||||||
raw.write = bad_write
|
raw.write = bad_write
|
||||||
b = self.tp(raw)
|
b = self.tp(raw)
|
||||||
b.write(b'spam')
|
b.write(b'spam')
|
||||||
self.assertRaises(IOError, b.close) # exception not swallowed
|
self.assertRaises(OSError, b.close) # exception not swallowed
|
||||||
self.assertTrue(b.closed)
|
self.assertTrue(b.closed)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1393,14 +1393,14 @@ class BufferedRWPairTest(unittest.TestCase):
|
||||||
def readable(self):
|
def readable(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.assertRaises(IOError, self.tp, NotReadable(), self.MockRawIO())
|
self.assertRaises(OSError, self.tp, NotReadable(), self.MockRawIO())
|
||||||
|
|
||||||
def test_constructor_with_not_writeable(self):
|
def test_constructor_with_not_writeable(self):
|
||||||
class NotWriteable(MockRawIO):
|
class NotWriteable(MockRawIO):
|
||||||
def writable(self):
|
def writable(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.assertRaises(IOError, self.tp, self.MockRawIO(), NotWriteable())
|
self.assertRaises(OSError, self.tp, self.MockRawIO(), NotWriteable())
|
||||||
|
|
||||||
def test_read(self):
|
def test_read(self):
|
||||||
pair = self.tp(self.BytesIO(b"abcdef"), self.MockRawIO())
|
pair = self.tp(self.BytesIO(b"abcdef"), self.MockRawIO())
|
||||||
|
@ -2146,7 +2146,7 @@ class TextIOWrapperTest(unittest.TestCase):
|
||||||
if s:
|
if s:
|
||||||
# The destructor *may* have printed an unraisable error, check it
|
# The destructor *may* have printed an unraisable error, check it
|
||||||
self.assertEqual(len(s.splitlines()), 1)
|
self.assertEqual(len(s.splitlines()), 1)
|
||||||
self.assertTrue(s.startswith("Exception IOError: "), s)
|
self.assertTrue(s.startswith("Exception OSError: "), s)
|
||||||
self.assertTrue(s.endswith(" ignored"), s)
|
self.assertTrue(s.endswith(" ignored"), s)
|
||||||
|
|
||||||
# Systematic tests of the text I/O API
|
# Systematic tests of the text I/O API
|
||||||
|
@ -2218,7 +2218,7 @@ class TextIOWrapperTest(unittest.TestCase):
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
for line in f:
|
for line in f:
|
||||||
self.assertEqual(line, "\xff\n")
|
self.assertEqual(line, "\xff\n")
|
||||||
self.assertRaises(IOError, f.tell)
|
self.assertRaises(OSError, f.tell)
|
||||||
self.assertEqual(f.tell(), p2)
|
self.assertEqual(f.tell(), p2)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
@ -2322,7 +2322,7 @@ class TextIOWrapperTest(unittest.TestCase):
|
||||||
def readable(self):
|
def readable(self):
|
||||||
return False
|
return False
|
||||||
txt = self.TextIOWrapper(UnReadable())
|
txt = self.TextIOWrapper(UnReadable())
|
||||||
self.assertRaises(IOError, txt.read)
|
self.assertRaises(OSError, txt.read)
|
||||||
|
|
||||||
def test_read_one_by_one(self):
|
def test_read_one_by_one(self):
|
||||||
txt = self.TextIOWrapper(self.BytesIO(b"AA\r\nBB"))
|
txt = self.TextIOWrapper(self.BytesIO(b"AA\r\nBB"))
|
||||||
|
@ -2497,9 +2497,9 @@ class TextIOWrapperTest(unittest.TestCase):
|
||||||
def test_flush_error_on_close(self):
|
def test_flush_error_on_close(self):
|
||||||
txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii")
|
txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii")
|
||||||
def bad_flush():
|
def bad_flush():
|
||||||
raise IOError()
|
raise OSError()
|
||||||
txt.flush = bad_flush
|
txt.flush = bad_flush
|
||||||
self.assertRaises(IOError, txt.close) # exception not swallowed
|
self.assertRaises(OSError, txt.close) # exception not swallowed
|
||||||
self.assertTrue(txt.closed)
|
self.assertTrue(txt.closed)
|
||||||
|
|
||||||
def test_multi_close(self):
|
def test_multi_close(self):
|
||||||
|
@ -3032,7 +3032,7 @@ class SignalsTest(unittest.TestCase):
|
||||||
# buffer, and block again.
|
# buffer, and block again.
|
||||||
try:
|
try:
|
||||||
wio.close()
|
wio.close()
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.EBADF:
|
if e.errno != errno.EBADF:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -3160,7 +3160,7 @@ class SignalsTest(unittest.TestCase):
|
||||||
# buffer, and could block (in case of failure).
|
# buffer, and could block (in case of failure).
|
||||||
try:
|
try:
|
||||||
wio.close()
|
wio.close()
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.EBADF:
|
if e.errno != errno.EBADF:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tty = open("/dev/tty", "rb")
|
tty = open("/dev/tty", "rb")
|
||||||
except IOError:
|
except OSError:
|
||||||
raise unittest.SkipTest("Unable to open /dev/tty")
|
raise unittest.SkipTest("Unable to open /dev/tty")
|
||||||
else:
|
else:
|
||||||
# Skip if another process is in foreground
|
# Skip if another process is in foreground
|
||||||
|
|
|
@ -14,7 +14,7 @@ try:
|
||||||
import signal
|
import signal
|
||||||
# The default handler for SIGXFSZ is to abort the process.
|
# The default handler for SIGXFSZ is to abort the process.
|
||||||
# By ignoring it, system calls exceeding the file size resource
|
# By ignoring it, system calls exceeding the file size resource
|
||||||
# limit will raise IOError instead of crashing the interpreter.
|
# limit will raise OSError instead of crashing the interpreter.
|
||||||
oldhandler = signal.signal(signal.SIGXFSZ, signal.SIG_IGN)
|
oldhandler = signal.signal(signal.SIGXFSZ, signal.SIG_IGN)
|
||||||
except (ImportError, AttributeError):
|
except (ImportError, AttributeError):
|
||||||
pass
|
pass
|
||||||
|
@ -162,7 +162,7 @@ def test_main():
|
||||||
# flush, too!
|
# flush, too!
|
||||||
f.write(b'x')
|
f.write(b'x')
|
||||||
f.flush()
|
f.flush()
|
||||||
except (IOError, OverflowError):
|
except (OSError, OverflowError):
|
||||||
f.close()
|
f.close()
|
||||||
unlink(TESTFN)
|
unlink(TESTFN)
|
||||||
raise unittest.SkipTest("filesystem does not have largefile support")
|
raise unittest.SkipTest("filesystem does not have largefile support")
|
||||||
|
|
|
@ -3183,13 +3183,13 @@ class ShutdownTest(BaseTest):
|
||||||
self.assertEqual('0 - release', self.called[-1])
|
self.assertEqual('0 - release', self.called[-1])
|
||||||
|
|
||||||
def test_with_ioerror_in_acquire(self):
|
def test_with_ioerror_in_acquire(self):
|
||||||
self._test_with_failure_in_method('acquire', IOError)
|
self._test_with_failure_in_method('acquire', OSError)
|
||||||
|
|
||||||
def test_with_ioerror_in_flush(self):
|
def test_with_ioerror_in_flush(self):
|
||||||
self._test_with_failure_in_method('flush', IOError)
|
self._test_with_failure_in_method('flush', OSError)
|
||||||
|
|
||||||
def test_with_ioerror_in_close(self):
|
def test_with_ioerror_in_close(self):
|
||||||
self._test_with_failure_in_method('close', IOError)
|
self._test_with_failure_in_method('close', OSError)
|
||||||
|
|
||||||
def test_with_valueerror_in_acquire(self):
|
def test_with_valueerror_in_acquire(self):
|
||||||
self._test_with_failure_in_method('acquire', ValueError)
|
self._test_with_failure_in_method('acquire', ValueError)
|
||||||
|
|
|
@ -520,12 +520,12 @@ class TextIOTestMixin:
|
||||||
def test_relative_seek(self):
|
def test_relative_seek(self):
|
||||||
memio = self.ioclass()
|
memio = self.ioclass()
|
||||||
|
|
||||||
self.assertRaises(IOError, memio.seek, -1, 1)
|
self.assertRaises(OSError, memio.seek, -1, 1)
|
||||||
self.assertRaises(IOError, memio.seek, 3, 1)
|
self.assertRaises(OSError, memio.seek, 3, 1)
|
||||||
self.assertRaises(IOError, memio.seek, -3, 1)
|
self.assertRaises(OSError, memio.seek, -3, 1)
|
||||||
self.assertRaises(IOError, memio.seek, -1, 2)
|
self.assertRaises(OSError, memio.seek, -1, 2)
|
||||||
self.assertRaises(IOError, memio.seek, 1, 1)
|
self.assertRaises(OSError, memio.seek, 1, 1)
|
||||||
self.assertRaises(IOError, memio.seek, 1, 2)
|
self.assertRaises(OSError, memio.seek, 1, 2)
|
||||||
|
|
||||||
def test_textio_properties(self):
|
def test_textio_properties(self):
|
||||||
memio = self.ioclass()
|
memio = self.ioclass()
|
||||||
|
|
|
@ -684,11 +684,11 @@ class MmapTests(unittest.TestCase):
|
||||||
self.assertTrue(m.closed)
|
self.assertTrue(m.closed)
|
||||||
|
|
||||||
def test_context_manager_exception(self):
|
def test_context_manager_exception(self):
|
||||||
# Test that the IOError gets passed through
|
# Test that the OSError gets passed through
|
||||||
with self.assertRaises(Exception) as exc:
|
with self.assertRaises(Exception) as exc:
|
||||||
with mmap.mmap(-1, 10) as m:
|
with mmap.mmap(-1, 10) as m:
|
||||||
raise IOError
|
raise OSError
|
||||||
self.assertIsInstance(exc.exception, IOError,
|
self.assertIsInstance(exc.exception, OSError,
|
||||||
"wrong exception raised in context manager")
|
"wrong exception raised in context manager")
|
||||||
self.assertTrue(m.closed, "context manager failed")
|
self.assertTrue(m.closed, "context manager failed")
|
||||||
|
|
||||||
|
@ -709,7 +709,7 @@ class LargeMmapTests(unittest.TestCase):
|
||||||
f.seek(num_zeroes)
|
f.seek(num_zeroes)
|
||||||
f.write(tail)
|
f.write(tail)
|
||||||
f.flush()
|
f.flush()
|
||||||
except (IOError, OverflowError):
|
except (OSError, OverflowError):
|
||||||
f.close()
|
f.close()
|
||||||
raise unittest.SkipTest("filesystem does not have largefile support")
|
raise unittest.SkipTest("filesystem does not have largefile support")
|
||||||
return f
|
return f
|
||||||
|
|
|
@ -2019,7 +2019,7 @@ class _TestManagerRestart(BaseTestCase):
|
||||||
address=addr, authkey=authkey, serializer=SERIALIZER)
|
address=addr, authkey=authkey, serializer=SERIALIZER)
|
||||||
try:
|
try:
|
||||||
manager.start()
|
manager.start()
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.EADDRINUSE:
|
if e.errno != errno.EADDRINUSE:
|
||||||
raise
|
raise
|
||||||
# Retry after some time, in case the old socket was lingering
|
# Retry after some time, in case the old socket was lingering
|
||||||
|
@ -2132,9 +2132,9 @@ class _TestConnection(BaseTestCase):
|
||||||
self.assertEqual(reader.writable, False)
|
self.assertEqual(reader.writable, False)
|
||||||
self.assertEqual(writer.readable, False)
|
self.assertEqual(writer.readable, False)
|
||||||
self.assertEqual(writer.writable, True)
|
self.assertEqual(writer.writable, True)
|
||||||
self.assertRaises(IOError, reader.send, 2)
|
self.assertRaises(OSError, reader.send, 2)
|
||||||
self.assertRaises(IOError, writer.recv)
|
self.assertRaises(OSError, writer.recv)
|
||||||
self.assertRaises(IOError, writer.poll)
|
self.assertRaises(OSError, writer.poll)
|
||||||
|
|
||||||
def test_spawn_close(self):
|
def test_spawn_close(self):
|
||||||
# We test that a pipe connection can be closed by parent
|
# We test that a pipe connection can be closed by parent
|
||||||
|
@ -2296,8 +2296,8 @@ class _TestConnection(BaseTestCase):
|
||||||
if self.TYPE == 'processes':
|
if self.TYPE == 'processes':
|
||||||
self.assertTrue(a.closed)
|
self.assertTrue(a.closed)
|
||||||
self.assertTrue(b.closed)
|
self.assertTrue(b.closed)
|
||||||
self.assertRaises(IOError, a.recv)
|
self.assertRaises(OSError, a.recv)
|
||||||
self.assertRaises(IOError, b.recv)
|
self.assertRaises(OSError, b.recv)
|
||||||
|
|
||||||
class _TestListener(BaseTestCase):
|
class _TestListener(BaseTestCase):
|
||||||
|
|
||||||
|
@ -2318,7 +2318,7 @@ class _TestListener(BaseTestCase):
|
||||||
self.assertEqual(d.recv(), 1729)
|
self.assertEqual(d.recv(), 1729)
|
||||||
|
|
||||||
if self.TYPE == 'processes':
|
if self.TYPE == 'processes':
|
||||||
self.assertRaises(IOError, l.accept)
|
self.assertRaises(OSError, l.accept)
|
||||||
|
|
||||||
class _TestListenerClient(BaseTestCase):
|
class _TestListenerClient(BaseTestCase):
|
||||||
|
|
||||||
|
@ -2866,12 +2866,12 @@ class TestInvalidHandle(unittest.TestCase):
|
||||||
def test_invalid_handles(self):
|
def test_invalid_handles(self):
|
||||||
conn = multiprocessing.connection.Connection(44977608)
|
conn = multiprocessing.connection.Connection(44977608)
|
||||||
try:
|
try:
|
||||||
self.assertRaises((ValueError, IOError), conn.poll)
|
self.assertRaises((ValueError, OSError), conn.poll)
|
||||||
finally:
|
finally:
|
||||||
# Hack private attribute _handle to avoid printing an error
|
# Hack private attribute _handle to avoid printing an error
|
||||||
# in conn.__del__
|
# in conn.__del__
|
||||||
conn._handle = None
|
conn._handle = None
|
||||||
self.assertRaises((ValueError, IOError),
|
self.assertRaises((ValueError, OSError),
|
||||||
multiprocessing.connection.Connection, -1)
|
multiprocessing.connection.Connection, -1)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -43,7 +43,7 @@ class NormalizationTest(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
testdata = open_urlresource(TESTDATAURL, encoding="utf-8",
|
testdata = open_urlresource(TESTDATAURL, encoding="utf-8",
|
||||||
check=check_version)
|
check=check_version)
|
||||||
except (IOError, HTTPException):
|
except (OSError, HTTPException):
|
||||||
self.skipTest("Could not retrieve " + TESTDATAURL)
|
self.skipTest("Could not retrieve " + TESTDATAURL)
|
||||||
self.addCleanup(testdata.close)
|
self.addCleanup(testdata.close)
|
||||||
for line in testdata:
|
for line in testdata:
|
||||||
|
|
|
@ -44,7 +44,7 @@ class OSSAudioDevTests(unittest.TestCase):
|
||||||
def play_sound_file(self, data, rate, ssize, nchannels):
|
def play_sound_file(self, data, rate, ssize, nchannels):
|
||||||
try:
|
try:
|
||||||
dsp = ossaudiodev.open('w')
|
dsp = ossaudiodev.open('w')
|
||||||
except IOError as msg:
|
except OSError as msg:
|
||||||
if msg.args[0] in (errno.EACCES, errno.ENOENT,
|
if msg.args[0] in (errno.EACCES, errno.ENOENT,
|
||||||
errno.ENODEV, errno.EBUSY):
|
errno.ENODEV, errno.EBUSY):
|
||||||
raise unittest.SkipTest(msg)
|
raise unittest.SkipTest(msg)
|
||||||
|
@ -190,7 +190,7 @@ class OSSAudioDevTests(unittest.TestCase):
|
||||||
def test_main():
|
def test_main():
|
||||||
try:
|
try:
|
||||||
dsp = ossaudiodev.open('w')
|
dsp = ossaudiodev.open('w')
|
||||||
except (ossaudiodev.error, IOError) as msg:
|
except (ossaudiodev.error, OSError) as msg:
|
||||||
if msg.args[0] in (errno.EACCES, errno.ENOENT,
|
if msg.args[0] in (errno.EACCES, errno.ENOENT,
|
||||||
errno.ENODEV, errno.EBUSY):
|
errno.ENODEV, errno.EBUSY):
|
||||||
raise unittest.SkipTest(msg)
|
raise unittest.SkipTest(msg)
|
||||||
|
|
|
@ -550,7 +550,7 @@ class PosixTester(unittest.TestCase):
|
||||||
self.assertEqual(st.st_flags | stat.UF_IMMUTABLE, new_st.st_flags)
|
self.assertEqual(st.st_flags | stat.UF_IMMUTABLE, new_st.st_flags)
|
||||||
try:
|
try:
|
||||||
fd = open(target_file, 'w+')
|
fd = open(target_file, 'w+')
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
self.assertEqual(e.errno, errno.EPERM)
|
self.assertEqual(e.errno, errno.EPERM)
|
||||||
finally:
|
finally:
|
||||||
posix.chflags(target_file, st.st_flags)
|
posix.chflags(target_file, st.st_flags)
|
||||||
|
|
|
@ -61,7 +61,7 @@ class ResourceTest(unittest.TestCase):
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
f.flush()
|
f.flush()
|
||||||
except IOError:
|
except OSError:
|
||||||
if not limit_set:
|
if not limit_set:
|
||||||
raise
|
raise
|
||||||
if limit_set:
|
if limit_set:
|
||||||
|
|
|
@ -1515,7 +1515,7 @@ class TestCopyFile(unittest.TestCase):
|
||||||
self._exited_with = exc_type, exc_val, exc_tb
|
self._exited_with = exc_type, exc_val, exc_tb
|
||||||
if self._raise_in_exit:
|
if self._raise_in_exit:
|
||||||
self._raised = True
|
self._raised = True
|
||||||
raise IOError("Cannot close")
|
raise OSError("Cannot close")
|
||||||
return self._suppress_at_exit
|
return self._suppress_at_exit
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
@ -1529,12 +1529,12 @@ class TestCopyFile(unittest.TestCase):
|
||||||
def test_w_source_open_fails(self):
|
def test_w_source_open_fails(self):
|
||||||
def _open(filename, mode='r'):
|
def _open(filename, mode='r'):
|
||||||
if filename == 'srcfile':
|
if filename == 'srcfile':
|
||||||
raise IOError('Cannot open "srcfile"')
|
raise OSError('Cannot open "srcfile"')
|
||||||
assert 0 # shouldn't reach here.
|
assert 0 # shouldn't reach here.
|
||||||
|
|
||||||
self._set_shutil_open(_open)
|
self._set_shutil_open(_open)
|
||||||
|
|
||||||
self.assertRaises(IOError, shutil.copyfile, 'srcfile', 'destfile')
|
self.assertRaises(OSError, shutil.copyfile, 'srcfile', 'destfile')
|
||||||
|
|
||||||
def test_w_dest_open_fails(self):
|
def test_w_dest_open_fails(self):
|
||||||
|
|
||||||
|
@ -1544,14 +1544,14 @@ class TestCopyFile(unittest.TestCase):
|
||||||
if filename == 'srcfile':
|
if filename == 'srcfile':
|
||||||
return srcfile
|
return srcfile
|
||||||
if filename == 'destfile':
|
if filename == 'destfile':
|
||||||
raise IOError('Cannot open "destfile"')
|
raise OSError('Cannot open "destfile"')
|
||||||
assert 0 # shouldn't reach here.
|
assert 0 # shouldn't reach here.
|
||||||
|
|
||||||
self._set_shutil_open(_open)
|
self._set_shutil_open(_open)
|
||||||
|
|
||||||
shutil.copyfile('srcfile', 'destfile')
|
shutil.copyfile('srcfile', 'destfile')
|
||||||
self.assertTrue(srcfile._entered)
|
self.assertTrue(srcfile._entered)
|
||||||
self.assertTrue(srcfile._exited_with[0] is IOError)
|
self.assertTrue(srcfile._exited_with[0] is OSError)
|
||||||
self.assertEqual(srcfile._exited_with[1].args,
|
self.assertEqual(srcfile._exited_with[1].args,
|
||||||
('Cannot open "destfile"',))
|
('Cannot open "destfile"',))
|
||||||
|
|
||||||
|
@ -1573,7 +1573,7 @@ class TestCopyFile(unittest.TestCase):
|
||||||
self.assertTrue(srcfile._entered)
|
self.assertTrue(srcfile._entered)
|
||||||
self.assertTrue(destfile._entered)
|
self.assertTrue(destfile._entered)
|
||||||
self.assertTrue(destfile._raised)
|
self.assertTrue(destfile._raised)
|
||||||
self.assertTrue(srcfile._exited_with[0] is IOError)
|
self.assertTrue(srcfile._exited_with[0] is OSError)
|
||||||
self.assertEqual(srcfile._exited_with[1].args,
|
self.assertEqual(srcfile._exited_with[1].args,
|
||||||
('Cannot close',))
|
('Cannot close',))
|
||||||
|
|
||||||
|
@ -1591,7 +1591,7 @@ class TestCopyFile(unittest.TestCase):
|
||||||
|
|
||||||
self._set_shutil_open(_open)
|
self._set_shutil_open(_open)
|
||||||
|
|
||||||
self.assertRaises(IOError,
|
self.assertRaises(OSError,
|
||||||
shutil.copyfile, 'srcfile', 'destfile')
|
shutil.copyfile, 'srcfile', 'destfile')
|
||||||
self.assertTrue(srcfile._entered)
|
self.assertTrue(srcfile._entered)
|
||||||
self.assertTrue(destfile._entered)
|
self.assertTrue(destfile._entered)
|
||||||
|
|
|
@ -222,7 +222,7 @@ class DebuggingServerTests(unittest.TestCase):
|
||||||
self.assertEqual(smtp.source_address, ('127.0.0.1', port))
|
self.assertEqual(smtp.source_address, ('127.0.0.1', port))
|
||||||
self.assertEqual(smtp.local_hostname, 'localhost')
|
self.assertEqual(smtp.local_hostname, 'localhost')
|
||||||
smtp.quit()
|
smtp.quit()
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.EADDRINUSE:
|
if e.errno == errno.EADDRINUSE:
|
||||||
self.skipTest("couldn't bind to port %d" % port)
|
self.skipTest("couldn't bind to port %d" % port)
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -3723,7 +3723,7 @@ class FileObjectClassTestCase(SocketConnectedTest):
|
||||||
# First read raises a timeout
|
# First read raises a timeout
|
||||||
self.assertRaises(socket.timeout, self.read_file.read, 1)
|
self.assertRaises(socket.timeout, self.read_file.read, 1)
|
||||||
# Second read is disallowed
|
# Second read is disallowed
|
||||||
with self.assertRaises(IOError) as ctx:
|
with self.assertRaises(OSError) as ctx:
|
||||||
self.read_file.read(1)
|
self.read_file.read(1)
|
||||||
self.assertIn("cannot read from timed out object", str(ctx.exception))
|
self.assertIn("cannot read from timed out object", str(ctx.exception))
|
||||||
|
|
||||||
|
|
|
@ -246,15 +246,15 @@ class BasicSocketTests(unittest.TestCase):
|
||||||
s = ssl.wrap_socket(sock, server_side=True, certfile=CERTFILE)
|
s = ssl.wrap_socket(sock, server_side=True, certfile=CERTFILE)
|
||||||
self.assertRaisesRegex(ValueError, "can't connect in server-side mode",
|
self.assertRaisesRegex(ValueError, "can't connect in server-side mode",
|
||||||
s.connect, (HOST, 8080))
|
s.connect, (HOST, 8080))
|
||||||
with self.assertRaises(IOError) as cm:
|
with self.assertRaises(OSError) as cm:
|
||||||
with socket.socket() as sock:
|
with socket.socket() as sock:
|
||||||
ssl.wrap_socket(sock, certfile=WRONGCERT)
|
ssl.wrap_socket(sock, certfile=WRONGCERT)
|
||||||
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
||||||
with self.assertRaises(IOError) as cm:
|
with self.assertRaises(OSError) as cm:
|
||||||
with socket.socket() as sock:
|
with socket.socket() as sock:
|
||||||
ssl.wrap_socket(sock, certfile=CERTFILE, keyfile=WRONGCERT)
|
ssl.wrap_socket(sock, certfile=CERTFILE, keyfile=WRONGCERT)
|
||||||
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
||||||
with self.assertRaises(IOError) as cm:
|
with self.assertRaises(OSError) as cm:
|
||||||
with socket.socket() as sock:
|
with socket.socket() as sock:
|
||||||
ssl.wrap_socket(sock, certfile=WRONGCERT, keyfile=WRONGCERT)
|
ssl.wrap_socket(sock, certfile=WRONGCERT, keyfile=WRONGCERT)
|
||||||
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
||||||
|
@ -442,7 +442,7 @@ class ContextTests(unittest.TestCase):
|
||||||
ctx.load_cert_chain(CERTFILE)
|
ctx.load_cert_chain(CERTFILE)
|
||||||
ctx.load_cert_chain(CERTFILE, keyfile=CERTFILE)
|
ctx.load_cert_chain(CERTFILE, keyfile=CERTFILE)
|
||||||
self.assertRaises(TypeError, ctx.load_cert_chain, keyfile=CERTFILE)
|
self.assertRaises(TypeError, ctx.load_cert_chain, keyfile=CERTFILE)
|
||||||
with self.assertRaises(IOError) as cm:
|
with self.assertRaises(OSError) as cm:
|
||||||
ctx.load_cert_chain(WRONGCERT)
|
ctx.load_cert_chain(WRONGCERT)
|
||||||
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
||||||
with self.assertRaisesRegex(ssl.SSLError, "PEM lib"):
|
with self.assertRaisesRegex(ssl.SSLError, "PEM lib"):
|
||||||
|
@ -527,7 +527,7 @@ class ContextTests(unittest.TestCase):
|
||||||
ctx.load_verify_locations(cafile=BYTES_CERTFILE, capath=None)
|
ctx.load_verify_locations(cafile=BYTES_CERTFILE, capath=None)
|
||||||
self.assertRaises(TypeError, ctx.load_verify_locations)
|
self.assertRaises(TypeError, ctx.load_verify_locations)
|
||||||
self.assertRaises(TypeError, ctx.load_verify_locations, None, None)
|
self.assertRaises(TypeError, ctx.load_verify_locations, None, None)
|
||||||
with self.assertRaises(IOError) as cm:
|
with self.assertRaises(OSError) as cm:
|
||||||
ctx.load_verify_locations(WRONGCERT)
|
ctx.load_verify_locations(WRONGCERT)
|
||||||
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
self.assertEqual(cm.exception.errno, errno.ENOENT)
|
||||||
with self.assertRaisesRegex(ssl.SSLError, "PEM lib"):
|
with self.assertRaisesRegex(ssl.SSLError, "PEM lib"):
|
||||||
|
@ -1229,11 +1229,11 @@ else:
|
||||||
except OSError as x:
|
except OSError as x:
|
||||||
if support.verbose:
|
if support.verbose:
|
||||||
sys.stdout.write("\nOSError is %s\n" % x.args[1])
|
sys.stdout.write("\nOSError is %s\n" % x.args[1])
|
||||||
except IOError as x:
|
except OSError as x:
|
||||||
if x.errno != errno.ENOENT:
|
if x.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
if support.verbose:
|
if support.verbose:
|
||||||
sys.stdout.write("\IOError is %s\n" % str(x))
|
sys.stdout.write("\OSError is %s\n" % str(x))
|
||||||
else:
|
else:
|
||||||
raise AssertionError("Use of invalid cert should have failed!")
|
raise AssertionError("Use of invalid cert should have failed!")
|
||||||
|
|
||||||
|
@ -1387,7 +1387,7 @@ else:
|
||||||
"badkey.pem"))
|
"badkey.pem"))
|
||||||
|
|
||||||
def test_rude_shutdown(self):
|
def test_rude_shutdown(self):
|
||||||
"""A brutal shutdown of an SSL server should raise an IOError
|
"""A brutal shutdown of an SSL server should raise an OSError
|
||||||
in the client when attempting handshake.
|
in the client when attempting handshake.
|
||||||
"""
|
"""
|
||||||
listener_ready = threading.Event()
|
listener_ready = threading.Event()
|
||||||
|
@ -1415,7 +1415,7 @@ else:
|
||||||
listener_gone.wait()
|
listener_gone.wait()
|
||||||
try:
|
try:
|
||||||
ssl_sock = ssl.wrap_socket(c)
|
ssl_sock = ssl.wrap_socket(c)
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.fail('connecting to closed SSL socket should have failed')
|
self.fail('connecting to closed SSL socket should have failed')
|
||||||
|
|
|
@ -489,7 +489,7 @@ class StructTest(unittest.TestCase):
|
||||||
def test_bool(self):
|
def test_bool(self):
|
||||||
class ExplodingBool(object):
|
class ExplodingBool(object):
|
||||||
def __bool__(self):
|
def __bool__(self):
|
||||||
raise IOError
|
raise OSError
|
||||||
for prefix in tuple("<>!=")+('',):
|
for prefix in tuple("<>!=")+('',):
|
||||||
false = (), [], [], '', 0
|
false = (), [], [], '', 0
|
||||||
true = [1], 'test', 5, -1, 0xffffffff+1, 0xffffffff/2
|
true = [1], 'test', 5, -1, 0xffffffff+1, 0xffffffff/2
|
||||||
|
@ -520,10 +520,10 @@ class StructTest(unittest.TestCase):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
struct.pack(prefix + '?', ExplodingBool())
|
struct.pack(prefix + '?', ExplodingBool())
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.fail("Expected IOError: struct.pack(%r, "
|
self.fail("Expected OSError: struct.pack(%r, "
|
||||||
"ExplodingBool())" % (prefix + '?'))
|
"ExplodingBool())" % (prefix + '?'))
|
||||||
|
|
||||||
for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']:
|
for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']:
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue