Replace mentions of IOError

This commit is contained in:
Antoine Pitrou 2011-10-12 20:10:51 +02:00
parent 5d6fbe8207
commit 62ab10a05a
17 changed files with 85 additions and 39 deletions

View File

@ -69,7 +69,7 @@ making an explicit call into this module at termination. ::
try:
with open("/tmp/counter") as infile:
_count = int(infile.read())
except IOError:
except FileNotFoundError:
_count = 0
def incrcounter(n):

View File

@ -19,6 +19,11 @@ argument. This can be an integer file descriptor, such as returned by
``sys.stdin.fileno()``, or a :class:`io.IOBase` object, such as ``sys.stdin``
itself, which provides a :meth:`fileno` that returns a genuine file descriptor.
.. versionchanged:: 3.3
Operations in this module used to raise a :exc:`IOError` where they now
raise a :exc:`OSError`.
The module defines the following functions:
@ -40,7 +45,7 @@ The module defines the following functions:
larger than 1024 bytes, this is most likely to result in a segmentation
violation or a more subtle data corruption.
If the :c:func:`fcntl` fails, an :exc:`IOError` is raised.
If the :c:func:`fcntl` fails, an :exc:`OSError` is raised.
.. function:: ioctl(fd, op[, arg[, mutate_flag]])
@ -107,7 +112,7 @@ The module defines the following functions:
When *operation* is :const:`LOCK_SH` or :const:`LOCK_EX`, it can also be
bitwise ORed with :const:`LOCK_NB` to avoid blocking on lock acquisition.
If :const:`LOCK_NB` is used and the lock cannot be acquired, an
:exc:`IOError` will be raised and the exception will have an *errno*
:exc:`OSError` will be raised and the exception will have an *errno*
attribute set to :const:`EACCES` or :const:`EAGAIN` (depending on the
operating system; for portability, check for both values). On at least some
systems, :const:`LOCK_EX` can only be used if the file descriptor refers to a

View File

@ -783,7 +783,7 @@ are always available. They are listed here in alphabetical order.
.. function:: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True)
Open *file* and return a corresponding stream. If the file cannot be opened,
an :exc:`IOError` is raised.
an :exc:`OSError` is raised.
*file* is either a string or bytes object giving the pathname (absolute or
relative to the current working directory) of the file to be opened or
@ -912,6 +912,9 @@ are always available. They are listed here in alphabetical order.
(where :func:`open` is declared), :mod:`os`, :mod:`os.path`, :mod:`tempfile`,
and :mod:`shutil`.
.. versionchanged:: 3.3
:exc:`IOError` used to be raised, it is now an alias of :exc:`OSError`.
.. XXX works for bytes too, but should it?
.. function:: ord(c)

View File

@ -185,10 +185,13 @@ class can also install themselves in the built-in namespace as the function
translation object from the cache; the actual instance data is still shared with
the cache.
If no :file:`.mo` file is found, this function raises :exc:`IOError` if
If no :file:`.mo` file is found, this function raises :exc:`OSError` if
*fallback* is false (which is the default), and returns a
:class:`NullTranslations` instance if *fallback* is true.
.. versionchanged:: 3.3
:exc:`IOError` used to be raised instead of :exc:`OSError`.
.. function:: install(domain, localedir=None, codeset=None, names=None)
@ -342,7 +345,7 @@ The entire set of key/value pairs are placed into a dictionary and set as the
If the :file:`.mo` file's magic number is invalid, or if other problems occur
while reading the file, instantiating a :class:`GNUTranslations` class can raise
:exc:`IOError`.
:exc:`OSError`.
The following methods are overridden from the base class implementation:

View File

@ -40,7 +40,11 @@ The module defines the following exception:
.. exception:: LoadError
Instances of :class:`FileCookieJar` raise this exception on failure to load
cookies from a file. :exc:`LoadError` is a subclass of :exc:`IOError`.
cookies from a file. :exc:`LoadError` is a subclass of :exc:`OSError`.
.. versionchanged:: 3.3
LoadError was made a subclass of :exc:`OSError` instead of
:exc:`IOError`.
The following classes are provided:
@ -257,9 +261,12 @@ contained :class:`Cookie` objects.
Arguments are as for :meth:`save`.
The named file must be in the format understood by the class, or
:exc:`LoadError` will be raised. Also, :exc:`IOError` may be raised, for
:exc:`LoadError` will be raised. Also, :exc:`OSError` may be raised, for
example if the file does not exist.
.. versionchanged:: 3.3
:exc:`IOError` used to be raised, it is now an alias of :exc:`OSError`.
.. method:: FileCookieJar.revert(filename=None, ignore_discard=False, ignore_expires=False)

View File

