summaryrefslogtreecommitdiffstats
path: root/Lib/email/encoders.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2011-03-15 16:24:47 (GMT)
committerR David Murray <rdmurray@bitdance.com>2011-03-15 16:24:47 (GMT)
commitdf1d00a1e3d5ec1ee994ab0b002b974f22a6eaa4 (patch)
tree86857c1aad72537a81ce1a1a4439071523d51dd1 /Lib/email/encoders.py
parent2ef76981a0753db6373d8ba0194c345b6356a16f (diff)
parent56a9d7e3daff45f5fef206ea42398b4a0505fb47 (diff)
downloadcpython-df1d00a1e3d5ec1ee994ab0b002b974f22a6eaa4.zip
cpython-df1d00a1e3d5ec1ee994ab0b002b974f22a6eaa4.tar.gz
cpython-df1d00a1e3d5ec1ee994ab0b002b974f22a6eaa4.tar.bz2
Merge #11554 test_email_codecs activation from 3.2.
Diffstat (limited to 'Lib/email/encoders.py')
-rw-r--r--Lib/email/encoders.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/email/encoders.py b/Lib/email/encoders.py
index 0ea441d..c66f4cc 100644
--- a/Lib/email/encoders.py
+++ b/Lib/email/encoders.py
@@ -54,10 +54,13 @@ def encode_7or8bit(msg):
# There's no payload. For backwards compatibility we use 7bit
msg['Content-Transfer-Encoding'] = '7bit'
return
- # We play a trick to make this go fast. If encoding to ASCII succeeds, we
- # know the data must be 7bit, otherwise treat it as 8bit.
+ # We play a trick to make this go fast. If encoding/decode to ASCII
+ # succeeds, we know the data must be 7bit, otherwise treat it as 8bit.
try:
- orig.encode('ascii')
+ if isinstance(orig, str):
+ orig.encode('ascii')
+ else:
+ orig.decode('ascii')
except UnicodeError:
# iso-2022-* is non-ASCII but still 7-bit
charset = msg.get_charset()