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