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/charset.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/charset.py')
-rw-r--r-- | Lib/email/charset.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/email/charset.py b/Lib/email/charset.py index 24d5545..f22be2c 100644 --- a/Lib/email/charset.py +++ b/Lib/email/charset.py @@ -263,7 +263,7 @@ class Charset: Returns "quoted-printable" if self.body_encoding is QP. Returns "base64" if self.body_encoding is BASE64. - Returns "7bit" otherwise. + Returns conversion function otherwise. """ assert self.body_encoding != SHORTEST if self.body_encoding == QP: @@ -381,7 +381,10 @@ class Charset: """Body-encode a string by converting it first to bytes. The type of encoding (base64 or quoted-printable) will be based on - self.body_encoding. + self.body_encoding. If body_encoding is None, we assume the + output charset is a 7bit encoding, so re-encoding the decoded + string using the ascii codec produces the correct string version + of the content. """ # 7bit/8bit encodings return the string unchanged (module conversions) if self.body_encoding is BASE64: @@ -391,4 +394,6 @@ class Charset: elif self.body_encoding is QP: return email.quoprimime.body_encode(string) else: + if isinstance(string, str): + string = string.encode(self.output_charset).decode('ascii') return string |