summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2011-04-13 20:46:05 (GMT)
committerR David Murray <rdmurray@bitdance.com>2011-04-13 20:46:05 (GMT)
commitb35c850a3f7e2e6d470bb9543b9ba83aa33047f7 (patch)
tree9d7c221e58a8585d0721cc8498ef98d24c3dc269 /Lib/test/test_email
parentf400ab40e4eb7dc6ad886920fb02ce4f7d1e929f (diff)
downloadcpython-b35c850a3f7e2e6d470bb9543b9ba83aa33047f7.zip
cpython-b35c850a3f7e2e6d470bb9543b9ba83aa33047f7.tar.gz
cpython-b35c850a3f7e2e6d470bb9543b9ba83aa33047f7.tar.bz2
#11684: Complete parser bytes interface by adding BytesHeaderParser
Patch by Steffen Daode Nurpmeso.
Diffstat (limited to 'Lib/test/test_email')
-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 404282b..632e0a9 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -177,6 +177,17 @@ class TestMessageAPI(TestEmailBase):
gen.flatten(msg, False)
self.assertEqual(out.getvalue(), msgdata)
+ def test_byte_message_rfc822_only(self):
+ # Make sure new bytes header parser also passes this.
+ with openfile('msg_46.txt', 'rb') as fp:
+ msgdata = fp.read()
+ parser = email.parser.BytesHeaderParser()
+ msg = parser.parsebytes(msgdata)
+ out = BytesIO()
+ gen = email.generator.BytesGenerator(out)
+ gen.flatten(msg)
+ self.assertEqual(out.getvalue(), msgdata)
+
def test_get_decoded_payload(self):
eq = self.assertEqual
msg = self._msgobj('msg_10.txt')
@@ -2749,6 +2760,7 @@ Do you like this message?
class TestParsers(TestEmailBase):
+
def test_header_parser(self):
eq = self.assertEqual
# Parse only the headers of a complex multipart MIME document
@@ -2760,6 +2772,18 @@ class TestParsers(TestEmailBase):
self.assertFalse(msg.is_multipart())
self.assertTrue(isinstance(msg.get_payload(), str))
+ def test_bytes_header_parser(self):
+ eq = self.assertEqual
+ # Parse only the headers of a complex multipart MIME document
+ with openfile('msg_02.txt', 'rb') as fp:
+ msg = email.parser.BytesHeaderParser().parse(fp)
+ eq(msg['from'], 'ppp-request@zzz.org')
+ eq(msg['to'], 'ppp@zzz.org')
+ eq(msg.get_content_type(), 'multipart/mixed')
+ self.assertFalse(msg.is_multipart())
+ self.assertTrue(isinstance(msg.get_payload(), str))
+ self.assertTrue(isinstance(msg.get_payload(decode=True), bytes))
+
def test_whitespace_continuation(self):
eq = self.assertEqual
# This message contains a line after the Subject: header that has only