@ -318,7 +318,7 @@ of which this module provides three different variants:
response if the :func:`listdir` fails.
If the request was mapped to a file, it is opened and the contents are
returned. Any :exc:`IOError` exception in opening the requested file is
returned. Any :exc:`OSError` exception in opening the requested file is
mapped to a ``404``, ``'File not found'`` error. Otherwise, the content
type is guessed by calling the :meth:`guess_type` method, which in turn
uses the *extensions_map* variable.

View File

@ -355,17 +355,25 @@ Retrieving source code
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 :exc:`IOError` is raised if the source code cannot
line of code was found. An :exc:`OSError` is raised if the source code cannot
be retrieved.
.. versionchanged:: 3.3
:exc:`OSError` is raised instead of :exc:`IOError`, now an alias of the
former.
.. function:: getsource(object)
Return the text of the source code for an 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 :exc:`IOError` is raised if the source code
returned as a single string. An :exc:`OSError` is raised if the source code
cannot be retrieved.
.. versionchanged:: 3.3
:exc:`OSError` is raised instead of :exc:`IOError`, now an alias of the
former.
.. function:: cleandoc(doc)

View File

@ -20,6 +20,11 @@ api. The normal API deals only with ASCII characters and is of limited use
for internationalized applications. The wide char API should be used where
ever possible
.. versionchanged:: 3.3
Operations in this module now raise :exc:`OSError` where :exc:`IOError`
was raised.
.. _msvcrt-files:
File Operations
@ -29,7 +34,7 @@ File Operations
.. function:: locking(fd, mode, nbytes)
Lock part of a file based on file descriptor *fd* from the C runtime. Raises
:exc:`IOError` on failure. The locked region of the file extends from the
:exc:`OSError` on failure. The locked region of the file extends from the
current file position for *nbytes* bytes, and may continue beyond the end of the
file. *mode* must be one of the :const:`LK_\*` constants listed below. Multiple
regions in a file may be locked at the same time, but may not overlap. Adjacent
@ -41,13 +46,13 @@ File Operations
Locks the specified bytes. If the bytes cannot be locked, the program
immediately tries again after 1 second. If, after 10 attempts, the bytes cannot
be locked, :exc:`IOError` is raised.
be locked, :exc:`OSError` is raised.
.. data:: LK_NBLCK
LK_NBRLCK
Locks the specified bytes. If the bytes cannot be locked, :exc:`IOError` is
Locks the specified bytes. If the bytes cannot be locked, :exc:`OSError` is
raised.
@ -73,7 +78,7 @@ File Operations
.. function:: get_osfhandle(fd)
Return the file handle for the file descriptor *fd*. Raises :exc:`IOError` if
Return the file handle for the file descriptor *fd*. Raises :exc:`OSError` if
*fd* is not recognized.
@ -144,4 +149,4 @@ Other Functions
.. function:: heapmin()
Force the :c:func:`malloc` heap to clean itself up and return unused blocks to
the operating system. On failure, this raises :exc:`IOError`.
the operating system. On failure, this raises :exc:`OSError`.

View File

@ -784,9 +784,14 @@ Connection objects usually created using :func:`Pipe` -- see also
to receive and the other end has closed.
If *maxlength* is specified and the message is longer than *maxlength*
then :exc:`IOError` is raised and the connection will no longer be
then :exc:`OSError` is raised and the connection will no longer be
readable.
.. versionchanged:: 3.3
This function used to raise a :exc:`IOError`, which is now an
alias of :exc:`OSError`.
.. method:: recv_bytes_into(buffer[, offset])
Read into *buffer* a complete message of byte data sent from the other end

View File

@ -1426,11 +1426,8 @@ Files and Directories
try:
fp = open("myfile")
except IOError as e:
if e.errno == errno.EACCESS:
return "some default data"
# Not a permission error.
raise
except PermissionError:
return "some default data"
else:
with fp:
return fp.read()

View File

