Skip to content

Commit f9f934a

Browse files
committed
fix-Sphinx-reference-warnings-in-urllib.{parse,request}.rst
1 parent fcda96f commit f9f934a

2 files changed

Lines changed: 152 additions & 55 deletions

File tree

Doc/library/urllib.parse.rst

Lines changed: 120 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ or on combining URL components into a URL string.
125125

126126
If the *allow_fragments* argument is false, fragment identifiers are not
127127
recognized. Instead, they are parsed as part of the path
128-
or query component, and :attr:`fragment` is set to ``None`` or the empty
128+
or query component, and :attr:`fragment <SplitResult.fragment>` is set to
129+
``None`` or the empty
129130
string (depending on the value of *missing_as_none*) in the return value.
130131

131132
The return value is a :term:`named tuple`, which means that its items can
@@ -134,37 +135,40 @@ or on combining URL components into a URL string.
134135
+------------------+-------+-------------------------+-------------------------------+
135136
| Attribute | Index | Value | Value if not present |
136137
+==================+=======+=========================+===============================+
137-
| :attr:`scheme` | 0 | URL scheme specifier | *scheme* parameter or |
138+
| |split-scheme| | 0 | URL scheme specifier | *scheme* parameter or |
138139
| | | | empty string [1]_ |
139140
+------------------+-------+-------------------------+-------------------------------+
140-
| :attr:`netloc` | 1 | Network location part | ``None`` or empty string [1]_ |
141+
| |split-netloc| | 1 | Network location part | ``None`` or empty string [1]_ |
141142
+------------------+-------+-------------------------+-------------------------------+
142-
| :attr:`path` | 2 | Hierarchical path | empty string |
143+
| |split-path| | 2 | Hierarchical path | empty string |
143144
+------------------+-------+-------------------------+-------------------------------+
144-
| :attr:`query` | 3 | Query component | ``None`` or empty string [1]_ |
145+
| |split-query| | 3 | Query component | ``None`` or empty string [1]_ |
145146
+------------------+-------+-------------------------+-------------------------------+
146-
| :attr:`fragment` | 4 | Fragment identifier | ``None`` or empty string [1]_ |
147+
| |split-frag| | 4 | Fragment identifier | ``None`` or empty string [1]_ |
147148
+------------------+-------+-------------------------+-------------------------------+
148-
| :attr:`username` | | User name | ``None`` |
149+
| |split-username| | | User name | ``None`` |
149150
+------------------+-------+-------------------------+-------------------------------+
150-
| :attr:`password` | | Password | ``None`` |
151+
| |split-password| | | Password | ``None`` |
151152
+------------------+-------+-------------------------+-------------------------------+
152-
| :attr:`hostname` | | Host name (lower case) | ``None`` |
153+
| |split-hostname| | | Host name (lower case) | ``None`` |
153154
+------------------+-------+-------------------------+-------------------------------+
154-
| :attr:`port` | | Port number as integer, | ``None`` |
155+
| |split-port| | | Port number as integer, | ``None`` |
155156
| | | if present | |
156157
+------------------+-------+-------------------------+-------------------------------+
157158

158159
.. [1] Depending on the value of the *missing_as_none* argument.
159160
160-
Reading the :attr:`port` attribute will raise a :exc:`ValueError` if
161+
Reading the :attr:`port <SplitResult.port>` attribute will raise a
162+
:exc:`ValueError` if
161163
an invalid port is specified in the URL. See section
162164
:ref:`urlparse-result-object` for more information on the result object.
163165

164-
Unmatched square brackets in the :attr:`netloc` attribute will raise a
166+
Unmatched square brackets in the :attr:`netloc <SplitResult.netloc>`
167+
attribute will raise a
165168
:exc:`ValueError`.
166169

167-
Characters in the :attr:`netloc` attribute that decompose under NFKC
170+
Characters in the :attr:`netloc <SplitResult.netloc>` attribute that
171+
decompose under NFKC
168172
normalization (as used by the IDNA encoding) into any of ``/``, ``?``,
169173
``#``, ``@``, or ``:`` will raise a :exc:`ValueError`. If the URL is
170174
decomposed before parsing, no error will be raised.
@@ -174,8 +178,10 @@ or on combining URL components into a URL string.
174178
``\r`` and tab ``\t`` characters are removed from the URL at any position.
175179

