summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-03-14 18:24:22 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-03-14 18:24:22 (GMT)
commit8d8f11049265f4e53b2d97f5caa73c4ca0ee7875 (patch)
tree9e5f681a88bd3b4c905f424a87ea03406a05f38a /Lib/test
parent9d8c18665004755d87ba891a822265199a160609 (diff)
parent9fd170e2d053bd86592b8728bdd00cf2d2a06d0b (diff)
downloadcpython-8d8f11049265f4e53b2d97f5caa73c4ca0ee7875.zip
cpython-8d8f11049265f4e53b2d97f5caa73c4ca0ee7875.tar.gz
cpython-8d8f11049265f4e53b2d97f5caa73c4ca0ee7875.tar.bz2
#14062: fix BytesParser handling of Header objects
This is a different fix than the 3.2 fix, but the new tests are the same. This also affected smtplib.SMTP.send_message, which calls BytesParser.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_email/test_email.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index a4d39ab..1f354c2 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -3601,6 +3601,30 @@ class Test8BitBytesHandling(unittest.TestCase):
g.flatten(msg)
self.assertEqual(s.getvalue(), source)
+ def test_bytes_generator_b_encoding_linesep(self):
+ # Issue 14062: b encoding was tacking on an extra \n.
+ m = Message()
+ # This has enough non-ascii that it should always end up b encoded.
+ m['Subject'] = Header('žluťoučký kůň')
+ s = BytesIO()
+ g = email.generator.BytesGenerator(s)
+ g.flatten(m, linesep='\r\n')
+ self.assertEqual(
+ s.getvalue(),
+ b'Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=\r\n\r\n')
+
+ def test_generator_b_encoding_linesep(self):
+ # Since this broke in ByteGenerator, test Generator for completeness.
+ m = Message()
+ # This has enough non-ascii that it should always end up b encoded.
+ m['Subject'] = Header('žluťoučký kůň')
+ s = StringIO()
+ g = email.generator.Generator(s)
+ g.flatten(m, linesep='\r\n')
+ self.assertEqual(
+ s.getvalue(),
+ 'Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=\r\n\r\n')
+
def test_crlf_control_via_policy(self):
# msg_26 is crlf terminated
with openfile('msg_26.txt', 'rb') as fp: