Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(11)

Side by Side Diff: Lib/email/test/test_email_renamed.py

Issue 2407: [issue1974] Use space character as continuation_ws (Closed) SVN Base: http://svn.python.org/view/*checkout*/python/trunk/
Patch Set: Created 1 year, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (C) 2001-2007 Python Software Foundation 1 # Copyright (C) 2001-2007 Python Software Foundation
2 # Contact: email-sig@python.org 2 # Contact: email-sig@python.org
3 # email package unit tests 3 # email package unit tests
4 4
5 import os 5 import os
6 import sys 6 import sys
7 import time 7 import time
8 import base64 8 import base64
9 import difflib 9 import difflib
10 import unittest 10 import unittest
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 \t123456789112345678921234567893123456789412345678951234567896123456789712345678 98112345678911234567892123456789112345678911234567892123456789 528 \t123456789112345678921234567893123456789412345678951234567896123456789712345678 98112345678911234567892123456789112345678911234567892123456789
529 \tmore text 529 \tmore text
530 530
531 test 531 test
532 """) 532 """)
533 sfp = StringIO() 533 sfp = StringIO()
534 g = Generator(sfp) 534 g = Generator(sfp)
535 g.flatten(msg) 535 g.flatten(msg)
536 eq(sfp.getvalue(), """\ 536 eq(sfp.getvalue(), """\
537 Subject: bug demonstration 537 Subject: bug demonstration
538 \t123456789112345678921234567893123456789412345678951234567896123456789712345678 98112345678911234567892123456789112345678911234567892123456789 538 1234567891123456789212345678931234567894123456789512345678961234567897123456789 8112345678911234567892123456789112345678911234567892123456789
539 \tmore text 539 more text
540 540
541 test 541 test
542 """) 542 """)
543 543
544 def test_another_long_almost_unsplittable_header(self): 544 def test_another_long_almost_unsplittable_header(self):
545 eq = self.ndiffAssertEqual 545 eq = self.ndiffAssertEqual
546 hstr = """\ 546 hstr = """\
547 bug demonstration 547 bug demonstration
548 \t123456789112345678921234567893123456789412345678951234567896123456789712345678 98112345678911234567892123456789112345678911234567892123456789 548 \t123456789112345678921234567893123456789412345678951234567896123456789712345678 98112345678911234567892123456789112345678911234567892123456789
549 \tmore text""" 549 \tmore text"""
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 'wasnipoop; giraffes="very-long-necked-animals"; ' 629 'wasnipoop; giraffes="very-long-necked-animals"; '
630 'spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"') 630 'spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"')
631 sfp = StringIO() 631 sfp = StringIO()
632 g = Generator(sfp) 632 g = Generator(sfp)
633 g.flatten(msg) 633 g.flatten(msg)
634 eq(sfp.getvalue(), '''\ 634 eq(sfp.getvalue(), '''\
635 Content-Type: text/plain; charset="us-ascii" 635 Content-Type: text/plain; charset="us-ascii"
636 MIME-Version: 1.0 636 MIME-Version: 1.0
637 Content-Transfer-Encoding: 7bit 637 Content-Transfer-Encoding: 7bit
638 X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals"; 638 X-Foobar-Spoink-Defrobnit: wasnipoop; giraffes="very-long-necked-animals";
639 \tspooge="yummy"; hippos="gargantuan"; marshmallows="gooey" 639 spooge="yummy"; hippos="gargantuan"; marshmallows="gooey"
640 640
641 ''') 641 ''')
642 642
643 def test_no_semis_header_splitter(self): 643 def test_no_semis_header_splitter(self):
644 eq = self.ndiffAssertEqual 644 eq = self.ndiffAssertEqual
645 msg = Message() 645 msg = Message()
646 msg['From'] = 'test@dom.ain' 646 msg['From'] = 'test@dom.ain'
647 msg['References'] = SPACE.join(['<%d@dom.ain>' % i for i in range(10)]) 647 msg['References'] = SPACE.join(['<%d@dom.ain>' % i for i in range(10)])
648 msg.set_payload('Test') 648 msg.set_payload('Test')
649 sfp = StringIO() 649 sfp = StringIO()
650 g = Generator(sfp) 650 g = Generator(sfp)
651 g.flatten(msg) 651 g.flatten(msg)
652 eq(sfp.getvalue(), """\ 652 eq(sfp.getvalue(), """\
653 From: test@dom.ain 653 From: test@dom.ain
654 References: <0@dom.ain> <1@dom.ain> <2@dom.ain> <3@dom.ain> <4@dom.ain> 654 References: <0@dom.ain> <1@dom.ain> <2@dom.ain> <3@dom.ain> <4@dom.ain>
655 \t<5@dom.ain> <6@dom.ain> <7@dom.ain> <8@dom.ain> <9@dom.ain> 655 <5@dom.ain> <6@dom.ain> <7@dom.ain> <8@dom.ain> <9@dom.ain>
656 656
657 Test""") 657 Test""")
658 658
659 def test_no_split_long_header(self): 659 def test_no_split_long_header(self):
660 eq = self.ndiffAssertEqual 660 eq = self.ndiffAssertEqual
661 hstr = 'References: ' + 'x' * 80 661 hstr = 'References: ' + 'x' * 80
662 h = Header(hstr, continuation_ws='\t') 662 h = Header(hstr, continuation_ws='\t')
663 eq(h.encode(), """\ 663 eq(h.encode(), """\
664 References: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx""") 664 References: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx""")
665 665
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 723
724 """) 724 """)
725 725
726 def test_long_to_header(self): 726 def test_long_to_header(self):
727 eq = self.ndiffAssertEqual 727 eq = self.ndiffAssertEqual
728 to = '"Someone Test #A" <someone@eecs.umich.edu>,<someone@eecs.umich.edu >,"Someone Test #B" <someone@umich.edu>, "Someone Test #C" <someone@eecs.umich.e du>, "Someone Test #D" <someone@eecs.umich.edu>' 728 to = '"Someone Test #A" <someone@eecs.umich.edu>,<someone@eecs.umich.edu >,"Someone Test #B" <someone@umich.edu>, "Someone Test #C" <someone@eecs.umich.e du>, "Someone Test #D" <someone@eecs.umich.edu>'
729 msg = Message() 729 msg = Message()
730 msg['To'] = to 730 msg['To'] = to
731 eq(msg.as_string(0), '''\ 731 eq(msg.as_string(0), '''\
732 To: "Someone Test #A" <someone@eecs.umich.edu>, <someone@eecs.umich.edu>, 732 To: "Someone Test #A" <someone@eecs.umich.edu>, <someone@eecs.umich.edu>,
733 \t"Someone Test #B" <someone@umich.edu>, 733 "Someone Test #B" <someone@umich.edu>,
734 \t"Someone Test #C" <someone@eecs.umich.edu>, 734 "Someone Test #C" <someone@eecs.umich.edu>,
735 \t"Someone Test #D" <someone@eecs.umich.edu> 735 "Someone Test #D" <someone@eecs.umich.edu>
736 736
737 ''') 737 ''')
738 738
739 def test_long_line_after_append(self): 739 def test_long_line_after_append(self):
740 eq = self.ndiffAssertEqual 740 eq = self.ndiffAssertEqual
741 s = 'This is an example of string which has almost the limit of header l ength.' 741 s = 'This is an example of string which has almost the limit of header l ength.'
742 h = Header(s) 742 h = Header(s)
743 h.append('Add another line.') 743 h.append('Add another line.')
744 eq(h.encode(), """\ 744 eq(h.encode(), """\
745 This is an example of string which has almost the limit of header length. 745 This is an example of string which has almost the limit of header length.
(...skipping 22 matching lines...) Expand all
768 def test_long_received_header(self): 768 def test_long_received_header(self):
769 h = 'from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by hrothgar.la. mastaler.com (tmda-ofmipd) with ESMTP; Wed, 05 Mar 2003 18:10:18 -0700' 769 h = 'from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by hrothgar.la. mastaler.com (tmda-ofmipd) with ESMTP; Wed, 05 Mar 2003 18:10:18 -0700'
770 msg = Message() 770 msg = Message()
771 msg['Received-1'] = Header(h, continuation_ws='\t') 771 msg['Received-1'] = Header(h, continuation_ws='\t')
772 msg['Received-2'] = h 772 msg['Received-2'] = h
773 self.assertEqual(msg.as_string(), """\ 773 self.assertEqual(msg.as_string(), """\
774 Received-1: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by 774 Received-1: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
775 \throthgar.la.mastaler.com (tmda-ofmipd) with ESMTP; 775 \throthgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
776 \tWed, 05 Mar 2003 18:10:18 -0700 776 \tWed, 05 Mar 2003 18:10:18 -0700
777 Received-2: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by 777 Received-2: from FOO.TLD (vizworld.acl.foo.tld [123.452.678.9]) by
778 \throthgar.la.mastaler.com (tmda-ofmipd) with ESMTP; 778 hrothgar.la.mastaler.com (tmda-ofmipd) with ESMTP;
779 \tWed, 05 Mar 2003 18:10:18 -0700 779 Wed, 05 Mar 2003 18:10:18 -0700
780 780
781 """) 781 """)
782 782
783 def test_string_headerinst_eq(self): 783 def test_string_headerinst_eq(self):
784 h = '<15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David Bremner\'s message of "Thu, 6 Mar 2003 13:58:21 +0100")' 784 h = '<15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David Bremner\'s message of "Thu, 6 Mar 2003 13:58:21 +0100")'
785 msg = Message() 785 msg = Message()
786 msg['Received-1'] = Header(h, header_name='Received-1', 786 msg['Received-1'] = Header(h, header_name='Received-1')
787 continuation_ws='\t')
788 msg['Received-2'] = h 787 msg['Received-2'] = h
789 self.assertEqual(msg.as_string(), """\ 788 self.assertEqual(msg.as_string(), """\
790 Received-1: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> 789 Received-1: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David
791 \t(David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100") 790 Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
792 Received-2: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> 791 Received-2: <15975.17901.207240.414604@sgigritzmann1.mathematik.tu-muenchen.de> (David
793 \t(David Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100") 792 Bremner's message of "Thu, 6 Mar 2003 13:58:21 +0100")
794 793
795 """) 794 """)
796 795
797 def test_long_unbreakable_lines_with_continuation(self): 796 def test_long_unbreakable_lines_with_continuation(self):
798 eq = self.ndiffAssertEqual 797 eq = self.ndiffAssertEqual
799 msg = Message() 798 msg = Message()
800 t = """\ 799 t = """\
801 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9 800 iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
802 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp""" 801 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp"""
803 msg['Face-1'] = t 802 msg['Face-1'] = t
804 msg['Face-2'] = Header(t, header_name='Face-2') 803 msg['Face-2'] = Header(t, header_name='Face-2')
805 eq(msg.as_string(), """\ 804 eq(msg.as_string(), """\
806 Face-1: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9 805 Face-1: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
807 \tlocQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp 806 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
808 Face-2: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9 807 Face-2: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUAAAAkHiJeRUIcGBi9
809 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp 808 locQDQ4zJykFBAXJfWDjAAACYUlEQVR4nF2TQY/jIAyFc6lydlG5x8Nyp1Y69wj1PN2I5gzp
810 809
811 """) 810 """)
812 811
813 def test_another_long_multiline_header(self): 812 def test_another_long_multiline_header(self):
814 eq = self.ndiffAssertEqual 813 eq = self.ndiffAssertEqual
815 m = '''\ 814 m = '''\
816 Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with Microsof t SMTPSVC(5.0.2195.4905); 815 Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with Microsof t SMTPSVC(5.0.2195.4905);
817 \tWed, 16 Oct 2002 07:41:11 -0700''' 816 \tWed, 16 Oct 2002 07:41:11 -0700'''
818 msg = email.message_from_string(m) 817 msg = email.message_from_string(m)
819 eq(msg.as_string(), '''\ 818 eq(msg.as_string(), '''\
820 Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with 819 Received: from siimage.com ([172.25.1.3]) by zima.siliconimage.com with
821 \tMicrosoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700 820 Microsoft SMTPSVC(5.0.2195.4905); Wed, 16 Oct 2002 07:41:11 -0700
822 821
823 ''') 822 ''')
824 823
825 def test_long_lines_with_different_header(self): 824 def test_long_lines_with_different_header(self):
826 eq = self.ndiffAssertEqual 825 eq = self.ndiffAssertEqual
827 h = """\ 826 h = """\
828 List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-tal k>, 827 List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-tal k>,
829 <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscr ibe>""" 828 <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscr ibe>"""
830 msg = Message() 829 msg = Message()
831 msg['List'] = h 830 msg['List'] = h
832 msg['List'] = Header(h, header_name='List') 831 msg['List'] = Header(h, header_name='List')
833 eq(msg.as_string(), """\ 832 eq(msg.as_string(), """\
834 List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassass in-talk>, 833 List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassass in-talk>,
835 \t<mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe> 834 <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
836 List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassass in-talk>, 835 List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassass in-talk>,
837 <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe> 836 <mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
838 837
839 """) 838 """)
840 839
841 840
842 841
843 # Test mangling of "From " lines in the body of a message 842 # Test mangling of "From " lines in the body of a message
844 class TestFromMangling(unittest.TestCase): 843 class TestFromMangling(unittest.TestCase):
845 def setUp(self): 844 def setUp(self):
(...skipping 2125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2971 charset='us-ascii', language='en') 2970 charset='us-ascii', language='en')
2972 eq(msg.get_param('title'), 2971 eq(msg.get_param('title'),
2973 ('us-ascii', 'en', 'This is even more ***fun*** isn\'t it!')) 2972 ('us-ascii', 'en', 'This is even more ***fun*** isn\'t it!'))
2974 msg = self._msgobj('msg_01.txt') 2973 msg = self._msgobj('msg_01.txt')
2975 msg.set_param('title', 'This is even more ***fun*** isn\'t it!', 2974 msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
2976 charset='us-ascii', language='en') 2975 charset='us-ascii', language='en')
2977 eq(msg.as_string(), """\ 2976 eq(msg.as_string(), """\
2978 Return-Path: <bbb@zzz.org> 2977 Return-Path: <bbb@zzz.org>
2979 Delivered-To: bbb@zzz.org 2978 Delivered-To: bbb@zzz.org
2980 Received: by mail.zzz.org (Postfix, from userid 889) 2979 Received: by mail.zzz.org (Postfix, from userid 889)
2981 \tid 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT) 2980 id 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT)
2982 MIME-Version: 1.0 2981 MIME-Version: 1.0
2983 Content-Transfer-Encoding: 7bit 2982 Content-Transfer-Encoding: 7bit
2984 Message-ID: <15090.61304.110929.45684@aaa.zzz.org> 2983 Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
2985 From: bbb@ddd.com (John X. Doe) 2984 From: bbb@ddd.com (John X. Doe)
2986 To: bbb@zzz.org 2985 To: bbb@zzz.org
2987 Subject: This is a test message 2986 Subject: This is a test message
2988 Date: Fri, 4 May 2001 14:05:44 -0400 2987 Date: Fri, 4 May 2001 14:05:44 -0400
2989 Content-Type: text/plain; charset=us-ascii; 2988 Content-Type: text/plain; charset=us-ascii;
2990 \ttitle*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t% 20it%21" 2989 title*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%2 0it%21"
2991 2990
2992 2991
2993 Hi, 2992 Hi,
2994 2993
2995 Do you like this message? 2994 Do you like this message?
2996 2995
2997 -Me 2996 -Me
2998 """) 2997 """)
2999 2998
3000 def test_del_param(self): 2999 def test_del_param(self):
3001 eq = self.ndiffAssertEqual 3000 eq = self.ndiffAssertEqual
3002 msg = self._msgobj('msg_01.txt') 3001 msg = self._msgobj('msg_01.txt')
3003 msg.set_param('foo', 'bar', charset='us-ascii', language='en') 3002 msg.set_param('foo', 'bar', charset='us-ascii', language='en')
3004 msg.set_param('title', 'This is even more ***fun*** isn\'t it!', 3003 msg.set_param('title', 'This is even more ***fun*** isn\'t it!',
3005 charset='us-ascii', language='en') 3004 charset='us-ascii', language='en')
3006 msg.del_param('foo', header='Content-Type') 3005 msg.del_param('foo', header='Content-Type')
3007 eq(msg.as_string(), """\ 3006 eq(msg.as_string(), """\
3008 Return-Path: <bbb@zzz.org> 3007 Return-Path: <bbb@zzz.org>
3009 Delivered-To: bbb@zzz.org 3008 Delivered-To: bbb@zzz.org
3010 Received: by mail.zzz.org (Postfix, from userid 889) 3009 Received: by mail.zzz.org (Postfix, from userid 889)
3011 \tid 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT) 3010 id 27CEAD38CC; Fri, 4 May 2001 14:05:44 -0400 (EDT)
3012 MIME-Version: 1.0 3011 MIME-Version: 1.0
3013 Content-Transfer-Encoding: 7bit 3012 Content-Transfer-Encoding: 7bit
3014 Message-ID: <15090.61304.110929.45684@aaa.zzz.org> 3013 Message-ID: <15090.61304.110929.45684@aaa.zzz.org>
3015 From: bbb@ddd.com (John X. Doe) 3014 From: bbb@ddd.com (John X. Doe)
3016 To: bbb@zzz.org 3015 To: bbb@zzz.org
3017 Subject: This is a test message 3016 Subject: This is a test message
3018 Date: Fri, 4 May 2001 14:05:44 -0400 3017 Date: Fri, 4 May 2001 14:05:44 -0400
3019 Content-Type: text/plain; charset="us-ascii"; 3018 Content-Type: text/plain; charset="us-ascii";
3020 \ttitle*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t% 20it%21" 3019 title*="us-ascii'en'This%20is%20even%20more%20%2A%2A%2Afun%2A%2A%2A%20isn%27t%2 0it%21"
3021 3020
3022 3021
3023 Hi, 3022 Hi,
3024 3023
3025 Do you like this message? 3024 Do you like this message?
3026 3025
3027 -Me 3026 -Me
3028 """) 3027 """)
3029 3028
3030 def test_rfc2231_get_content_charset(self): 3029 def test_rfc2231_get_content_charset(self):
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
3275 3274
3276 3275
3277 def test_main(): 3276 def test_main():
3278 for testclass in _testclasses(): 3277 for testclass in _testclasses():
3279 run_unittest(testclass) 3278 run_unittest(testclass)
3280 3279
3281 3280
3282 3281
3283 if __name__ == '__main__': 3282 if __name__ == '__main__':
3284 unittest.main(defaultTest='suite') 3283 unittest.main(defaultTest='suite')
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r483