mirror of
https://github.com/python/cpython.git
synced 2025-10-27 08:46:53 +00:00
Merged revisions 82510 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r82510 | senthil.kumaran | 2010-07-03 23:18:22 +0530 (Sat, 03 Jul 2010) | 4 lines Fix Issue5468 - urlencode to handle bytes and other alternate encodings. (Extensive tests provided). Patch by Dan Mahn. ........
This commit is contained in:
parent
8e42fb7ada
commit
fe1ad15b4b
4 changed files with 165 additions and 24 deletions
|
|
@ -307,23 +307,29 @@ The :mod:`urllib.parse` module defines the following functions:
|
|||
``b'a&\xef'``.
|
||||
|
||||
|
||||
.. function:: urlencode(query, doseq=False)
|
||||
.. function:: urlencode(query, doseq=False, safe='', encoding=None, errors=None)
|
||||
|
||||
Convert a mapping object or a sequence of two-element tuples to a
|
||||
"url-encoded" string, suitable to pass to :func:`urlopen` above as the
|
||||
optional *data* argument. This is useful to pass a dictionary of form
|
||||
fields to a ``POST`` request. The resulting string is a series of
|
||||
``key=value`` pairs separated by ``'&'`` characters, where both *key* and
|
||||
*value* are quoted using :func:`quote_plus` above. When a sequence of
|
||||
two-element tuples is used as the *query* argument, the first element of
|
||||
each tuple is a key and the second is a value. The value element in itself
|
||||
can be a sequence and in that case, if the optional parameter *doseq* is
|
||||
evaluates to *True*, individual ``key=value`` pairs separated by ``'&'``are
|
||||
generated for each element of the value sequence for the key. The order of
|
||||
parameters in the encoded string will match the order of parameter tuples in
|
||||
the sequence. This module provides the functions :func:`parse_qs` and
|
||||
:func:`parse_qsl` which are used to parse query strings into Python data
|
||||
structures.
|
||||
Convert a mapping object or a sequence of two-element, which may either be a
|
||||
:class:`str` or a :class:`bytes` tuples, to a "url-encoded" string,
|
||||
suitable to pass to :func:`urlopen` above as the optional *data* argument.
|
||||
This is useful to pass a dictionary of form fields to a ``POST`` request.
|
||||
The resulting string is a series of ``key=value`` pairs separated by ``'&'``
|
||||
characters, where both *key* and *value* are quoted using :func:`quote_plus`
|
||||
above. When a sequence of two-element tuples is used as the *query*
|
||||
argument, the first element of each tuple is a key and the second is a
|
||||
value. The value element in itself can be a sequence and in that case, if
|
||||
the optional parameter *doseq* is evaluates to *True*, individual
|
||||
``key=value`` pairs separated by ``'&'`` are generated for each element of
|
||||
the value sequence for the key. The order of parameters in the encoded
|
||||
string will match the order of parameter tuples in the sequence. This module
|
||||
provides the functions :func:`parse_qs` and :func:`parse_qsl` which are used
|
||||
to parse query strings into Python data structures.
|
||||
|
||||
When *query* parameter is a :class:`str`, the *safe*, *encoding* and *error*
|
||||
parameters are sent the :func:`quote_plus` for encoding.
|
||||
|
||||
.. versionchanged:: 3.2
|
||||
query paramater supports bytes and string.
|
||||
|
||||
|
||||
.. seealso::
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue