diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-06-27 18:37:00 -0400 |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-06-27 18:37:00 -0400 |
commit | d2a859909950af91a7e1c4821bae305c61fa426d (patch) | |
tree | b0ae3c9bc4884dcd51c37d49ad64d59dd598fc16 /Lib/email/encoders.py | |
parent | bf291877c868ad93dc0f4b7a50f5186e2e80191f (diff) | |
download | cpython-d2a859909950af91a7e1c4821bae305c61fa426d.tar.gz |
#14360: make encoders.encode_quopri work.
There were no tests for the encoders module. encode_base64 worked
because it is the default and so got tested implicitly elsewhere, and
we use encode_7or8bit internally, so that worked, too. I previously
fixed encode_noop, so this fix means that everythign in the encoders
module now works, hopefully correctly. Also added an explicit test
for encode_base64.
Diffstat (limited to 'Lib/email/encoders.py')
-rw-r--r-- | Lib/email/encoders.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/email/encoders.py b/Lib/email/encoders.py index 82a28cf344..a0d062a20c 100644 --- a/Lib/email/encoders.py +++ b/Lib/email/encoders.py @@ -20,7 +20,7 @@ from quopri import encodestring as _encodestring def _qencode(s): enc = _encodestring(s, quotetabs=True) # Must encode spaces, which quopri.encodestring() doesn't do - return enc.replace(' ', '=20') + return enc.replace(b' ', b'=20') def encode_base64(msg): @@ -41,8 +41,12 @@ def encode_quopri(msg): Also, add an appropriate Content-Transfer-Encoding header. """ orig = msg.get_payload() + if isinstance(orig, str): + # If it is a string, the model data may have binary data encoded in via + # surrogateescape. Convert back to bytes so we can CTE encode it. + orig = orig.encode('ascii', 'surrogateescape') encdata = _qencode(orig) - msg.set_payload(encdata) + msg.set_payload(encdata.decode('ascii', 'surrogateescape')) msg['Content-Transfer-Encoding'] = 'quoted-printable' |