summaryrefslogtreecommitdiffstats
path: root/Lib/email/test/test_email.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-02-09 18:02:58 (GMT)
committerR David Murray <rdmurray@bitdance.com>2013-02-09 18:02:58 (GMT)
commitceaa8b1d7557cf1550c16f8ae11ee9b118ef9a93 (patch)
tree0d40360708d62f6941b0d2865c7eecdaf1d7a12b /Lib/email/test/test_email.py
parentd489c7a0a3936cd4bbb746e6c3eac36bff38d74b (diff)
downloadcpython-ceaa8b1d7557cf1550c16f8ae11ee9b118ef9a93.zip
cpython-ceaa8b1d7557cf1550c16f8ae11ee9b118ef9a93.tar.gz
cpython-ceaa8b1d7557cf1550c16f8ae11ee9b118ef9a93.tar.bz2
#16564: Fix regression in use of encoders.encode_noop with binary data.
Diffstat (limited to 'Lib/email/test/test_email.py')
-rw-r--r--Lib/email/test/test_email.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
index 2fa4aa8..e66a410 100644
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -1438,6 +1438,22 @@ 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):
+ # 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.
+ bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff'
+ msg = MIMEApplication(bytesdata, _encoder=encoders.encode_noop)
+ # 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)
+ 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)
# Test the basic MIMEText class