summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2001-12-03 19:26:40 (GMT)
committerBarry Warsaw <barry@python.org>2001-12-03 19:26:40 (GMT)
commitc44d2c52c96e9a88cd368942f0d43d70e6ed64bf (patch)
tree6f177c75b53c231f9bdef6c170dd85597eb3cc29
parentbe5234610af367f00c23c01e44ea165fbfc64b98 (diff)
downloadcpython-c44d2c52c96e9a88cd368942f0d43d70e6ed64bf.zip
cpython-c44d2c52c96e9a88cd368942f0d43d70e6ed64bf.tar.gz
cpython-c44d2c52c96e9a88cd368942f0d43d70e6ed64bf.tar.bz2
decode(), encode(): Accepting the minor optimizations from SF patch
#486375, but not the rest of it, since that changes the documented semantics of encode().
-rw-r--r--Lib/email/Utils.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/email/Utils.py b/Lib/email/Utils.py
index b86091b..3d48287 100644
--- a/Lib/email/Utils.py
+++ b/Lib/email/Utils.py
@@ -75,14 +75,14 @@ def decode(s):
# The first element is any non-encoded leading text
rtn.append(parts[0])
charset = parts[1]
- encoding = parts[2]
+ encoding = parts[2].lower()
atom = parts[3]
# The next chunk to decode should be in parts[4]
parts = ecre.split(parts[4])
# The encoding must be either `q' or `b', case-insensitive
- if encoding.lower() == 'q':
+ if encoding == 'q':
func = _qdecode
- elif encoding.lower() == 'b':
+ elif encoding == 'b':
func = _bdecode
else:
func = _identity
@@ -96,13 +96,14 @@ def decode(s):
def encode(s, charset='iso-8859-1', encoding='q'):
"""Encode a string according to RFC 2047."""
- if encoding.lower() == 'q':
+ encoding = encoding.lower()
+ if encoding == 'q':
estr = _qencode(s)
- elif encoding.lower() == 'b':
+ elif encoding == 'b':
estr = _bencode(s)
else:
raise ValueError, 'Illegal encoding code: ' + encoding
- return '=?%s?%s?%s?=' % (charset.lower(), encoding.lower(), estr)
+ return '=?%s?%s?%s?=' % (charset.lower(), encoding, estr)