diff options
author | R David Murray <rdmurray@bitdance.com> | 2011-03-15 16:20:02 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2011-03-15 16:20:02 (GMT) |
commit | 56a9d7e3daff45f5fef206ea42398b4a0505fb47 (patch) | |
tree | 42f16713454d229e7b90122bb350eae90ca4550b /Lib/email/encoders.py | |
parent | de3909da6b8d09b7bcb142994ebd6daba61a23d3 (diff) | |
download | cpython-56a9d7e3daff45f5fef206ea42398b4a0505fb47.zip cpython-56a9d7e3daff45f5fef206ea42398b4a0505fb47.tar.gz cpython-56a9d7e3daff45f5fef206ea42398b4a0505fb47.tar.bz2 |
#11554: reactivate test_email_codecs, and make it pass.
The fix is to charset.py, which was not doing the encoding to the
correct output character set when doing a body_encode for either
the shift-jis or euc-jp charsets. There's also a fix for handling
a bytes input in encoders.py.
Patch by Michael Henry, comment changes by me.
Diffstat (limited to 'Lib/email/encoders.py')
-rw-r--r-- | Lib/email/encoders.py | 9 |
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() |