diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-02-11 15:54:22 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-02-11 15:54:22 (GMT) |
commit | 64634eb32112c84b858ba58729e7c7246affad34 (patch) | |
tree | da274d94f4994824cc5be10affcc4a65f6152546 /Lib/test/test_email | |
parent | a6e902ae35179349b24702f9eb3eb37fb31481b8 (diff) | |
parent | 66383b2e0a47cebf31586a1038e85d37c9aefadc (diff) | |
download | cpython-64634eb32112c84b858ba58729e7c7246affad34.zip cpython-64634eb32112c84b858ba58729e7c7246affad34.tar.gz cpython-64634eb32112c84b858ba58729e7c7246affad34.tar.bz2 |
Merge: #17171: fix email.encoders.encode_7or8bit when applied to binary data.
Diffstat (limited to 'Lib/test/test_email')
-rw-r--r-- | Lib/test/test_email/test_email.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index 54f7214..593d27b 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -1440,7 +1440,24 @@ class TestMIMEApplication(unittest.TestCase): eq(msg.get_payload().strip(), '+vv8/f7/') eq(msg.get_payload(decode=True), bytesdata) - def test_body_with_encode_noop(self): + def test_binary_body_with_encode_7or8bit(self): + # Issue 17171. + bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff' + msg = MIMEApplication(bytesdata, _encoder=encoders.encode_7or8bit) + # Treated as a string, this will be invalid code points. + self.assertEqual(msg.get_payload(), '\uFFFD' * len(bytesdata)) + self.assertEqual(msg.get_payload(decode=True), bytesdata) + self.assertEqual(msg['Content-Transfer-Encoding'], '8bit') + s = BytesIO() + g = BytesGenerator(s) + g.flatten(msg) + wireform = s.getvalue() + msg2 = email.message_from_bytes(wireform) + self.assertEqual(msg.get_payload(), '\uFFFD' * len(bytesdata)) + self.assertEqual(msg2.get_payload(decode=True), bytesdata) + self.assertEqual(msg2['Content-Transfer-Encoding'], '8bit') + + def test_binary_body_with_encode_noop(self): # Issue 16564: This does not produce an RFC valid message, since to be # valid it should have a CTE of binary. But the below works in # Python2, and is documented as working this way. |