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/encoders.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/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() |