176180
As is the case with all named tuples, the subclass has a few additional methods
177-
and attributes that are particularly useful. One such method is :meth:`_replace`.
178-
The :meth:`_replace` method will return a new :class:`SplitResult` object
181+
and attributes that are particularly useful. One such method is
182+
:meth:`~SplitResult._replace`.
183+
The :meth:`~SplitResult._replace` method will return a new
184+
:class:`SplitResult` object
179185
replacing specified fields with new values.
180186

181187
.. doctest::
@@ -431,9 +437,9 @@ or on combining URL components into a URL string.
431437
+------------------+-------+-------------------------+-------------------------------+
432438
| Attribute | Index | Value | Value if not present |
433439
+==================+=======+=========================+===============================+
434-
| :attr:`url` | 0 | URL with no fragment | empty string |
440+
| |defrag-url| | 0 | URL with no fragment | empty string |
435441
+------------------+-------+-------------------------+-------------------------------+
436-
| :attr:`fragment` | 1 | Fragment identifier | ``None`` or empty string [3]_ |
442+
| |defrag-frag| | 1 | Fragment identifier | ``None`` or empty string [3]_ |
437443
+------------------+-------+-------------------------+-------------------------------+
438444

439445
.. [3] Depending on the value of the *missing_as_none* argument.
@@ -506,14 +512,15 @@ byte values will trigger :exc:`UnicodeDecodeError`.
506512

507513
To support easier conversion of result objects between :class:`str` and
508514
:class:`bytes`, all return values from URL parsing functions provide
509-
either an :meth:`encode` method (when the result contains :class:`str`
510-
data) or a :meth:`decode` method (when the result contains :class:`bytes`
515+
either an :meth:`encode <DefragResult.encode>` method (when the result contains
516+
:class:`str` data) or a :meth:`decode <DefragResultBytes.decode>` method (when
517+
the result contains :class:`bytes`
511518
data). The signatures of these methods match those of the corresponding
512519
:class:`str` and :class:`bytes` methods (except that the default encoding
513520
is ``'ascii'`` rather than ``'utf-8'``). Each produces a value of a
514521
corresponding type that contains either :class:`bytes` data (for
515-
:meth:`encode` methods) or :class:`str` data (for
516-
:meth:`decode` methods).
522+
:meth:`encode <DefragResult.encode>` methods) or :class:`str` data (for
523+
:meth:`decode <DefragResultBytes.decode>` methods).
517524

518525
Applications that need to operate on potentially improperly quoted URLs
519526
that may contain non-ASCII data will need to do their own decoding from
@@ -537,7 +544,24 @@ The result objects from the :func:`urlsplit`, :func:`urlparse` and
537544
:func:`urldefrag` functions are subclasses of the :class:`tuple` type.
538545
These subclasses add the attributes listed in the documentation for
539546
those functions, the encoding and decoding support described in the
540-
previous section, as well as an additional method:
547+
previous section, as well as additional methods:
548+
549+
.. |split-scheme| replace:: :attr:`scheme <SplitResult.scheme>`
550+
.. |split-netloc| replace:: :attr:`netloc <SplitResult.netloc>`
551+
.. |split-path| replace:: :attr:`path <SplitResult.path>`
552+
.. |split-query| replace:: :attr:`query <SplitResult.query>`
553+
.. |split-frag| replace:: :attr:`fragment <SplitResult.fragment>`
554+
.. |split-username| replace:: :attr:`username <SplitResult.username>`
555+
.. |split-password| replace:: :attr:`password <SplitResult.password>`
556+
.. |split-hostname| replace:: :attr:`hostname <SplitResult.hostname>`
557+
.. |split-port| replace:: :attr:`port <SplitResult.port>`
558+
.. |defrag-url| replace:: :attr:`url <DefragResult.url>`
559+
.. |defrag-frag| replace:: :attr:`fragment <DefragResult.fragment>`
560+
561+
.. method:: SplitResult._replace(**kwargs)
562+
563+
Return a new structured parse result replacing specified fields with new
564+
values.
541565

542566
.. method:: urllib.parse.SplitResult.geturl()
543567

@@ -573,22 +597,75 @@ results when operating on :class:`str` objects:
573597
.. class:: DefragResult(url, fragment)
574598

575599
Concrete class for :func:`urldefrag` results containing :class:`str`
576-
data. The :meth:`encode` method returns a :class:`DefragResultBytes`
577-
instance.
600+
data.
601+
602+
.. attribute:: url
603+
604+
URL with no fragment.
605+
606+
.. attribute:: fragment
607+
608+
Fragment identifier.
609+
610+
.. method:: encode(encoding='ascii', errors='strict')
611+
612+
Return a :class:`DefragResultBytes` instance.
578613

579614
.. versionadded:: 3.2
580615

581616
.. class:: ParseResult(scheme, netloc, path, params, query, fragment)
582617

583618
Concrete class for :func:`urlparse` results containing :class:`str`
584-
data. The :meth:`encode` method returns a :class:`ParseResultBytes`
585-
instance.
619+
data.
620+
621+
.. method:: encode(encoding='ascii', errors='strict')
622+
623+
Return a :class:`ParseResultBytes` instance.
586624

587625
.. class:: SplitResult(scheme, netloc, path, query, fragment)
588626

589627
Concrete class for :func:`urlsplit` results containing :class:`str`
590-
data. The :meth:`encode` method returns a :class:`SplitResultBytes`
591-
instance.
628+
data.
629+
630+
.. attribute:: scheme
631+
632+
URL scheme specifier.
633+
634+
.. attribute:: netloc
635+
636+
Network location part.
637+
638+
.. attribute:: path
639+
640+
Hierarchical path.
641+
642+
.. attribute:: query
643+
644+
Query component.
645+
646+
.. attribute:: fragment
647+
648+
Fragment identifier.
649+
650+
.. attribute:: username
651+
652+
User name.
653+
654+
.. attribute:: password
655+
656+
Password.
657+
658+
.. attribute:: hostname
659+
660+
Host name, lower case.
661+
662+
.. attribute:: port
663+
664+
Port number as integer, if present.
665+
666+
.. method:: encode(encoding='ascii', errors='strict')
667+
668+
Return a :class:`SplitResultBytes` instance.
592669

593670

594671
The following classes provide the implementations of the parse results when
@@ -597,24 +674,33 @@ operating on :class:`bytes` or :class:`bytearray` objects:
597674
.. class:: DefragResultBytes(url, fragment)
598675

599676
Concrete class for :func:`urldefrag` results containing :class:`bytes`
600-
data. The :meth:`decode` method returns a :class:`DefragResult`
601-
instance.
677+
data.
678+
679+
.. method:: decode(encoding='ascii', errors='strict')
680+
681+
Return a :class:`DefragResult` instance.
602682

603683
.. versionadded:: 3.2
604684

605685
.. class:: ParseResultBytes(scheme, netloc, path, params, query, fragment)
606686

607687
Concrete class for :func:`urlparse` results containing :class:`bytes`
608-
data. The :meth:`decode` method returns a :class:`ParseResult`
609-
instance.
688+
data.
689+
690+
.. method:: decode(encoding='ascii', errors='strict')
691+
692+
Return a :class:`ParseResult` instance.
610693

611694
.. versionadded:: 3.2
612695

613696
.. class:: SplitResultBytes(scheme, netloc, path, query, fragment)
614697

615698
Concrete class for :func:`urlsplit` results containing :class:`bytes`
616-
data. The :meth:`decode` method returns a :class:`SplitResult`
617-
instance.
699+
data.
700+
701+
.. method:: decode(encoding='ascii', errors='strict')
702+
703+
Return a :class:`SplitResult` instance.
618704

619705
.. versionadded:: 3.2
620706

Doc/library/urllib.request.rst

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ The :mod:`!urllib.request` module defines the following functions:
138138
If the Python installation has SSL support (i.e., if the :mod:`ssl` module
139139
can be imported), :class:`HTTPSHandler` will also be added.
140140

141-
A :class:`BaseHandler` subclass may also change its :attr:`handler_order`
142-
attribute to modify its position in the handlers list.
141+
A :class:`BaseHandler` subclass may also change its
142+
:attr:`~BaseHandler.handler_order` attribute to modify its position in the
143+
handlers list.
143144

144145

145146
.. function:: pathname2url(path, *, add_scheme=False)
@@ -358,6 +359,11 @@ The following classes are provided:
358359

359360
To disable autodetected proxy pass an empty dictionary.
360361

362+
.. envvar:: no_proxy
363+
364+
A comma-separated list of hostname suffixes, optionally with ``:port``
365+
appended, which shouldn't be reached via proxy.
366+
361367
The :envvar:`no_proxy` environment variable can be used to specify hosts
362368
which shouldn't be reached via proxy; if set, it should be a comma-separated
363369
list of hostname suffixes, optionally with ``:port`` appended, for example
@@ -667,38 +673,38 @@ OpenerDirector Objects
667673
*handler* should be an instance of :class:`BaseHandler`. The following methods
668674
are searched, and added to the possible chains (note that HTTP errors are a
669675
special case). Note that, in the following, *protocol* should be replaced
670-
with the actual protocol to handle, for example :meth:`http_response` would
671-
be the HTTP protocol response handler. Also *type* should be replaced with
672-
the actual HTTP code, for example :meth:`http_error_404` would handle HTTP
673-
404 errors.
676+
with the actual protocol to handle, for example ``http_response`` would be
677+
the :ref:`protocol response handler <protocol_response>`. Also *type*
678+
should be replaced with the actual HTTP code, for example
679+
``http_error_404`` would handle HTTP 404 errors as described by the
680+
:ref:`HTTP error handler pattern <http_error_nnn>`.
674681

675-
* :meth:`!<protocol>_open` --- signal that the handler knows how to open *protocol*
676-
URLs.
682+
* ``<protocol>_open`` --- signal that the handler knows how to open
683+
*protocol* URLs.
677684

678-
See |protocol_open|_ for more information.
685+
See :ref:`the protocol open method pattern <protocol_open>` for more
686+
information.
679687

680-
* :meth:`!http_error_\<type\>` --- signal that the handler knows how to handle HTTP
688+
* ``http_error_<type>`` --- signal that the handler knows how to handle HTTP
681689
errors with HTTP error code *type*.
682690

683-
See |http_error_nnn|_ for more information.
691+
See :ref:`the HTTP error handler pattern <http_error_nnn>` for more
692+
information.
684693

685-
* :meth:`!<protocol>_error` --- signal that the handler knows how to handle errors
694+
* ``<protocol>_error`` --- signal that the handler knows how to handle errors
686695
from (non-\ ``http``) *protocol*.
687696

688-
* :meth:`!<protocol>_request` --- signal that the handler knows how to pre-process
697+
* ``<protocol>_request`` --- signal that the handler knows how to pre-process
689698
*protocol* requests.
690699

691-
See |protocol_request|_ for more information.
700+
See :ref:`the protocol request method pattern <protocol_request>` for more
701+
information.
692702

693-
* :meth:`!<protocol>_response` --- signal that the handler knows how to
703+
* ``<protocol>_response`` --- signal that the handler knows how to
694704
post-process *protocol* responses.
695705

696-
See |protocol_response|_ for more information.
697-
698-
.. |protocol_open| replace:: :meth:`BaseHandler.<protocol>_open`
699-
.. |http_error_nnn| replace:: :meth:`BaseHandler.http_error_\<nnn\>`
700-
.. |protocol_request| replace:: :meth:`BaseHandler.<protocol>_request`
701-
.. |protocol_response| replace:: :meth:`BaseHandler.<protocol>_response`
706+
See :ref:`the protocol response method pattern <protocol_response>` for
707+
more information.
702708

703709
.. method:: OpenerDirector.open(url, data=None[, timeout])
704710

@@ -784,6 +790,11 @@ The following attribute and methods should only be used by classes derived from
784790
protocol, or handle errors.
785791

786792

793+
.. attribute:: BaseHandler.handler_order
794+
795+
The order in which the handler is called within an opener chain.
796+
797+
787798
.. method:: BaseHandler.default_open(req)
788799

789800
This method is *not* defined in :class:`BaseHandler`, but subclasses should

0 commit comments

Comments
 (0)