[Python-checkins] cpython (merge 3.4 -> default): Merge: #23040: Clarify treatment of encoding and errors when component is bytes.

r.david.murray python-checkins at python.org
Thu Dec 25 03:24:20 CET 2014


https://hg.python.org/cpython/rev/367ba031a743
changeset:   93963:367ba031a743
parent:      93961:61daa699692b
parent:      93962:126aff7c6a33
user:        R David Murray <rdmurray at bitdance.com>
date:        Wed Dec 24 21:24:07 2014 -0500
summary:
  Merge: #23040: Clarify treatment of encoding and errors when component is bytes.

files:
  Doc/library/urllib.parse.rst |  7 ++++---
  Lib/urllib/parse.py          |  9 +++++----
  2 files changed, 9 insertions(+), 7 deletions(-)


diff --git a/Doc/library/urllib.parse.rst b/Doc/library/urllib.parse.rst
--- a/Doc/library/urllib.parse.rst
+++ b/Doc/library/urllib.parse.rst
@@ -522,7 +522,7 @@
 .. 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 "percent-encoded"
+   contain :class:`str` or :class:`bytes` objects, to a "percent-encoded"
    string.  If the resultant string is to be used as a *data* for POST
    operation with :func:`~urllib.request.urlopen` function, then it should be
    properly encoded to bytes, otherwise it would result in a :exc:`TypeError`.
@@ -537,8 +537,9 @@
    the value sequence for the key.  The order of parameters in the encoded
    string will match the order of parameter tuples in the sequence.
 
-   When *query* parameter is a :class:`str`, the *safe*, *encoding* and *error*
-   parameters are passed down to :func:`quote_plus` for encoding.
+   The *safe*, *encoding*, and *errors* parameters are passed down to
+   :func:`quote_plus` (the *encoding* and *errors* parameters are only passed
+   when a query element is a :class:`str`).
 
    To reverse this encoding process, :func:`parse_qs` and :func:`parse_qsl` are
    provided in this module to parse query strings into Python data structures.
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
--- a/Lib/urllib/parse.py
+++ b/Lib/urllib/parse.py
@@ -687,8 +687,8 @@
     called on a path where the existing slash characters are used as
     reserved characters.
 
-    string and safe may be either str or bytes objects. encoding must
-    not be specified if string is a str.
+    string and safe may be either str or bytes objects. encoding and errors
+    must not be specified if string is a bytes object.
 
     The optional encoding and errors parameters specify how to deal with
     non-ASCII characters, as accepted by the str.encode method.
@@ -760,8 +760,9 @@
     input.
 
     The components of a query arg may each be either a string or a bytes type.
-    When a component is a string, the safe, encoding and error parameters are
-    sent to the quote_plus function for encoding.
+
+    The safe, encoding, and errors parameters are passed down to quote_plus()
+    (encoding and errors only if a component is a str).
     """
 
     if hasattr(query, "items"):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list