[3.12] gh-101100: Fix Sphinx warnings in howto/urllib2.rst and library/http.client.rst (GH-114060) (#114063)

(cherry picked from commit c2808431b3)
This commit is contained in:
Hugo van Kemenade 2024-01-14 23:14:08 +02:00 committed by GitHub
parent 2aea0e967a
commit cc11c76da7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 48 additions and 48 deletions

View file

@ -392,16 +392,16 @@ info and geturl
=============== ===============
The response returned by urlopen (or the :exc:`~urllib.error.HTTPError` instance) has two The response returned by urlopen (or the :exc:`~urllib.error.HTTPError` instance) has two
useful methods :meth:`info` and :meth:`geturl` and is defined in the module useful methods :meth:`!info` and :meth:`!geturl` and is defined in the module
:mod:`urllib.response`.. :mod:`urllib.response`.
**geturl** - this returns the real URL of the page fetched. This is useful * **geturl** - this returns the real URL of the page fetched. This is useful
because ``urlopen`` (or the opener object used) may have followed a because ``urlopen`` (or the opener object used) may have followed a
redirect. The URL of the page fetched may not be the same as the URL requested. redirect. The URL of the page fetched may not be the same as the URL requested.
**info** - this returns a dictionary-like object that describes the page * **info** - this returns a dictionary-like object that describes the page
fetched, particularly the headers sent by the server. It is currently an fetched, particularly the headers sent by the server. It is currently an
:class:`http.client.HTTPMessage` instance. :class:`http.client.HTTPMessage` instance.
Typical headers include 'Content-length', 'Content-type', and so on. See the Typical headers include 'Content-length', 'Content-type', and so on. See the
`Quick Reference to HTTP Headers <https://jkorpela.fi/http.html>`_ `Quick Reference to HTTP Headers <https://jkorpela.fi/http.html>`_
@ -507,7 +507,7 @@ than the URL you pass to .add_password() will also match. ::
In the above example we only supplied our ``HTTPBasicAuthHandler`` to In the above example we only supplied our ``HTTPBasicAuthHandler`` to
``build_opener``. By default openers have the handlers for normal situations ``build_opener``. By default openers have the handlers for normal situations
-- ``ProxyHandler`` (if a proxy setting such as an :envvar:`http_proxy` -- ``ProxyHandler`` (if a proxy setting such as an :envvar:`!http_proxy`
environment variable is set), ``UnknownHandler``, ``HTTPHandler``, environment variable is set), ``UnknownHandler``, ``HTTPHandler``,
``HTTPDefaultErrorHandler``, ``HTTPRedirectHandler``, ``FTPHandler``, ``HTTPDefaultErrorHandler``, ``HTTPRedirectHandler``, ``FTPHandler``,
``FileHandler``, ``DataHandler``, ``HTTPErrorProcessor``. ``FileHandler``, ``DataHandler``, ``HTTPErrorProcessor``.

View file

@ -92,7 +92,7 @@ The module provides the following classes:
.. versionchanged:: 3.4.3 .. versionchanged:: 3.4.3
This class now performs all the necessary certificate and hostname checks This class now performs all the necessary certificate and hostname checks
by default. To revert to the previous, unverified, behavior by default. To revert to the previous, unverified, behavior
:func:`ssl._create_unverified_context` can be passed to the *context* :func:`!ssl._create_unverified_context` can be passed to the *context*
parameter. parameter.
.. versionchanged:: 3.8 .. versionchanged:: 3.8
@ -103,7 +103,7 @@ The module provides the following classes:
.. versionchanged:: 3.10 .. versionchanged:: 3.10
This class now sends an ALPN extension with protocol indicator This class now sends an ALPN extension with protocol indicator
``http/1.1`` when no *context* is given. Custom *context* should set ``http/1.1`` when no *context* is given. Custom *context* should set
ALPN protocols with :meth:`~ssl.SSLContext.set_alpn_protocol`. ALPN protocols with :meth:`~ssl.SSLContext.set_alpn_protocols`.
.. versionchanged:: 3.12 .. versionchanged:: 3.12
The deprecated *key_file*, *cert_file* and *check_hostname* parameters The deprecated *key_file*, *cert_file* and *check_hostname* parameters
@ -124,7 +124,7 @@ This module provides the following function:
.. function:: parse_headers(fp) .. function:: parse_headers(fp)
Parse the headers from a file pointer *fp* representing a HTTP Parse the headers from a file pointer *fp* representing a HTTP
request/response. The file has to be a :class:`BufferedIOBase` reader request/response. The file has to be a :class:`~io.BufferedIOBase` reader
(i.e. not text) and must provide a valid :rfc:`2822` style header. (i.e. not text) and must provide a valid :rfc:`2822` style header.
This function returns an instance of :class:`http.client.HTTPMessage` This function returns an instance of :class:`http.client.HTTPMessage`
@ -416,7 +416,7 @@ HTTPConnection Objects
.. versionadded:: 3.7 .. versionadded:: 3.7
As an alternative to using the :meth:`request` method described above, you can As an alternative to using the :meth:`~HTTPConnection.request` method described above, you can
also send your request step by step, by using the four functions below. also send your request step by step, by using the four functions below.
@ -648,6 +648,8 @@ method attribute. Here is an example session that uses the ``PUT`` method::
HTTPMessage Objects HTTPMessage Objects
------------------- -------------------
.. class:: HTTPMessage(email.message.Message)
An :class:`http.client.HTTPMessage` instance holds the headers from an HTTP An :class:`http.client.HTTPMessage` instance holds the headers from an HTTP
response. It is implemented using the :class:`email.message.Message` class. response. It is implemented using the :class:`email.message.Message` class.

View file

@ -86,7 +86,7 @@ The :mod:`urllib.request` module defines the following functions:
:class:`UnknownHandler` to ensure this never happens). :class:`UnknownHandler` to ensure this never happens).
In addition, if proxy settings are detected (for example, when a ``*_proxy`` In addition, if proxy settings are detected (for example, when a ``*_proxy``
environment variable like :envvar:`http_proxy` is set), environment variable like :envvar:`!http_proxy` is set),
:class:`ProxyHandler` is default installed and makes sure the requests are :class:`ProxyHandler` is default installed and makes sure the requests are
handled through the proxy. handled through the proxy.
@ -121,7 +121,7 @@ The :mod:`urllib.request` module defines the following functions:
.. versionchanged:: 3.10 .. versionchanged:: 3.10
HTTPS connection now send an ALPN extension with protocol indicator HTTPS connection now send an ALPN extension with protocol indicator
``http/1.1`` when no *context* is given. Custom *context* should set ``http/1.1`` when no *context* is given. Custom *context* should set
ALPN protocols with :meth:`~ssl.SSLContext.set_alpn_protocol`. ALPN protocols with :meth:`~ssl.SSLContext.set_alpn_protocols`.
.. deprecated:: 3.6 .. deprecated:: 3.6
@ -629,25 +629,25 @@ OpenerDirector Objects
the actual HTTP code, for example :meth:`http_error_404` would handle HTTP the actual HTTP code, for example :meth:`http_error_404` would handle HTTP
404 errors. 404 errors.
* :meth:`<protocol>_open` --- signal that the handler knows how to open *protocol* * :meth:`!<protocol>_open` --- signal that the handler knows how to open *protocol*
URLs. URLs.
See |protocol_open|_ for more information. See |protocol_open|_ for more information.
* :meth:`http_error_\<type\>` --- signal that the handler knows how to handle HTTP * :meth:`!http_error_\<type\>` --- signal that the handler knows how to handle HTTP
errors with HTTP error code *type*. errors with HTTP error code *type*.
See |http_error_nnn|_ for more information. See |http_error_nnn|_ for more information.
* :meth:`<protocol>_error` --- signal that the handler knows how to handle errors * :meth:`!<protocol>_error` --- signal that the handler knows how to handle errors
from (non-\ ``http``) *protocol*. from (non-\ ``http``) *protocol*.
* :meth:`<protocol>_request` --- signal that the handler knows how to pre-process * :meth:`!<protocol>_request` --- signal that the handler knows how to pre-process
*protocol* requests. *protocol* requests.
See |protocol_request|_ for more information. See |protocol_request|_ for more information.
* :meth:`<protocol>_response` --- signal that the handler knows how to * :meth:`!<protocol>_response` --- signal that the handler knows how to
post-process *protocol* responses. post-process *protocol* responses.
See |protocol_response|_ for more information. See |protocol_response|_ for more information.
@ -674,7 +674,7 @@ OpenerDirector Objects
Handle an error of the given protocol. This will call the registered error Handle an error of the given protocol. This will call the registered error
handlers for the given protocol with the given arguments (which are protocol handlers for the given protocol with the given arguments (which are protocol
specific). The HTTP protocol is a special case which uses the HTTP response specific). The HTTP protocol is a special case which uses the HTTP response
code to determine the specific error handler; refer to the :meth:`http_error_\<type\>` code to determine the specific error handler; refer to the :meth:`!http_error_\<type\>`
methods of the handler classes. methods of the handler classes.
Return values and exceptions raised are the same as those of :func:`urlopen`. Return values and exceptions raised are the same as those of :func:`urlopen`.
@ -684,25 +684,25 @@ OpenerDirector objects open URLs in three stages:
The order in which these methods are called within each stage is determined by The order in which these methods are called within each stage is determined by
sorting the handler instances. sorting the handler instances.
#. Every handler with a method named like :meth:`<protocol>_request` has that #. Every handler with a method named like :meth:`!<protocol>_request` has that
method called to pre-process the request. method called to pre-process the request.
#. 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 value (ie. a response), or raises an exception (usually
:exc:`~urllib.error.URLError`). 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:`~BaseHandler.default_open`. If all such methods return :const:`None`, the algorithm
is repeated for methods named like :meth:`<protocol>_open`. If all such methods is repeated for methods named like :meth:`!<protocol>_open`. If all such methods
return :const:`None`, the algorithm is repeated for methods named return :const:`None`, the algorithm is repeated for methods named
:meth:`unknown_open`. :meth:`~BaseHandler.unknown_open`.
Note that the implementation of these methods may involve calls of the parent Note that the implementation of these methods may involve calls of the parent
:class:`OpenerDirector` instance's :meth:`~OpenerDirector.open` and :class:`OpenerDirector` instance's :meth:`~OpenerDirector.open` and
:meth:`~OpenerDirector.error` methods. :meth:`~OpenerDirector.error` methods.
#. Every handler with a method named like :meth:`<protocol>_response` has that #. Every handler with a method named like :meth:`!<protocol>_response` has that
method called to post-process the response. method called to post-process the response.
@ -751,7 +751,7 @@ The following attribute and methods should only be used by classes derived from
the return value of the :meth:`~OpenerDirector.open` method of :class:`OpenerDirector`, or ``None``. the return value of the :meth:`~OpenerDirector.open` method of :class:`OpenerDirector`, or ``None``.
It should raise :exc:`~urllib.error.URLError`, unless a truly exceptional It should raise :exc:`~urllib.error.URLError`, unless a truly exceptional
thing happens (for example, :exc:`MemoryError` should not be mapped to thing happens (for example, :exc:`MemoryError` should not be mapped to
:exc:`URLError`). :exc:`~urllib.error.URLError`).
This method will be called before any protocol-specific open method. This method will be called before any protocol-specific open method.
@ -764,7 +764,7 @@ The following attribute and methods should only be used by classes derived from
define it if they want to handle URLs with the given protocol. define it if they want to handle URLs with the given protocol.
This method, if defined, will be called by the parent :class:`OpenerDirector`. This method, if defined, will be called by the parent :class:`OpenerDirector`.
Return values should be the same as for :meth:`default_open`. Return values should be the same as for :meth:`~BaseHandler.default_open`.
.. method:: BaseHandler.unknown_open(req) .. method:: BaseHandler.unknown_open(req)
@ -804,7 +804,7 @@ The following attribute and methods should only be used by classes derived from
Subclasses should override this method to handle specific HTTP errors. Subclasses should override this method to handle specific HTTP errors.
Arguments, return values and exceptions raised should be the same as for Arguments, return values and exceptions raised should be the same as for
:meth:`http_error_default`. :meth:`~BaseHandler.http_error_default`.
.. _protocol_request: .. _protocol_request:
@ -844,7 +844,7 @@ HTTPRedirectHandler Objects
is the case, :exc:`~urllib.error.HTTPError` is raised. See :rfc:`2616` for is the case, :exc:`~urllib.error.HTTPError` is raised. See :rfc:`2616` for
details of the 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 :exc:`~urllib.error.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,
HTTPS or FTP URL. HTTPS or FTP URL.
@ -921,7 +921,7 @@ ProxyHandler Objects
.. method:: ProxyHandler.<protocol>_open(request) .. method:: ProxyHandler.<protocol>_open(request)
:noindex: :noindex:
The :class:`ProxyHandler` will have a method :meth:`<protocol>_open` for every The :class:`ProxyHandler` will have a method :meth:`!<protocol>_open` for every
*protocol* which has a proxy in the *proxies* dictionary given in the *protocol* which has a proxy in the *proxies* dictionary given in the
constructor. The method will modify requests to go through the proxy, by constructor. The method will modify requests to go through the proxy, by
calling ``request.set_proxy()``, and call the next handler in the chain to calling ``request.set_proxy()``, and call the next handler in the chain to
@ -1177,7 +1177,7 @@ HTTPErrorProcessor Objects
For 200 error codes, the response object is returned immediately. For 200 error codes, the response object is returned immediately.
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:`http_error_\<type\>` handler methods, via :meth:`OpenerDirector.error`. :meth:`!http_error_\<type\>` handler methods, via :meth:`OpenerDirector.error`.
Eventually, :class:`HTTPDefaultErrorHandler` will raise an Eventually, :class:`HTTPDefaultErrorHandler` will raise an
:exc:`~urllib.error.HTTPError` if no other handler handles the error. :exc:`~urllib.error.HTTPError` if no other handler handles the error.
@ -1284,7 +1284,7 @@ Use of Basic HTTP Authentication::
:func:`build_opener` provides many handlers by default, including a :func:`build_opener` provides many handlers by default, including a
:class:`ProxyHandler`. By default, :class:`ProxyHandler` uses the environment :class:`ProxyHandler`. By default, :class:`ProxyHandler` uses the environment
variables named ``<scheme>_proxy``, where ``<scheme>`` is the URL scheme variables named ``<scheme>_proxy``, where ``<scheme>`` is the URL scheme
involved. For example, the :envvar:`http_proxy` environment variable is read to involved. For example, the :envvar:`!http_proxy` environment variable is read to
obtain the HTTP proxy's URL. obtain the HTTP proxy's URL.
This example replaces the default :class:`ProxyHandler` with one that uses This example replaces the default :class:`ProxyHandler` with one that uses
@ -1379,7 +1379,7 @@ some point in the future.
points to a local file, the object will not be copied unless filename is supplied. points to a local file, the object will not be copied unless filename is supplied.
Return a tuple ``(filename, headers)`` where *filename* is the Return a tuple ``(filename, headers)`` where *filename* is the
local file name under which the object can be found, and *headers* is whatever local file name under which the object can be found, and *headers* is whatever
the :meth:`info` method of the object returned by :func:`urlopen` returned (for the :meth:`!info` method of the object returned by :func:`urlopen` returned (for
a remote object). Exceptions are the same as for :func:`urlopen`. a remote object). Exceptions are the same as for :func:`urlopen`.
The second argument, if present, specifies the file location to copy to (if The second argument, if present, specifies the file location to copy to (if
@ -1404,7 +1404,7 @@ some point in the future.
:mimetype:`application/x-www-form-urlencoded` format; see the :mimetype:`application/x-www-form-urlencoded` format; see the
:func:`urllib.parse.urlencode` function. :func:`urllib.parse.urlencode` function.
:func:`urlretrieve` will raise :exc:`ContentTooShortError` when it detects that :func:`urlretrieve` will raise :exc:`~urllib.error.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
size reported by a *Content-Length* header). This can occur, for example, when size reported by a *Content-Length* header). This can occur, for example, when
the download is interrupted. the download is interrupted.
@ -1413,8 +1413,8 @@ some point in the future.
urlretrieve reads more data, but if less data is available, it raises the urlretrieve reads more data, but if less data is available, it raises the
exception. exception.
You can still retrieve the downloaded data in this case, it is stored in the You can still retrieve the downloaded data in this case, it is stored in the
:attr:`content` attribute of the exception instance. :attr:`!content` attribute of the exception instance.
If no *Content-Length* header was supplied, urlretrieve can not check the size If no *Content-Length* header was supplied, urlretrieve can not check the size
of the data it has downloaded, and just returns it. In this case you just have of the data it has downloaded, and just returns it. In this case you just have
@ -1508,7 +1508,7 @@ some point in the future.
authentication is performed. For the 30x response codes, recursion is bounded authentication is performed. For the 30x response codes, recursion is bounded
by the value of the *maxtries* attribute, which defaults to 10. by the value of the *maxtries* attribute, which defaults to 10.
For all other response codes, the method :meth:`http_error_default` is called For all other response codes, the method :meth:`~BaseHandler.http_error_default` is called
which you can override in subclasses to handle the error appropriately. which you can override in subclasses to handle the error appropriately.
.. note:: .. note::

View file

@ -25,7 +25,6 @@ Doc/glossary.rst
Doc/howto/descriptor.rst Doc/howto/descriptor.rst
Doc/howto/enum.rst Doc/howto/enum.rst
Doc/howto/logging.rst Doc/howto/logging.rst
Doc/howto/urllib2.rst
Doc/library/2to3.rst Doc/library/2to3.rst
Doc/library/aifc.rst Doc/library/aifc.rst
Doc/library/ast.rst Doc/library/ast.rst
@ -57,7 +56,6 @@ Doc/library/fcntl.rst
Doc/library/ftplib.rst Doc/library/ftplib.rst
Doc/library/functools.rst Doc/library/functools.rst
Doc/library/getopt.rst Doc/library/getopt.rst
Doc/library/http.client.rst
Doc/library/http.cookiejar.rst Doc/library/http.cookiejar.rst
Doc/library/http.server.rst Doc/library/http.server.rst
Doc/library/importlib.rst Doc/library/importlib.rst

View file

@ -1220,7 +1220,7 @@ class
Previously there was no way to check that without using private API. See the Previously there was no way to check that without using private API. See the
`relevant issue in python/typing `relevant issue in python/typing
<https://github.com/python/typing/issues/751>` <https://github.com/python/typing/issues/751>`_.
.. ..

View file

@ -584,8 +584,8 @@ Use the frame bound builtins when offering a name suggestion in
.. nonce: qtm-9T .. nonce: qtm-9T
.. section: Library .. section: Library
In :mod:`importlib._bootstrap`, enhance namespace package repr to `<module In :mod:`importlib._bootstrap`, enhance namespace package repr to ``<module
'x' (namespace) from ['path']>`. 'x' (namespace) from ['path']>``.
.. ..

View file

@ -2857,8 +2857,8 @@ Patch by Justin Blanchard.
Add formal support for UDPLITE sockets. Support was present before, but it Add formal support for UDPLITE sockets. Support was present before, but it
is now easier to detect support with ``hasattr(socket, 'IPPROTO_UDPLITE')`` is now easier to detect support with ``hasattr(socket, 'IPPROTO_UDPLITE')``
and there are constants defined for each of the values needed: and there are constants defined for each of the values needed:
:py:obj:`socket.IPPROTO_UDPLITE`, :py:obj:`UDPLITE_SEND_CSCOV`, and ``socket.IPPROTO_UDPLITE``, ``UDPLITE_SEND_CSCOV``, and
:py:obj:`UDPLITE_RECV_CSCOV`. Patch by Gabe Appleton. ``UDPLITE_RECV_CSCOV``. Patch by Gabe Appleton.
.. ..

View file

@ -112,8 +112,8 @@ Port :mod:`syslog` to multiphase initialization (:pep:`489`).
Reporting a specialised error message for invalid string prefixes, which was Reporting a specialised error message for invalid string prefixes, which was
introduced in :issue:`40246`, is being reverted due to backwards introduced in :issue:`40246`, is being reverted due to backwards
compatibility concerns for strings that immediately follow a reserved compatibility concerns for strings that immediately follow a reserved
keyword without whitespace between them. Constructs like `bg="#d00" if clear keyword without whitespace between them. Constructs like ``bg="#d00" if clear
else"#fca"` were failing to parse, which is not an acceptable breakage on else"#fca"`` were failing to parse, which is not an acceptable breakage on
such short notice. such short notice.
.. ..