diff options
author | Senthil Kumaran <orsenthil@gmail.com> | 2010-07-03 17:48:22 (GMT) |
---|---|---|
committer | Senthil Kumaran <orsenthil@gmail.com> | 2010-07-03 17:48:22 (GMT) |
commit | df022da3d87311e44213ea2e5f95cc6667d44d83 (patch) | |
tree | ca5dd75016520ee58d30a095dd6ca4ce5084eb05 /Doc/library | |
parent | 85029334f6b6a8ce6131a4e91ccdb5bec76ec7af (diff) | |
download | cpython-df022da3d87311e44213ea2e5f95cc6667d44d83.zip cpython-df022da3d87311e44213ea2e5f95cc6667d44d83.tar.gz cpython-df022da3d87311e44213ea2e5f95cc6667d44d83.tar.bz2 |
Fix Issue5468 - urlencode to handle bytes and other alternate encodings.
(Extensive tests provided). Patch by Dan Mahn.
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/urllib.parse.rst | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/Doc/library/urllib.parse.rst b/Doc/library/urllib.parse.rst index 3d13efc..add07a5 100644 --- a/Doc/library/urllib.parse.rst +++ b/Doc/library/urllib.parse.rst @@ -310,23 +310,29 @@ The :mod:`urllib.parse` module defines the following functions: ``b'a&\xef'``. -.. function:: urlencode(query, doseq=False) - - 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. +.. function:: urlencode(query, doseq=False, safe='', encoding=None, errors=None) + + Convert a mapping object or a sequence of two-element tuples, which may + either be a :class:`str` or a :class:`bytes`, 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:: |