Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a236b0

Browse files
committed
Add section for urllib.parse.
1 parent a3b7a14 commit 9a236b0

2 files changed

Lines changed: 52 additions & 9 deletions

File tree

Doc/library/urllib.parse.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,9 @@ or on combining URL components into a URL string.
279279
object.
280280

281281
.. versionchanged:: 3.2
282-
Result is a structured object rather than a simple 2-tuple
282+
Result is a structured object rather than a simple 2-tuple.
283283

284+
:: _parsing-ascii-encoded-bytes:
284285

285286
Parsing ASCII Encoded Bytes
286287
---------------------------

Doc/whatsnew/3.2.rst

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,14 +1839,56 @@ reading directly from dictionaries and strings.
18391839

18401840
(All changes contributed by Łukasz Langa.)
18411841

1842-
.. XXX: Mention urllib.parse changes
1843-
Issue 9873 (Nick Coghlan):
1844-
- ASCII byte sequence support in URL parsing
1845-
- named tuple for urldefrag return value
1846-
Issue 5468 (Dan Mahn) for urlencode:
1847-
- bytes input support
1848-
- non-UTF8 percent encoding of non-ASCII characters
1849-
Issue 2987 for IPv6 (RFC2732) support in urlparse
1842+
urllib.parse
1843+
------------
1844+
1845+
A number of usability improvements were made for the :mod:`urllib.parse` module.
1846+
1847+
The :func:`~urllib.parse.urlparse` function now supports `IPv6
1848+
<http://en.wikipedia.org/wiki/IPv6>`_ addresses as described in :rfc:`2732`:
1849+
1850+
>>> import urllib.parse
1851+
>>> urllib.parse.urlparse('http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]/foo/')
1852+
ParseResult(scheme='http',
1853+
netloc='[dead:beef:cafe:5417:affe:8FA3:deaf:feed]',
1854+
path='/foo/',
1855+
params='',
1856+
query='',
1857+
fragment='')
1858+
1859+
The :func:`~urllib.parse.urldefrag` function now returns a :term:`named tuple`::
1860+
1861+
>>> r = urllib.parse.urldefrag('http://python.org/about/#target')
1862+
>>> r
1863+
DefragResult(url='http://python.org/about/', fragment='target')
1864+
>>> r[0]
1865+
'http://python.org/about/
1866+
>>> r.fragment
1867+
'target'
1868+
1869+
And, the :func:`~urllib.parse.urlencode` function is now much more flexible,
1870+
accepting either a string or bytes type for the *query* argument. If it is a
1871+
string, then the *safe*, *encoding*, and *error* parameters are sent to
1872+
:func:`~urllib.parse.quote_plus` for encoding::
1873+
1874+
>>> urllib.parse.urlencode([
1875+
('type', 'telenovela'),
1876+
('name', '¿Dónde Está Elisa?')],
1877+
encoding='latin-1')
1878+
'type=telenovela&name=%BFD%F3nde+Est%E1+Elisa%3F'
1879+
1880+
As detailed in :ref:`parsing-ascii-encoded-bytes` , all the :mod:`urllib.parse`
1881+
functions now accept ASCII-encoded byte strings as input, so long as they are
1882+
not mixed with regular strings. If ASCII-encoded byte strings are given as
1883+
parameters, the return types will also be an ASCII-encoded byte strings:
1884+
1885+
>>> urllib.parse.urlparse(b'http://www.python.org:80/about/')
1886+
ParseResultBytes(scheme=b'http', netloc=b'www.python.org:80',
1887+
path=b'/about/', params=b'', query=b'', fragment=b'')
1888+
1889+
(Work by Nick Coghlan, Dan Mahn, and Senthil Kumaran in :issue:`2987`,
1890+
:issue:`5468`, and :issue:`9873`.)
1891+
18501892

18511893
Multi-threading
18521894
===============

0 commit comments

Comments
 (0)