Commit c19225ef authored by Serhiy Storchaka's avatar Serhiy Storchaka

Improve #19204: Improved cross-references in the urllib package documentation.

parent ce7df06d
...@@ -31,8 +31,9 @@ The following exceptions are raised by :mod:`urllib.error` as appropriate: ...@@ -31,8 +31,9 @@ The following exceptions are raised by :mod:`urllib.error` as appropriate:
Though being an exception (a subclass of :exc:`URLError`), an Though being an exception (a subclass of :exc:`URLError`), an
:exc:`HTTPError` can also function as a non-exceptional file-like return :exc:`HTTPError` can also function as a non-exceptional file-like return
value (the same thing that :func:`urlopen` returns). This is useful when value (the same thing that :func:`~urllib.request.urlopen` returns). This
handling exotic HTTP errors, such as requests for authentication. is useful when handling exotic HTTP errors, such as requests for
authentication.
.. attribute:: code .. attribute:: code
...@@ -47,7 +48,8 @@ The following exceptions are raised by :mod:`urllib.error` as appropriate: ...@@ -47,7 +48,8 @@ The following exceptions are raised by :mod:`urllib.error` as appropriate:
.. exception:: ContentTooShortError(msg, content) .. exception:: ContentTooShortError(msg, content)
This exception is raised when the :func:`urlretrieve` function detects that This exception is raised when the :func:`~urllib.request.urlretrieve`
function detects that
the amount of the downloaded data is less than the expected amount (given by the amount of the downloaded data is less than the expected amount (given by
the *Content-Length* header). The :attr:`content` attribute stores the the *Content-Length* header). The :attr:`content` attribute stores the
downloaded (and supposedly truncated) data. downloaded (and supposedly truncated) data.
......
...@@ -518,8 +518,8 @@ task isn't already covered by the URL parsing functions above. ...@@ -518,8 +518,8 @@ task isn't already covered by the URL parsing functions above.
Convert a mapping object or a sequence of two-element tuples, which may Convert a mapping object or a sequence of two-element tuples, which may
either be a :class:`str` or a :class:`bytes`, to a "percent-encoded" either be a :class:`str` or a :class:`bytes`, to a "percent-encoded"
string. If the resultant string is to be used as a *data* for POST string. If the resultant string is to be used as a *data* for POST
operation with :func:`urlopen` function, then it should be properly encoded operation with :func:`~urllib.request.urlopen` function, then it should be
to bytes, otherwise it would result in a :exc:`TypeError`. properly encoded to bytes, otherwise it would result in a :exc:`TypeError`.
The resulting string is a series of ``key=value`` pairs separated by ``'&'`` The resulting string is a series of ``key=value`` pairs separated by ``'&'``
characters, where both *key* and *value* are quoted using :func:`quote_plus` characters, where both *key* and *value* are quoted using :func:`quote_plus`
......
...@@ -81,7 +81,7 @@ The :mod:`urllib.request` module defines the following functions: ...@@ -81,7 +81,7 @@ The :mod:`urllib.request` module defines the following functions:
* :meth:`~urllib.response.addinfourl.getcode` -- return the HTTP status code of the response. * :meth:`~urllib.response.addinfourl.getcode` -- return the HTTP status code of the response.
Raises :exc:`URLError` on errors. Raises :exc:`~urllib.error.URLError` on errors.
Note that ``None`` may be returned if no handler handles the request (though Note that ``None`` may be returned if no handler handles the request (though
the default installed global :class:`OpenerDirector` uses the default installed global :class:`OpenerDirector` uses
...@@ -144,14 +144,14 @@ The :mod:`urllib.request` module defines the following functions: ...@@ -144,14 +144,14 @@ The :mod:`urllib.request` module defines the following functions:
Convert the pathname *path* from the local syntax for a path to the form used in Convert the pathname *path* from the local syntax for a path to the form used in
the path component of a URL. This does not produce a complete URL. The return the path component of a URL. This does not produce a complete URL. The return
value will already be quoted using the :func:`quote` function. value will already be quoted using the :func:`~urllib.parse.quote` function.
.. function:: url2pathname(path) .. function:: url2pathname(path)
Convert the path component *path* from a percent-encoded URL to the local syntax for a Convert the path component *path* from a percent-encoded URL to the local syntax for a
path. This does not accept a complete URL. This function uses :func:`unquote` path. This does not accept a complete URL. This function uses
to decode *path*. :func:`~urllib.parse.unquote` to decode *path*.
.. function:: getproxies() .. function:: getproxies()
...@@ -240,7 +240,7 @@ The following classes are provided: ...@@ -240,7 +240,7 @@ The following classes are provided:
.. class:: HTTPDefaultErrorHandler() .. class:: HTTPDefaultErrorHandler()
A class which defines a default handler for HTTP error responses; all responses A class which defines a default handler for HTTP error responses; all responses
are turned into :exc:`HTTPError` exceptions. are turned into :exc:`~urllib.error.HTTPError` exceptions.
.. class:: HTTPRedirectHandler() .. class:: HTTPRedirectHandler()
...@@ -614,8 +614,8 @@ sorting the handler instances. ...@@ -614,8 +614,8 @@ sorting the handler instances.
#. Handlers with a method named like :meth:`protocol_open` are called to handle #. Handlers with a method named like :meth:`protocol_open` are called to handle
the request. This stage ends when a handler either returns a non-\ :const:`None` the request. This stage ends when a handler either returns a non-\ :const:`None`
value (ie. a response), or raises an exception (usually :exc:`URLError`). value (ie. a response), or raises an exception (usually
Exceptions are allowed to propagate. :exc:`~urllib.error.URLError`). Exceptions are allowed to propagate.
In fact, the above algorithm is first tried for methods named In fact, the above algorithm is first tried for methods named
:meth:`default_open`. If all such methods return :const:`None`, the algorithm :meth:`default_open`. If all such methods return :const:`None`, the algorithm
...@@ -674,8 +674,9 @@ The following attribute and methods should only be used by classes derived from ...@@ -674,8 +674,9 @@ The following attribute and methods should only be used by classes derived from
This method, if implemented, will be called by the parent This method, if implemented, will be called by the parent
:class:`OpenerDirector`. It should return a file-like object as described in :class:`OpenerDirector`. It should return a file-like object as described in
the return value of the :meth:`open` of :class:`OpenerDirector`, or ``None``. the return value of the :meth:`open` of :class:`OpenerDirector`, or ``None``.
It should raise :exc:`URLError`, unless a truly exceptional thing happens (for It should raise :exc:`~urllib.error.URLError`, unless a truly exceptional
example, :exc:`MemoryError` should not be mapped to :exc:`URLError`). thing happens (for example, :exc:`MemoryError` should not be mapped to
:exc:`URLError`).
This method will be called before any protocol-specific open method. This method will be called before any protocol-specific open method.
...@@ -761,8 +762,8 @@ HTTPRedirectHandler Objects ...@@ -761,8 +762,8 @@ HTTPRedirectHandler Objects
.. note:: .. note::
Some HTTP redirections require action from this module's client code. If this Some HTTP redirections require action from this module's client code. If this
is the case, :exc:`HTTPError` is raised. See :rfc:`2616` for details of the is the case, :exc:`~urllib.error.HTTPError` is raised. See :rfc:`2616` for
precise meanings of the various redirection codes. details of the precise meanings of the various redirection codes.
An :class:`HTTPError` exception raised as a security consideration if the An :class:`HTTPError` exception raised as a security consideration if the
HTTPRedirectHandler is presented with a redirected url which is not an HTTP, HTTPRedirectHandler is presented with a redirected url which is not an HTTP,
...@@ -775,9 +776,9 @@ HTTPRedirectHandler Objects ...@@ -775,9 +776,9 @@ HTTPRedirectHandler Objects
by the default implementations of the :meth:`http_error_30\*` methods when a by the default implementations of the :meth:`http_error_30\*` methods when a
redirection is received from the server. If a redirection should take place, redirection is received from the server. If a redirection should take place,
return a new :class:`Request` to allow :meth:`http_error_30\*` to perform the return a new :class:`Request` to allow :meth:`http_error_30\*` to perform the
redirect to *newurl*. Otherwise, raise :exc:`HTTPError` if no other handler redirect to *newurl*. Otherwise, raise :exc:`~urllib.error.HTTPError` if
should try to handle this URL, or return ``None`` if you can't but another no other handler should try to handle this URL, or return ``None`` if you
handler might. can't but another handler might.
.. note:: .. note::
...@@ -979,7 +980,7 @@ FileHandler Objects ...@@ -979,7 +980,7 @@ FileHandler Objects
.. versionchanged:: 3.2 .. versionchanged:: 3.2
This method is applicable only for local hostnames. When a remote This method is applicable only for local hostnames. When a remote
hostname is given, an :exc:`URLError` is raised. hostname is given, an :exc:`~urllib.error.URLError` is raised.
.. _ftp-handler-objects: .. _ftp-handler-objects:
...@@ -1021,7 +1022,7 @@ UnknownHandler Objects ...@@ -1021,7 +1022,7 @@ UnknownHandler Objects
.. method:: UnknownHandler.unknown_open() .. method:: UnknownHandler.unknown_open()
Raise a :exc:`URLError` exception. Raise a :exc:`~urllib.error.URLError` exception.
.. _http-error-processor-objects: .. _http-error-processor-objects:
...@@ -1038,7 +1039,7 @@ HTTPErrorProcessor Objects ...@@ -1038,7 +1039,7 @@ HTTPErrorProcessor Objects
For non-200 error codes, this simply passes the job on to the For non-200 error codes, this simply passes the job on to the
:meth:`protocol_error_code` handler methods, via :meth:`OpenerDirector.error`. :meth:`protocol_error_code` handler methods, via :meth:`OpenerDirector.error`.
Eventually, :class:`HTTPDefaultErrorHandler` will raise an Eventually, :class:`HTTPDefaultErrorHandler` will raise an
:exc:`HTTPError` if no other handler handles the error. :exc:`~urllib.error.HTTPError` if no other handler handles the error.
.. method:: HTTPErrorProcessor.https_response() .. method:: HTTPErrorProcessor.https_response()
...@@ -1251,7 +1252,7 @@ some point in the future. ...@@ -1251,7 +1252,7 @@ some point in the future.
argument may be given to specify a ``POST`` request (normally the request argument may be given to specify a ``POST`` request (normally the request
type is ``GET``). The *data* argument must be a bytes object in standard type is ``GET``). The *data* argument must be a bytes object in standard
:mimetype:`application/x-www-form-urlencoded` format; see the :mimetype:`application/x-www-form-urlencoded` format; see the
:func:`urlencode` function below. :func:`urllib.parse.urlencode` function.
:func:`urlretrieve` will raise :exc:`ContentTooShortError` when it detects that :func:`urlretrieve` will raise :exc:`ContentTooShortError` when it detects that
the amount of data available was less than the expected amount (which is the the amount of data available was less than the expected amount (which is the
...@@ -1333,8 +1334,8 @@ some point in the future. ...@@ -1333,8 +1334,8 @@ some point in the future.
If the *url* uses the :file:`http:` scheme identifier, the optional *data* If the *url* uses the :file:`http:` scheme identifier, the optional *data*
argument may be given to specify a ``POST`` request (normally the request type argument may be given to specify a ``POST`` request (normally the request type
is ``GET``). The *data* argument must in standard is ``GET``). The *data* argument must in standard
:mimetype:`application/x-www-form-urlencoded` format; see the :func:`urlencode` :mimetype:`application/x-www-form-urlencoded` format; see the
function below. :func:`urllib.parse.urlencode` function.
.. attribute:: version .. attribute:: version
......
:mod:`urllib` --- URL handling modules :mod:`urllib` --- URL handling modules
====================================== ======================================
.. module:: urllib
``urllib`` is a package that collects several modules for working with URLs: ``urllib`` is a package that collects several modules for working with URLs:
* :mod:`urllib.request` for opening and reading URLs * :mod:`urllib.request` for opening and reading URLs
......
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