[Python-checkins] cpython (2.7): #17171: backport behavior-confirming test from python3.

r.david.murray python-checkins at python.org
Mon Feb 11 17:20:04 CET 2013


http://hg.python.org/cpython/rev/e44fa71d76fe
changeset:   82165:e44fa71d76fe
branch:      2.7
parent:      82161:1c2dbed859ca
user:        R David Murray <rdmurray at bitdance.com>
date:        Mon Feb 11 10:57:37 2013 -0500
summary:
  #17171: backport behavior-confirming test from python3.

files:
  Lib/email/test/test_email_renamed.py |  19 +++++++++++++++-
  1 files changed, 18 insertions(+), 1 deletions(-)


diff --git a/Lib/email/test/test_email_renamed.py b/Lib/email/test/test_email_renamed.py
--- a/Lib/email/test/test_email_renamed.py
+++ b/Lib/email/test/test_email_renamed.py
@@ -994,7 +994,24 @@
         eq(msg.get_payload(), '+vv8/f7/')
         eq(msg.get_payload(decode=True), bytes)
 
-    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(), bytesdata)
+        self.assertEqual(msg.get_payload(decode=True), bytesdata)
+        self.assertEqual(msg['Content-Transfer-Encoding'], '8bit')
+        s = StringIO()
+        g = Generator(s)
+        g.flatten(msg)
+        wireform = s.getvalue()
+        msg2 = email.message_from_string(wireform)
+        self.assertEqual(msg.get_payload(), 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, and is
         # documented as working this way.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list