summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-08-21 21:10:31 -0400
committerR David Murray <rdmurray@bitdance.com>2013-08-21 21:10:31 -0400
commit9b75a095ea1b53a609aee5162914821b06e0008e (patch)
tree83d017cb275668996e13e878f94f338e7f89f389 /Lib/test
parentac38ecdbb2b5663a98044c53998baebf02673597 (diff)
downloadcpython-9b75a095ea1b53a609aee5162914821b06e0008e.tar.gz
#18324: set_payload now correctly handles binary input.
This also backs out the previous fixes for for #14360, #1717, and #16564. Those bugs were actually caused by the fact that set_payload didn't decode to str, thus rendering the model inconsistent. This fix does mean the data processed by the encoder functions goes through an extra encode/decode cycle, but it means the model is always consistent. Future API updates will provide a better way to encode payloads, which will bypass this minor de-optimization. Tests by Vajrasky Kok.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_email/test_email.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index 56be794a0a..e11194b5b8 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -593,6 +593,42 @@ class TestMessageAPI(TestEmailBase):
"attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.ppt",
msg['Content-Disposition'])
+ def test_binary_quopri_payload(self):
+ for charset in ('latin-1', 'ascii'):
+ msg = Message()
+ msg['content-type'] = 'text/plain; charset=%s' % charset
+ msg['content-transfer-encoding'] = 'quoted-printable'
+ msg.set_payload(b'foo=e6=96=87bar')
+ self.assertEqual(
+ msg.get_payload(decode=True),
+ b'foo\xe6\x96\x87bar',
+ 'get_payload returns wrong result with charset %s.' % charset)
+
+ def test_binary_base64_payload(self):
+ for charset in ('latin-1', 'ascii'):
+ msg = Message()
+ msg['content-type'] = 'text/plain; charset=%s' % charset
+ msg['content-transfer-encoding'] = 'base64'
+ msg.set_payload(b'Zm9v5paHYmFy')
+ self.assertEqual(
+ msg.get_payload(decode=True),
+ b'foo\xe6\x96\x87bar',
+ 'get_payload returns wrong result with charset %s.' % charset)
+
+ def test_binary_uuencode_payload(self):
+ for charset in ('latin-1', 'ascii'):
+ for encoding in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
+ msg = Message()
+ msg['content-type'] = 'text/plain; charset=%s' % charset
+ msg['content-transfer-encoding'] = encoding
+ msg.set_payload(b"begin 666 -\n)9F]OYI:'8F%R\n \nend\n")
+ self.assertEqual(
+ msg.get_payload(decode=True),
+ b'foo\xe6\x96\x87bar',
+ str(('get_payload returns wrong result ',
+ 'with charset {0} and encoding {1}.')).\
+ format(charset, encoding))
+
def test_add_header_with_name_only_param(self):
msg = Message()
msg.add_header('Content-Disposition', 'inline', foo_bar=None)