summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-02-09 18:10:54 (GMT)
committerR David Murray <rdmurray@bitdance.com>2013-02-09 18:10:54 (GMT)
commit6cb1d67eb3bd235e1d49eeb602f15f3d40a5e228 (patch)
treeac855e8de48da9928d9754b419991157be0d9cdb /Lib/test/test_email
parent7d01a1eb2b636891fcac90f48290293bc2b9f3eb (diff)
parentceaa8b1d7557cf1550c16f8ae11ee9b118ef9a93 (diff)
downloadcpython-6cb1d67eb3bd235e1d49eeb602f15f3d40a5e228.zip
cpython-6cb1d67eb3bd235e1d49eeb602f15f3d40a5e228.tar.gz
cpython-6cb1d67eb3bd235e1d49eeb602f15f3d40a5e228.tar.bz2
Merge: #16564: Fix regression in use of encoders.encode_noop with binary data.
Diffstat (limited to 'Lib/test/test_email')
-rw-r--r--Lib/test/test_email/test_email.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index da7cb53..54f7214 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -1440,6 +1440,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