diff options
| author | Benjamin Peterson <benjamin@python.org> | 2011-03-15 19:45:20 (GMT) |
|---|---|---|
| committer | Benjamin Peterson <benjamin@python.org> | 2011-03-15 19:45:20 (GMT) |
| commit | e97a5b2bda0b1b0352137e564a93e0176b6619e5 (patch) | |
| tree | 364c998e611d1347d960263d6b539a02fad526cc /Lib/email/charset.py | |
| parent | d6afe724cb8a701d6ad2adeb1d8d20e4fde6fca0 (diff) | |
| parent | ffdbbcaf715323f653388966eec5c42bf6b139c5 (diff) | |
| download | cpython-e97a5b2bda0b1b0352137e564a93e0176b6619e5.zip cpython-e97a5b2bda0b1b0352137e564a93e0176b6619e5.tar.gz cpython-e97a5b2bda0b1b0352137e564a93e0176b6619e5.tar.bz2 | |
merge heads
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 |
