summaryrefslogtreecommitdiffstats
path: root/Lib/email/utils.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2008-08-18 21:44:30 (GMT)
committerGuido van Rossum <guido@python.org>2008-08-18 21:44:30 (GMT)
commit52dbbb906804f36067ecbc8c89a00cdab545bdb2 (patch)
tree1b923b821dc0547f6fa3e30401c7dac177a8f557 /Lib/email/utils.py
parent4171da5c9d899dc64cb15f177f05b9de05563148 (diff)
downloadcpython-52dbbb906804f36067ecbc8c89a00cdab545bdb2.zip
cpython-52dbbb906804f36067ecbc8c89a00cdab545bdb2.tar.gz
cpython-52dbbb906804f36067ecbc8c89a00cdab545bdb2.tar.bz2
- Issue #3300: make urllib.parse.[un]quote() default to UTF-8.
Code contributed by Matt Giuca. quote() now encodes the input before quoting, unquote() decodes after unquoting. There are new arguments to change the encoding and errors settings. There are also new APIs to skip the encode/decode steps. [un]quote_plus() are also affected.
Diffstat (limited to 'Lib/email/utils.py')
-rw-r--r--Lib/email/utils.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/email/utils.py b/Lib/email/utils.py
index e1d21f6..35275f6 100644
--- a/Lib/email/utils.py
+++ b/Lib/email/utils.py
@@ -219,7 +219,7 @@ def encode_rfc2231(s, charset=None, language=None):
charset is given but not language, the string is encoded using the empty
string for language.
"""
- s = urllib.parse.quote(s, safe='')
+ s = urllib.parse.quote(s, safe='', encoding=charset or 'ascii')
if charset is None and language is None:
return s
if language is None:
@@ -271,7 +271,10 @@ def decode_params(params):
# language specifiers at the beginning of the string.
for num, s, encoded in continuations:
if encoded:
- s = urllib.parse.unquote(s)
+ # Decode as "latin-1", so the characters in s directly
+ # represent the percent-encoded octet values.
+ # collapse_rfc2231_value treats this as an octet sequence.
+ s = urllib.parse.unquote(s, encoding="latin-1")
extended = True
value.append(s)
value = quote(EMPTYSTRING.join(value))