summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2003-03-07 22:46:41 (GMT)
committerBarry Warsaw <barry@python.org>2003-03-07 22:46:41 (GMT)
commit8e1e7f5468f972891446f3caa078b85a1c920ccb (patch)
tree0c44b385519c86e1f3b56e2711696042e2145943 /Lib/email
parent21fcc4e28776921176ef971ace4fc93008e98c1f (diff)
downloadcpython-8e1e7f5468f972891446f3caa078b85a1c920ccb.zip
cpython-8e1e7f5468f972891446f3caa078b85a1c920ccb.tar.gz
cpython-8e1e7f5468f972891446f3caa078b85a1c920ccb.tar.bz2
decode_rfc2231(): RFC 2231 allows leaving out both the charset and
language without including any single quotes.
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/Utils.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/email/Utils.py b/Lib/email/Utils.py
index 4b5394d..28b4459 100644
--- a/Lib/email/Utils.py
+++ b/Lib/email/Utils.py
@@ -280,9 +280,11 @@ def unquote(str):
def decode_rfc2231(s):
"""Decode string according to RFC 2231"""
import urllib
- charset, language, s = s.split("'", 2)
- s = urllib.unquote(s)
- return charset, language, s
+ parts = s.split("'", 2)
+ if len(parts) == 1:
+ return None, None, s
+ charset, language, s = parts
+ return charset, language, urllib.unquote(s)
def encode_rfc2231(s, charset=None, language=None):
@@ -335,6 +337,6 @@ def decode_params(params):
for num, continuation in continuations:
value.append(continuation)
charset, language, value = decode_rfc2231(EMPTYSTRING.join(value))
- new_params.append((name,
- (charset, language, '"%s"' % quote(value))))
+ new_params.append(
+ (name, (charset, language, '"%s"' % quote(value))))
return new_params