@ -38,6 +38,10 @@ the standard audio interface for Linux and recent versions of FreeBSD.
This probably all warrants a footnote or two, but I don't understand
things well enough right now to write it! --GPW
.. versionchanged:: 3.3
Operations in this module now raise :exc:`OSError` where :exc:`IOError`
was raised.
.. seealso::
@ -56,7 +60,7 @@ the standard audio interface for Linux and recent versions of FreeBSD.
what went wrong.
(If :mod:`ossaudiodev` receives an error from a system call such as
:c:func:`open`, :c:func:`write`, or :c:func:`ioctl`, it raises :exc:`IOError`.
:c:func:`open`, :c:func:`write`, or :c:func:`ioctl`, it raises :exc:`OSError`.
Errors detected directly by :mod:`ossaudiodev` result in :exc:`OSSAudioError`.)
(For backwards compatibility, the exception class is also available as
@ -168,7 +172,7 @@ The following methods each map to exactly one :func:`ioctl` system call. The
correspondence is obvious: for example, :meth:`setfmt` corresponds to the
``SNDCTL_DSP_SETFMT`` ioctl, and :meth:`sync` to ``SNDCTL_DSP_SYNC`` (this can
be useful when consulting the OSS documentation). If the underlying
:func:`ioctl` fails, they all raise :exc:`IOError`.
:func:`ioctl` fails, they all raise :exc:`OSError`.
.. method:: oss_audio_device.nonblock()
@ -344,7 +348,7 @@ The mixer object provides two file-like methods:
.. method:: oss_mixer_device.close()
This method closes the open mixer device file. Any further attempts to use the
mixer after this file is closed will raise an :exc:`IOError`.
mixer after this file is closed will raise an :exc:`OSError`.
.. method:: oss_mixer_device.fileno()
@ -403,7 +407,7 @@ The remaining methods are specific to audio mixing:
returned, but both volumes are the same.
Raises :exc:`OSSAudioError` if an invalid control was is specified, or
:exc:`IOError` if an unsupported control is specified.
:exc:`OSError` if an unsupported control is specified.
.. method:: oss_mixer_device.set(control, (left, right))
@ -427,7 +431,7 @@ The remaining methods are specific to audio mixing:
.. method:: oss_mixer_device.set_recsrc(bitmask)
Call this function to specify a recording source. Returns a bitmask indicating
the new recording source (or sources) if successful; raises :exc:`IOError` if an
the new recording source (or sources) if successful; raises :exc:`OSError` if an
invalid source was specified. To set the current recording source to the
microphone input::

View File

@ -213,7 +213,7 @@ information that can be obtained using functions provided in this module::
# first create the Distribution instance
try:
dist = packaging.database.Distribution(path)
except IOError:
except FileNotFoundError:
sys.exit('No such distribution')
print('Information about %r' % dist.name)

View File

@ -199,7 +199,7 @@ normally be executed automatically during interactive sessions from the user's
histfile = os.path.join(os.path.expanduser("~"), ".pyhist")
try:
readline.read_history_file(histfile)
except IOError:
except FileNotFoundError:
pass
import atexit
atexit.register(readline.write_history_file, histfile)
@ -224,7 +224,7 @@ support history save/restore. ::
if hasattr(readline, "read_history_file"):
try:
readline.read_history_file(histfile)
except IOError:
except FileNotFoundError:
pass
atexit.register(self.save_history, histfile)

View File

@ -51,11 +51,14 @@ Directory and files operations
*dst* must be the complete target file name; look at :func:`copy` for a copy that
accepts a target directory path. If *src* and *dst* are the same files,
:exc:`Error` is raised.
The destination location must be writable; otherwise, an :exc:`IOError` exception
The destination location must be writable; otherwise, an :exc:`OSError` exception
will be raised. If *dst* already exists, it will be replaced. Special files
such as character or block devices and pipes cannot be copied with this
function. *src* and *dst* are path names given as strings.
.. versionchanged:: 3.3
:exc:`IOError` used to be raised instead of :exc:`OSError`.
.. function:: copymode(src, dst)

View File

@ -262,9 +262,9 @@ be finalized; only the internally used file object will be closed. See the
If *errorlevel* is ``0``, all errors are ignored when using :meth:`TarFile.extract`.
Nevertheless, they appear as error messages in the debug output, when debugging
is enabled. If ``1``, all *fatal* errors are raised as :exc:`OSError` or
:exc:`IOError` exceptions. If ``2``, all *non-fatal* errors are raised as
:exc:`TarError` exceptions as well.
is enabled. If ``1``, all *fatal* errors are raised as :exc:`OSError`
exceptions. If ``2``, all *non-fatal* errors are raised as :exc:`TarError`
exceptions as well.
The *encoding* and *errors* arguments define the character encoding to be
used for reading or writing the archive and how conversion errors are going

View File

@ -8,20 +8,23 @@
The :mod:`urllib.error` module defines the exception classes for exceptions
raised by :mod:`urllib.request`. The base exception class is :exc:`URLError`,
which inherits from :exc:`IOError`.
raised by :mod:`urllib.request`. The base exception class is :exc:`URLError`.
The following exceptions are raised by :mod:`urllib.error` as appropriate:
.. exception:: URLError
The handlers raise this exception (or derived exceptions) when they run into
a problem. It is a subclass of :exc:`IOError`.
a problem. It is a subclass of :exc:`OSError`.
.. attribute:: reason
The reason for this error. It can be a message string or another
exception instance such as :exc:`OSError`.
exception instance.
.. versionchanged:: 3.3
:exc:`URLError` has been made a subclass of :exc:`OSError` instead
of :exc:`IOError`.
.. exception:: HTTPError

View File

@ -85,9 +85,12 @@ zipimporter Objects
.. method:: get_data(pathname)
Return the data associated with *pathname*. Raise :exc:`IOError` if the
Return the data associated with *pathname*. Raise :exc:`OSError` if the
file wasn't found.
.. versionchanged:: 3.3
:exc:`IOError` used to be raised instead of :exc:`OSError`.
.. method:: get_filename(fullname)