summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-12-13 02:40:20 (GMT)
committerR David Murray <rdmurray@bitdance.com>2013-12-13 02:40:20 (GMT)
commit775632ba107fb37dfe2d38a39e129f1daad070cf (patch)
treed7dbab56a10db1d7870c140cfcf3adbeb06430d1 /Lib/email
parentcd0cb8ccd376186f08fd3ee2be0085f45f66b3d3 (diff)
downloadcpython-775632ba107fb37dfe2d38a39e129f1daad070cf.zip
cpython-775632ba107fb37dfe2d38a39e129f1daad070cf.tar.gz
cpython-775632ba107fb37dfe2d38a39e129f1daad070cf.tar.bz2
#19957: Simplify encode_7or8bit now that _payload is always str.
Patch by Vajrasky Kok, test enhancement by me.
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/encoders.py17
1 files changed, 4 insertions, 13 deletions
diff --git a/Lib/email/encoders.py b/Lib/email/encoders.py
index f9657f0..0a66acb 100644
--- a/Lib/email/encoders.py
+++ b/Lib/email/encoders.py
@@ -54,21 +54,12 @@ 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/decode 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 decoding from ASCII succeeds,
+ # we know the data must be 7bit, otherwise treat it as 8bit.
try:
- if isinstance(orig, str):
- orig.encode('ascii')
- else:
- orig.decode('ascii')
+ orig.decode('ascii')
except UnicodeError:
- charset = msg.get_charset()
- output_cset = charset and charset.output_charset
- # iso-2022-* is non-ASCII but encodes to a 7-bit representation
- if output_cset and output_cset.lower().startswith('iso-2022-'):
- msg['Content-Transfer-Encoding'] = '7bit'
- else:
- msg['Content-Transfer-Encoding'] = '8bit'
+ msg['Content-Transfer-Encoding'] = '8bit'
else:
msg['Content-Transfer-Encoding'] = '7bit'