Commit 62ab10a0 authored by Antoine Pitrou's avatar Antoine Pitrou

Replace mentions of IOError

parent 5d6fbe82
...@@ -69,7 +69,7 @@ making an explicit call into this module at termination. :: ...@@ -69,7 +69,7 @@ making an explicit call into this module at termination. ::
try: try:
with open("/tmp/counter") as infile: with open("/tmp/counter") as infile:
_count = int(infile.read()) _count = int(infile.read())
except IOError: except FileNotFoundError:
_count = 0 _count = 0
def incrcounter(n): def incrcounter(n):
......
...@@ -19,6 +19,11 @@ argument. This can be an integer file descriptor, such as returned by ...@@ -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`` ``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. 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: The module defines the following functions:
...@@ -40,7 +45,7 @@ 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 larger than 1024 bytes, this is most likely to result in a segmentation
violation or a more subtle data corruption. 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]]) .. function:: ioctl(fd, op[, arg[, mutate_flag]])
...@@ -107,7 +112,7 @@ The module defines the following functions: ...@@ -107,7 +112,7 @@ The module defines the following functions:
When *operation* is :const:`LOCK_SH` or :const:`LOCK_EX`, it can also be 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. 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 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 attribute set to :const:`EACCES` or :const:`EAGAIN` (depending on the
operating system; for portability, check for both values). On at least some 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 systems, :const:`LOCK_EX` can only be used if the file descriptor refers to a
......
...@@ -783,7 +783,7 @@ are always available. They are listed here in alphabetical order. ...@@ -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) .. 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, 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 *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 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. ...@@ -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`, (where :func:`open` is declared), :mod:`os`, :mod:`os.path`, :mod:`tempfile`,
and :mod:`shutil`. 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? .. XXX works for bytes too, but should it?
.. function:: ord(c) .. function:: ord(c)
......
...@@ -185,10 +185,13 @@ class can also install themselves in the built-in namespace as the function ...@@ -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 translation object from the cache; the actual instance data is still shared with
the cache. 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 *fallback* is false (which is the default), and returns a
:class:`NullTranslations` instance if *fallback* is true. :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) .. 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 ...@@ -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 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 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: The following methods are overridden from the base class implementation:
......
...@@ -40,7 +40,11 @@ The module defines the following exception: ...@@ -40,7 +40,11 @@ The module defines the following exception:
.. exception:: LoadError .. exception:: LoadError
Instances of :class:`FileCookieJar` raise this exception on failure to load 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: The following classes are provided:
...@@ -257,9 +261,12 @@ contained :class:`Cookie` objects. ...@@ -257,9 +261,12 @@ contained :class:`Cookie` objects.
Arguments are as for :meth:`save`. Arguments are as for :meth:`save`.
The named file must be in the format understood by the class, or 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. 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) .. method:: FileCookieJar.revert(filename=None, ignore_discard=False, ignore_expires=False)
......
...@@ -318,7 +318,7 @@ of which this module provides three different variants: ...@@ -318,7 +318,7 @@ of which this module provides three different variants:
response if the :func:`listdir` fails. response if the :func:`listdir` fails.
If the request was mapped to a file, it is opened and the contents are 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 mapped to a ``404``, ``'File not found'`` error. Otherwise, the content
type is guessed by calling the :meth:`guess_type` method, which in turn type is guessed by calling the :meth:`guess_type` method, which in turn
uses the *extensions_map* variable. uses the *extensions_map* variable.
......
...@@ -355,17 +355,25 @@ Retrieving source code ...@@ -355,17 +355,25 @@ Retrieving source code
argument may be a module, class, method, function, traceback, frame, or 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. 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 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. be retrieved.
.. versionchanged:: 3.3
:exc:`OSError` is raised instead of :exc:`IOError`, now an alias of the
former.
.. function:: getsource(object) .. function:: getsource(object)
Return the text of the source code for an object. The argument may be a module, 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 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. cannot be retrieved.
.. versionchanged:: 3.3
:exc:`OSError` is raised instead of :exc:`IOError`, now an alias of the
former.
.. function:: cleandoc(doc) .. function:: cleandoc(doc)
......
...@@ -20,6 +20,11 @@ api. The normal API deals only with ASCII characters and is of limited use ...@@ -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 for internationalized applications. The wide char API should be used where
ever possible ever possible
.. versionchanged:: 3.3
Operations in this module now raise :exc:`OSError` where :exc:`IOError`
was raised.
.. _msvcrt-files: .. _msvcrt-files:
File Operations File Operations
...@@ -29,7 +34,7 @@ File Operations ...@@ -29,7 +34,7 @@ File Operations
.. function:: locking(fd, mode, nbytes) .. function:: locking(fd, mode, nbytes)
Lock part of a file based on file descriptor *fd* from the C runtime. Raises 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 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 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 regions in a file may be locked at the same time, but may not overlap. Adjacent
...@@ -41,13 +46,13 @@ File Operations ...@@ -41,13 +46,13 @@ File Operations
Locks the specified bytes. If the bytes cannot be locked, the program 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 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 .. data:: LK_NBLCK
LK_NBRLCK 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. raised.
...@@ -73,7 +78,7 @@ File Operations ...@@ -73,7 +78,7 @@ File Operations
.. function:: get_osfhandle(fd) .. 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. *fd* is not recognized.
...@@ -144,4 +149,4 @@ Other Functions ...@@ -144,4 +149,4 @@ Other Functions
.. function:: heapmin() .. function:: heapmin()
Force the :c:func:`malloc` heap to clean itself up and return unused blocks to 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`.
...@@ -784,9 +784,14 @@ Connection objects usually created using :func:`Pipe` -- see also ...@@ -784,9 +784,14 @@ Connection objects usually created using :func:`Pipe` -- see also
to receive and the other end has closed. to receive and the other end has closed.
If *maxlength* is specified and the message is longer than *maxlength* 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. 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]) .. method:: recv_bytes_into(buffer[, offset])
Read into *buffer* a complete message of byte data sent from the other end Read into *buffer* a complete message of byte data sent from the other end
......
...@@ -1426,11 +1426,8 @@ Files and Directories ...@@ -1426,11 +1426,8 @@ Files and Directories
try: try:
fp = open("myfile") fp = open("myfile")
except IOError as e: except PermissionError:
if e.errno == errno.EACCESS: return "some default data"
return "some default data"
# Not a permission error.
raise
else: else:
with fp: with fp:
return fp.read() return fp.read()
......
...@@ -38,6 +38,10 @@ the standard audio interface for Linux and recent versions of FreeBSD. ...@@ -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 This probably all warrants a footnote or two, but I don't understand
things well enough right now to write it! --GPW 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:: .. seealso::
...@@ -56,7 +60,7 @@ the standard audio interface for Linux and recent versions of FreeBSD. ...@@ -56,7 +60,7 @@ the standard audio interface for Linux and recent versions of FreeBSD.
what went wrong. what went wrong.
(If :mod:`ossaudiodev` receives an error from a system call such as (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`.) Errors detected directly by :mod:`ossaudiodev` result in :exc:`OSSAudioError`.)
(For backwards compatibility, the exception class is also available as (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 ...@@ -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 correspondence is obvious: for example, :meth:`setfmt` corresponds to the
``SNDCTL_DSP_SETFMT`` ioctl, and :meth:`sync` to ``SNDCTL_DSP_SYNC`` (this can ``SNDCTL_DSP_SETFMT`` ioctl, and :meth:`sync` to ``SNDCTL_DSP_SYNC`` (this can
be useful when consulting the OSS documentation). If the underlying 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() .. method:: oss_audio_device.nonblock()
...@@ -344,7 +348,7 @@ The mixer object provides two file-like methods: ...@@ -344,7 +348,7 @@ The mixer object provides two file-like methods:
.. method:: oss_mixer_device.close() .. method:: oss_mixer_device.close()
This method closes the open mixer device file. Any further attempts to use the 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() .. method:: oss_mixer_device.fileno()
...@@ -403,7 +407,7 @@ The remaining methods are specific to audio mixing: ...@@ -403,7 +407,7 @@ The remaining methods are specific to audio mixing:
returned, but both volumes are the same. returned, but both volumes are the same.
Raises :exc:`OSSAudioError` if an invalid control was is specified, or 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)) .. method:: oss_mixer_device.set(control, (left, right))
...@@ -427,7 +431,7 @@ The remaining methods are specific to audio mixing: ...@@ -427,7 +431,7 @@ The remaining methods are specific to audio mixing:
.. method:: oss_mixer_device.set_recsrc(bitmask) .. method:: oss_mixer_device.set_recsrc(bitmask)
Call this function to specify a recording source. Returns a bitmask indicating 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 invalid source was specified. To set the current recording source to the
microphone input:: microphone input::
......
...@@ -213,7 +213,7 @@ information that can be obtained using functions provided in this module:: ...@@ -213,7 +213,7 @@ information that can be obtained using functions provided in this module::
# first create the Distribution instance # first create the Distribution instance
try: try:
dist = packaging.database.Distribution(path) dist = packaging.database.Distribution(path)
except IOError: except FileNotFoundError:
sys.exit('No such distribution') sys.exit('No such distribution')
print('Information about %r' % dist.name) print('Information about %r' % dist.name)
......
...@@ -199,7 +199,7 @@ normally be executed automatically during interactive sessions from the user's ...@@ -199,7 +199,7 @@ normally be executed automatically during interactive sessions from the user's
histfile = os.path.join(os.path.expanduser("~"), ".pyhist") histfile = os.path.join(os.path.expanduser("~"), ".pyhist")
try: try:
readline.read_history_file(histfile) readline.read_history_file(histfile)
except IOError: except FileNotFoundError:
pass pass
import atexit import atexit
atexit.register(readline.write_history_file, histfile) atexit.register(readline.write_history_file, histfile)
...@@ -224,7 +224,7 @@ support history save/restore. :: ...@@ -224,7 +224,7 @@ support history save/restore. ::
if hasattr(readline, "read_history_file"): if hasattr(readline, "read_history_file"):
try: try:
readline.read_history_file(histfile) readline.read_history_file(histfile)
except IOError: except FileNotFoundError:
pass pass
atexit.register(self.save_history, histfile) atexit.register(self.save_history, histfile)
......
...@@ -51,11 +51,14 @@ Directory and files operations ...@@ -51,11 +51,14 @@ Directory and files operations
*dst* must be the complete target file name; look at :func:`copy` for a copy that *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, accepts a target directory path. If *src* and *dst* are the same files,
:exc:`Error` is raised. :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 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 such as character or block devices and pipes cannot be copied with this
function. *src* and *dst* are path names given as strings. 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) .. function:: copymode(src, dst)
......
...@@ -262,9 +262,9 @@ be finalized; only the internally used file object will be closed. See the ...@@ -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`. 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 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 is enabled. If ``1``, all *fatal* errors are raised as :exc:`OSError`
:exc:`IOError` exceptions. If ``2``, all *non-fatal* errors are raised as exceptions. If ``2``, all *non-fatal* errors are raised as :exc:`TarError`
:exc:`TarError` exceptions as well. exceptions as well.
The *encoding* and *errors* arguments define the character encoding to be The *encoding* and *errors* arguments define the character encoding to be
used for reading or writing the archive and how conversion errors are going used for reading or writing the archive and how conversion errors are going
......
...@@ -8,20 +8,23 @@ ...@@ -8,20 +8,23 @@
The :mod:`urllib.error` module defines the exception classes for exceptions The :mod:`urllib.error` module defines the exception classes for exceptions
raised by :mod:`urllib.request`. The base exception class is :exc:`URLError`, raised by :mod:`urllib.request`. The base exception class is :exc:`URLError`.
which inherits from :exc:`IOError`.
The following exceptions are raised by :mod:`urllib.error` as appropriate: The following exceptions are raised by :mod:`urllib.error` as appropriate:
.. exception:: URLError .. exception:: URLError
The handlers raise this exception (or derived exceptions) when they run into 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 .. attribute:: reason
The reason for this error. It can be a message string or another 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 .. exception:: HTTPError
......
...@@ -85,9 +85,12 @@ zipimporter Objects ...@@ -85,9 +85,12 @@ zipimporter Objects
.. method:: get_data(pathname) .. 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. file wasn't found.
.. versionchanged:: 3.3
:exc:`IOError` used to be raised instead of :exc:`OSError`.
.. method:: get_filename(fullname) .. method:: get_filename(fullname)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment