Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
email.test.test_email.TestParsers Class Reference
Inheritance diagram for email.test.test_email.TestParsers:
Inheritance graph
[legend]
Collaboration diagram for email.test.test_email.TestParsers:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_header_parser
def test_whitespace_continuation
def test_whitespace_continuation_last_header
def test_crlf_separation
def test_crlf_flatten
def test_multipart_digest_with_extra_mime_headers
def test_three_lines
def test_strip_line_feed_and_carriage_return_in_headers
def test_rfc2822_header_syntax
def test_rfc2822_space_not_allowed_in_header
def test_rfc2822_one_character_header
def test_CRLFLF_at_end_of_part
def ndiffAssertEqual

Static Public Attributes

 maxDiff = None

Detailed Description

Definition at line 2892 of file test_email.py.


Member Function Documentation

def email.test.test_email.TestEmailBase.ndiffAssertEqual (   self,
  first,
  second 
) [inherited]
Like assertEqual except use ndiff for readable output.

Definition at line 57 of file test_email.py.

00057 
00058     def ndiffAssertEqual(self, first, second):
00059         """Like assertEqual except use ndiff for readable output."""
00060         if first != second:
00061             sfirst = str(first)
00062             ssecond = str(second)
00063             rfirst = [repr(line) for line in sfirst.splitlines()]
00064             rsecond = [repr(line) for line in ssecond.splitlines()]
00065             diff = difflib.ndiff(rfirst, rsecond)
00066             raise self.failureException(NL + NL.join(diff))

Here is the call graph for this function:

Definition at line 2951 of file test_email.py.

02951 
02952     def test_crlf_flatten(self):
02953         # Using newline='\n' preserves the crlfs in this input file.
02954         with openfile('msg_26.txt', newline='\n') as fp:
02955             text = fp.read()
02956         msg = email.message_from_string(text)
02957         s = StringIO()
02958         g = Generator(s)
02959         g.flatten(msg, linesep='\r\n')
02960         self.assertEqual(s.getvalue(), text)

Here is the call graph for this function:

Definition at line 2940 of file test_email.py.

02940 
02941     def test_crlf_separation(self):
02942         eq = self.assertEqual
02943         with openfile('msg_26.txt', newline='\n') as fp:
02944             msg = Parser().parse(fp)
02945         eq(len(msg.get_payload()), 2)
02946         part1 = msg.get_payload(0)
02947         eq(part1.get_content_type(), 'text/plain')
02948         eq(part1.get_payload(), 'Simple email with attachment.\r\n\r\n')
02949         part2 = msg.get_payload(1)
02950         eq(part2.get_content_type(), 'application/riscos')

Here is the call graph for this function:

Definition at line 3036 of file test_email.py.

03036 
03037     def test_CRLFLF_at_end_of_part(self):
03038         # issue 5610: feedparser should not eat two chars from body part ending
03039         # with "\r\n\n".
03040         m = (
03041             "From: foo@bar.com\n"
03042             "To: baz\n"
03043             "Mime-Version: 1.0\n"
03044             "Content-Type: multipart/mixed; boundary=BOUNDARY\n"
03045             "\n"
03046             "--BOUNDARY\n"
03047             "Content-Type: text/plain\n"
03048             "\n"
03049             "body ending with CRLF newline\r\n"
03050             "\n"
03051             "--BOUNDARY--\n"
03052           )
03053         msg = email.message_from_string(m)
03054         self.assertTrue(msg.get_payload(0).get_payload().endswith('\r\n'))
03055 

Here is the call graph for this function:

Definition at line 2893 of file test_email.py.

02893 
02894     def test_header_parser(self):
02895         eq = self.assertEqual
02896         # Parse only the headers of a complex multipart MIME document
02897         with openfile('msg_02.txt') as fp:
02898             msg = HeaderParser().parse(fp)
02899         eq(msg['from'], 'ppp-request@zzz.org')
02900         eq(msg['to'], 'ppp@zzz.org')
02901         eq(msg.get_content_type(), 'multipart/mixed')
02902         self.assertFalse(msg.is_multipart())
02903         self.assertTrue(isinstance(msg.get_payload(), str))

Here is the call graph for this function:

Definition at line 2963 of file test_email.py.

02963 
02964     def test_multipart_digest_with_extra_mime_headers(self):
02965         eq = self.assertEqual
02966         neq = self.ndiffAssertEqual
02967         with openfile('msg_28.txt') as fp:
02968             msg = email.message_from_file(fp)
02969         # Structure is:
02970         # multipart/digest
02971         #   message/rfc822
02972         #     text/plain
02973         #   message/rfc822
02974         #     text/plain
02975         eq(msg.is_multipart(), 1)
02976         eq(len(msg.get_payload()), 2)
02977         part1 = msg.get_payload(0)
02978         eq(part1.get_content_type(), 'message/rfc822')
02979         eq(part1.is_multipart(), 1)
02980         eq(len(part1.get_payload()), 1)
02981         part1a = part1.get_payload(0)
02982         eq(part1a.is_multipart(), 0)
02983         eq(part1a.get_content_type(), 'text/plain')
02984         neq(part1a.get_payload(), 'message 1\n')
02985         # next message/rfc822
02986         part2 = msg.get_payload(1)
02987         eq(part2.get_content_type(), 'message/rfc822')
02988         eq(part2.is_multipart(), 1)
02989         eq(len(part2.get_payload()), 1)
02990         part2a = part2.get_payload(0)
02991         eq(part2a.is_multipart(), 0)
02992         eq(part2a.get_content_type(), 'text/plain')
02993         neq(part2a.get_payload(), 'message 2\n')

Here is the call graph for this function:

Definition at line 3013 of file test_email.py.

03013 
03014     def test_rfc2822_header_syntax(self):
03015         eq = self.assertEqual
03016         m = '>From: foo\nFrom: bar\n!"#QUX;~: zoo\n\nbody'
03017         msg = email.message_from_string(m)
03018         eq(len(msg), 3)
03019         eq(sorted(field for field in msg), ['!"#QUX;~', '>From', 'From'])
03020         eq(msg.get_payload(), 'body')

Here is the call graph for this function:

Definition at line 3027 of file test_email.py.

03027 
03028     def test_rfc2822_one_character_header(self):
03029         eq = self.assertEqual
03030         m = 'A: first header\nB: second header\nCC: third header\n\nbody'
03031         msg = email.message_from_string(m)
03032         headers = msg.keys()
03033         headers.sort()
03034         eq(headers, ['A', 'B', 'CC'])
03035         eq(msg.get_payload(), 'body')

Here is the call graph for this function:

Definition at line 3021 of file test_email.py.

03021 
03022     def test_rfc2822_space_not_allowed_in_header(self):
03023         eq = self.assertEqual
03024         m = '>From foo@example.com 11:25:53\nFrom: bar\n!"#QUX;~: zoo\n\nbody'
03025         msg = email.message_from_string(m)
03026         eq(len(msg.keys()), 0)

Here is the call graph for this function:

Definition at line 3002 of file test_email.py.

03002 
03003     def test_strip_line_feed_and_carriage_return_in_headers(self):
03004         eq = self.assertEqual
03005         # For [ 1002475 ] email message parser doesn't handle \r\n correctly
03006         value1 = 'text'
03007         value2 = 'more text'
03008         m = 'Header: %s\r\nNext-Header: %s\r\n\r\nBody\r\n\r\n' % (
03009             value1, value2)
03010         msg = email.message_from_string(m)
03011         eq(msg.get('Header'), value1)
03012         eq(msg.get('Next-Header'), value2)

Here is the call graph for this function:

Definition at line 2994 of file test_email.py.

02994 
02995     def test_three_lines(self):
02996         # A bug report by Andrew McNamara
02997         lines = ['From: Andrew Person <aperson@dom.ain',
02998                  'Subject: Test',
02999                  'Date: Tue, 20 Aug 2002 16:43:45 +1000']
03000         msg = email.message_from_string(NL.join(lines))
03001         self.assertEqual(msg['date'], 'Tue, 20 Aug 2002 16:43:45 +1000')

Here is the call graph for this function:

Definition at line 2904 of file test_email.py.

02904 
02905     def test_whitespace_continuation(self):
02906         eq = self.assertEqual
02907         # This message contains a line after the Subject: header that has only
02908         # whitespace, but it is not empty!
02909         msg = email.message_from_string("""\
02910 From: aperson@dom.ain
02911 To: bperson@dom.ain
02912 Subject: the next line has a space on it
02913 \x20
02914 Date: Mon, 8 Apr 2002 15:09:19 -0400
02915 Message-ID: spam
02916 
02917 Here's the message body
02918 """)
02919         eq(msg['subject'], 'the next line has a space on it\n ')
02920         eq(msg['message-id'], 'spam')
02921         eq(msg.get_payload(), "Here's the message body\n")

Here is the call graph for this function:

Definition at line 2922 of file test_email.py.

02922 
02923     def test_whitespace_continuation_last_header(self):
02924         eq = self.assertEqual
02925         # Like the previous test, but the subject line is the last
02926         # header.
02927         msg = email.message_from_string("""\
02928 From: aperson@dom.ain
02929 To: bperson@dom.ain
02930 Date: Mon, 8 Apr 2002 15:09:19 -0400
02931 Message-ID: spam
02932 Subject: the next line has a space on it
02933 \x20
02934 
02935 Here's the message body
02936 """)
02937         eq(msg['subject'], 'the next line has a space on it\n ')
02938         eq(msg['message-id'], 'spam')
02939         eq(msg.get_payload(), "Here's the message body\n")

Here is the call graph for this function:


Member Data Documentation

Definition at line 2961 of file test_email.py.


The documentation for this class was generated from the following file: