Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
email.test.test_email.TestQuopri Class Reference

List of all members.

Public Member Functions

def setUp
def test_quopri_header_check
def test_quopri_body_check
def test_header_quopri_len
def test_body_quopri_len
def test_quote_unquote_idempotent
def test_header_encode_null
def test_header_encode_one_word
def test_header_encode_two_lines
def test_header_encode_non_ascii
def test_header_encode_alt_charset
def test_header_decode_null
def test_header_decode_one_word
def test_header_decode_two_lines
def test_header_decode_non_ascii
def test_decode_null_word
def test_decode_null_line_null_word
def test_decode_one_word
def test_decode_one_word_eol
def test_decode_one_line
def test_decode_one_line_lf
def test_decode_one_line_cr
def test_decode_one_line_nl
def test_decode_one_line_crnl
def test_decode_one_line_one_word
def test_decode_one_line_one_word_eol
def test_decode_two_lines
def test_decode_two_lines_eol
def test_decode_one_long_line
def test_decode_one_space
def test_decode_multiple_spaces
def test_decode_one_line_trailing_spaces
def test_decode_two_lines_trailing_spaces
def test_decode_quoted_word
def test_decode_uppercase_quoting
def test_decode_lowercase_quoting
def test_decode_soft_line_break
def test_decode_false_quoting
def test_encode_null
def test_encode_null_lines
def test_encode_one_line
def test_encode_one_line_crlf
def test_encode_one_line_eol
def test_encode_one_space
def test_encode_one_line_one_space
def test_encode_two_lines_one_space
def test_encode_one_word_trailing_spaces
def test_encode_one_line_trailing_spaces
def test_encode_one_word_trailing_tab
def test_encode_one_line_trailing_tab
def test_encode_trailing_space_before_maxlinelen
def test_encode_trailing_space_at_maxlinelen
def test_encode_trailing_space_beyond_maxlinelen
def test_encode_whitespace_lines
def test_encode_quoted_equals
def test_encode_one_long_string
def test_encode_one_long_line
def test_encode_one_very_long_line
def test_encode_one_long_line
def test_encode_shortest_maxlinelen
def test_encode_maxlinelen_too_small
def test_encode

Public Attributes

 hlit
 hnon
 blit
 bnon

Private Member Functions

def _test_header_encode
def _test_header_decode
def _test_decode
def _test_encode

Detailed Description

Definition at line 3520 of file test_email.py.


Member Function Documentation

def email.test.test_email.TestQuopri._test_decode (   self,
  encoded,
  expected_decoded,
  eol = None 
) [private]

Definition at line 3637 of file test_email.py.

03637 
03638     def _test_decode(self, encoded, expected_decoded, eol=None):
03639         if eol is None:
03640             decoded = quoprimime.decode(encoded)
03641         else:
03642             decoded = quoprimime.decode(encoded, eol=eol)
03643         self.assertEqual(decoded, expected_decoded)

Here is the call graph for this function:

Here is the caller graph for this function:

def email.test.test_email.TestQuopri._test_encode (   self,
  body,
  expected_encoded_body,
  maxlinelen = None,
  eol = None 
) [private]

Definition at line 3713 of file test_email.py.

03713 
03714     def _test_encode(self, body, expected_encoded_body, maxlinelen=None, eol=None):
03715         kwargs = {}
03716         if maxlinelen is None:
03717             # Use body_encode's default.
03718             maxlinelen = 76
03719         else:
03720             kwargs['maxlinelen'] = maxlinelen
03721         if eol is None:
03722             # Use body_encode's default.
03723             eol = '\n'
03724         else:
03725             kwargs['eol'] = eol
03726         encoded_body = quoprimime.body_encode(body, **kwargs)
03727         self.assertEqual(encoded_body, expected_encoded_body)
03728         if eol == '\n' or eol == '\r\n':
03729             # We know how to split the result back into lines, so maxlinelen
03730             # can be checked.
03731             for line in encoded_body.splitlines():
03732                 self.assertLessEqual(len(line), maxlinelen)

Here is the call graph for this function:

Here is the caller graph for this function:

def email.test.test_email.TestQuopri._test_header_decode (   self,
  encoded_header,
  expected_decoded_header 
) [private]

Definition at line 3621 of file test_email.py.

03621 
03622     def _test_header_decode(self, encoded_header, expected_decoded_header):
03623         decoded_header = quoprimime.header_decode(encoded_header)
03624         self.assertEqual(decoded_header, expected_decoded_header)

Here is the call graph for this function:

Here is the caller graph for this function:

def email.test.test_email.TestQuopri._test_header_encode (   self,
  header,
  expected_encoded_header,
  charset = None 
) [private]

Definition at line 3596 of file test_email.py.

03596 
03597     def _test_header_encode(self, header, expected_encoded_header, charset=None):
03598         if charset is None:
03599             encoded_header = quoprimime.header_encode(header)
03600         else:
03601             encoded_header = quoprimime.header_encode(header, charset)
03602         self.assertEqual(encoded_header, expected_encoded_header)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 3521 of file test_email.py.

03521 
03522     def setUp(self):
03523         # Set of characters (as byte integers) that don't need to be encoded
03524         # in headers.
03525         self.hlit = list(chain(
03526             range(ord('a'), ord('z') + 1),
03527             range(ord('A'), ord('Z') + 1),
03528             range(ord('0'), ord('9') + 1),
03529             (c for c in b'!*+-/')))
03530         # Set of characters (as byte integers) that do need to be encoded in
03531         # headers.
03532         self.hnon = [c for c in range(256) if c not in self.hlit]
03533         assert len(self.hlit) + len(self.hnon) == 256
03534         # Set of characters (as byte integers) that don't need to be encoded
03535         # in bodies.
03536         self.blit = list(range(ord(' '), ord('~') + 1))
03537         self.blit.append(ord('\t'))
03538         self.blit.remove(ord('='))
03539         # Set of characters (as byte integers) that do need to be encoded in
03540         # bodies.
03541         self.bnon = [c for c in range(256) if c not in self.blit]
03542         assert len(self.blit) + len(self.bnon) == 256

Here is the caller graph for this function:

Definition at line 3584 of file test_email.py.

03584 
03585     def test_body_quopri_len(self):
03586         eq = self.assertEqual
03587         for c in self.blit:
03588             eq(quoprimime.body_length(bytes([c])), 1)
03589         for c in self.bnon:
03590             eq(quoprimime.body_length(bytes([c])), 3)

Here is the call graph for this function:

Definition at line 3710 of file test_email.py.

03710 
03711     def test_decode_false_quoting(self):
03712         self._test_decode('A=1,B=A ==> A+B==2', 'A=1,B=A ==> A+B==2')

Here is the call graph for this function:

Definition at line 3704 of file test_email.py.

03704 
03705     def test_decode_lowercase_quoting(self):
03706         self._test_decode('ab=cd=ef', 'ab\xcd\xef')

Here is the call graph for this function:

Definition at line 3689 of file test_email.py.

03689 
03690     def test_decode_multiple_spaces(self):
03691         self._test_decode(' ' * 5, '')

Here is the call graph for this function:

Definition at line 3647 of file test_email.py.

03647 
03648     def test_decode_null_line_null_word(self):
03649         self._test_decode('\r\n', '\n')

Here is the call graph for this function:

Definition at line 3644 of file test_email.py.

03644 
03645     def test_decode_null_word(self):
03646         self._test_decode('', '')

Here is the call graph for this function:

Definition at line 3656 of file test_email.py.

03656 
03657     def test_decode_one_line(self):
03658         self._test_decode('hello\r\n', 'hello\n')

Here is the call graph for this function:

Definition at line 3662 of file test_email.py.

03662 
03663     def test_decode_one_line_cr(self):
03664         self._test_decode('hello\r', 'hello\n')

Here is the call graph for this function:

Definition at line 3668 of file test_email.py.

03668 
03669     def test_decode_one_line_crnl(self):
03670         self._test_decode('hello\r\n', 'helloX', eol='X')

Here is the call graph for this function:

Definition at line 3659 of file test_email.py.

03659 
03660     def test_decode_one_line_lf(self):
03661         self._test_decode('hello\n', 'hello\n')

Here is the call graph for this function:

Definition at line 3665 of file test_email.py.

03665 
03666     def test_decode_one_line_nl(self):
03667         self._test_decode('hello\n', 'helloX', eol='X')

Here is the call graph for this function:

Definition at line 3671 of file test_email.py.

03671 
03672     def test_decode_one_line_one_word(self):
03673         self._test_decode('hello\r\nworld', 'hello\nworld')

Here is the call graph for this function:

Definition at line 3674 of file test_email.py.

03674 
03675     def test_decode_one_line_one_word_eol(self):
03676         self._test_decode('hello\r\nworld', 'helloXworld', eol='X')

Here is the call graph for this function:

Definition at line 3692 of file test_email.py.

03692 
03693     def test_decode_one_line_trailing_spaces(self):
03694         self._test_decode('hello    \r\n', 'hello\n')

Here is the call graph for this function:

Definition at line 3683 of file test_email.py.

03683 
03684     def test_decode_one_long_line(self):
03685         self._test_decode('Spam' * 250, 'Spam' * 250)

Here is the call graph for this function:

Definition at line 3686 of file test_email.py.

03686 
03687     def test_decode_one_space(self):
03688         self._test_decode(' ', '')

Here is the call graph for this function:

Definition at line 3650 of file test_email.py.

03650 
03651     def test_decode_one_word(self):
03652         self._test_decode('hello', 'hello')

Here is the call graph for this function:

Definition at line 3653 of file test_email.py.

03653 
03654     def test_decode_one_word_eol(self):
03655         self._test_decode('hello', 'hello', eol='X')

Here is the call graph for this function:

Definition at line 3698 of file test_email.py.

03698 
03699     def test_decode_quoted_word(self):
03700         self._test_decode('=22quoted=20words=22', '"quoted words"')

Here is the call graph for this function:

Definition at line 3707 of file test_email.py.

03707 
03708     def test_decode_soft_line_break(self):
03709         self._test_decode('soft line=\r\nbreak', 'soft linebreak')

Here is the call graph for this function:

Definition at line 3677 of file test_email.py.

03677 
03678     def test_decode_two_lines(self):
03679         self._test_decode('hello\r\nworld\r\n', 'hello\nworld\n')

Here is the call graph for this function:

Definition at line 3680 of file test_email.py.

03680 
03681     def test_decode_two_lines_eol(self):
03682         self._test_decode('hello\r\nworld\r\n', 'helloXworldX', eol='X')

Here is the call graph for this function:

Definition at line 3695 of file test_email.py.

03695 
03696     def test_decode_two_lines_trailing_spaces(self):
03697         self._test_decode('hello    \r\nworld   \r\n', 'hello\nworld\n')

Here is the call graph for this function:

Definition at line 3701 of file test_email.py.

03701 
03702     def test_decode_uppercase_quoting(self):
03703         self._test_decode('ab=CD=EF', 'ab\xcd\xef')

Here is the call graph for this function:

Definition at line 3808 of file test_email.py.

03808 
03809     def test_encode(self):
03810         eq = self.assertEqual
03811         eq(quoprimime.body_encode(''), '')
03812         eq(quoprimime.body_encode('hello'), 'hello')
03813         # Test the binary flag
03814         eq(quoprimime.body_encode('hello\r\nworld'), 'hello\nworld')
03815         # Test the maxlinelen arg
03816         eq(quoprimime.body_encode('xxxx ' * 20, maxlinelen=40), """\
03817 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=
03818  xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=
03819 x xxxx xxxx xxxx xxxx=20""")
03820         # Test the eol argument
03821         eq(quoprimime.body_encode('xxxx ' * 20, maxlinelen=40, eol='\r\n'),
03822            """\
03823 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx=\r
03824  xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx=\r
03825 x xxxx xxxx xxxx xxxx=20""")
03826         eq(quoprimime.body_encode("""\
03827 one line
03828 
03829 two line"""), """\
03830 one line
03831 
03832 two line""")
03833 
03834 
03835 
# Test the Charset class

Here is the call graph for this function:

Definition at line 3805 of file test_email.py.

03805 
03806     def test_encode_maxlinelen_too_small(self):
03807         self.assertRaises(ValueError, self._test_encode, '', '', maxlinelen=3)

Here is the call graph for this function:

Definition at line 3733 of file test_email.py.

03733 
03734     def test_encode_null(self):
03735         self._test_encode('', '')

Here is the call graph for this function:

Definition at line 3736 of file test_email.py.

03736 
03737     def test_encode_null_lines(self):
03738         self._test_encode('\n\n', '\n\n')

Here is the call graph for this function:

Definition at line 3739 of file test_email.py.

03739 
03740     def test_encode_one_line(self):
03741         self._test_encode('hello\n', 'hello\n')

Here is the call graph for this function:

Definition at line 3742 of file test_email.py.

03742 
03743     def test_encode_one_line_crlf(self):
03744         self._test_encode('hello\r\n', 'hello\n')

Here is the call graph for this function:

Definition at line 3745 of file test_email.py.

03745 
03746     def test_encode_one_line_eol(self):
03747         self._test_encode('hello\n', 'hello\r\n', eol='\r\n')

Here is the call graph for this function:

Definition at line 3751 of file test_email.py.

03751 
03752     def test_encode_one_line_one_space(self):
03753         self._test_encode(' \n', '=20\n')
03754 
03755 # XXX: body_encode() expect strings, but uses ord(char) from these strings
03756 # to index into a 256-entry list.  For code points above 255, this will fail.
03757 # Should there be a check for 8-bit only ord() values in body, or at least
03758 # a comment about the expected input?

Here is the call graph for this function:

Definition at line 3765 of file test_email.py.

03765 
03766     def test_encode_one_line_trailing_spaces(self):
03767         self._test_encode('hello   \n', 'hello  =20\n')

Here is the call graph for this function:

Definition at line 3771 of file test_email.py.

03771 
03772     def test_encode_one_line_trailing_tab(self):
03773         self._test_encode('hello  \t\n', 'hello  =09\n')

Here is the call graph for this function:

Definition at line 3792 of file test_email.py.

03792 
03793     def test_encode_one_long_line(self):
03794         self._test_encode('x' * 100 + '\n', 'x' * 75 + '=\n' + 'x' * 25 + '\n')

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 3799 of file test_email.py.

03799 
03800     def test_encode_one_long_line(self):
03801         self._test_encode('x' * 100 + '\n', 'x' * 75 + '=\n' + 'x' * 25 + '\n')

Here is the call graph for this function:

Definition at line 3789 of file test_email.py.

03789 
03790     def test_encode_one_long_string(self):
03791         self._test_encode('x' * 100, 'x' * 75 + '=\n' + 'x' * 25)

Here is the call graph for this function:

Definition at line 3748 of file test_email.py.

03748 
03749     def test_encode_one_space(self):
03750         self._test_encode(' ', '=20')

Here is the call graph for this function:

Definition at line 3795 of file test_email.py.

03795 
03796     def test_encode_one_very_long_line(self):
03797         self._test_encode('x' * 200 + '\n',
03798                 2 * ('x' * 75 + '=\n') + 'x' * 50 + '\n')

Here is the call graph for this function:

Definition at line 3762 of file test_email.py.

03762 
03763     def test_encode_one_word_trailing_spaces(self):
03764         self._test_encode('hello   ', 'hello  =20')

Here is the call graph for this function:

Definition at line 3768 of file test_email.py.

03768 
03769     def test_encode_one_word_trailing_tab(self):
03770         self._test_encode('hello  \t', 'hello  =09')

Here is the call graph for this function:

Definition at line 3786 of file test_email.py.

03786 
03787     def test_encode_quoted_equals(self):
03788         self._test_encode('a = b', 'a =3D b')

Here is the call graph for this function:

Definition at line 3802 of file test_email.py.

03802 
03803     def test_encode_shortest_maxlinelen(self):
03804         self._test_encode('=' * 5, '=3D=\n' * 4 + '=3D', maxlinelen=4)

Here is the call graph for this function:

Definition at line 3777 of file test_email.py.

03777 
03778     def test_encode_trailing_space_at_maxlinelen(self):
03779         self._test_encode('abcd \n1234', 'abcd=\n=20\n1234', maxlinelen=5)

Here is the call graph for this function:

Definition at line 3774 of file test_email.py.

03774 
03775     def test_encode_trailing_space_before_maxlinelen(self):
03776         self._test_encode('abcd \n1234', 'abcd =\n\n1234', maxlinelen=6)

Here is the call graph for this function:

Definition at line 3780 of file test_email.py.

03780 
03781     def test_encode_trailing_space_beyond_maxlinelen(self):
03782         self._test_encode('abcd \n1234', 'abc=\nd=20\n1234', maxlinelen=4)

Here is the call graph for this function:

Definition at line 3759 of file test_email.py.

03759 
03760     def test_encode_two_lines_one_space(self):
03761         self._test_encode(' \n \n', '=20\n=20\n')

Here is the call graph for this function:

Definition at line 3783 of file test_email.py.

03783 
03784     def test_encode_whitespace_lines(self):
03785         self._test_encode(' \n' * 5, '=20\n' * 5)

Here is the call graph for this function:

Definition at line 3634 of file test_email.py.

03634 
03635     def test_header_decode_non_ascii(self):
03636         self._test_header_decode('hello=C7there', 'hello\xc7there')

Here is the call graph for this function:

Definition at line 3625 of file test_email.py.

03625 
03626     def test_header_decode_null(self):
03627         self._test_header_decode('', '')

Here is the call graph for this function:

Definition at line 3628 of file test_email.py.

03628 
03629     def test_header_decode_one_word(self):
03630         self._test_header_decode('hello', 'hello')

Here is the call graph for this function:

Definition at line 3631 of file test_email.py.

03631 
03632     def test_header_decode_two_lines(self):
03633         self._test_header_decode('hello=0Aworld', 'hello\nworld')

Here is the call graph for this function:

Definition at line 3617 of file test_email.py.

03617 
03618     def test_header_encode_alt_charset(self):
03619         self._test_header_encode(b'hello', '=?iso-8859-2?q?hello?=',
03620                 charset='iso-8859-2')

Here is the call graph for this function:

Definition at line 3613 of file test_email.py.

03613 
03614     def test_header_encode_non_ascii(self):
03615         self._test_header_encode(b'hello\xc7there',
03616                                 '=?iso-8859-1?q?hello=C7there?=')

Here is the call graph for this function:

Definition at line 3603 of file test_email.py.

03603 
03604     def test_header_encode_null(self):
03605         self._test_header_encode(b'', '')

Here is the call graph for this function:

Definition at line 3606 of file test_email.py.

03606 
03607     def test_header_encode_one_word(self):
03608         self._test_header_encode(b'hello', '=?iso-8859-1?q?hello?=')

Here is the call graph for this function:

Definition at line 3609 of file test_email.py.

03609 
03610     def test_header_encode_two_lines(self):
03611         self._test_header_encode(b'hello\nworld',
03612                                 '=?iso-8859-1?q?hello=0Aworld?=')

Here is the call graph for this function:

Definition at line 3559 of file test_email.py.

03559 
03560     def test_header_quopri_len(self):
03561         eq = self.assertEqual
03562         eq(quoprimime.header_length(b'hello'), 5)
03563         # RFC 2047 chrome is not included in header_length().
03564         eq(len(quoprimime.header_encode(b'hello', charset='xxx')),
03565            quoprimime.header_length(b'hello') +
03566            # =?xxx?q?...?= means 10 extra characters
03567            10)
03568         eq(quoprimime.header_length(b'h@e@l@l@o@'), 20)
03569         # RFC 2047 chrome is not included in header_length().
03570         eq(len(quoprimime.header_encode(b'h@e@l@l@o@', charset='xxx')),
03571            quoprimime.header_length(b'h@e@l@l@o@') +
03572            # =?xxx?q?...?= means 10 extra characters
03573            10)
03574         for c in self.hlit:
03575             eq(quoprimime.header_length(bytes([c])), 1,
03576                'expected length 1 for %r' % chr(c))
03577         for c in self.hnon:
03578             # Space is special; it's encoded to _
03579             if c == ord(' '):
03580                 continue
03581             eq(quoprimime.header_length(bytes([c])), 3,
03582                'expected length 3 for %r' % chr(c))
03583         eq(quoprimime.header_length(b' '), 1)

Here is the call graph for this function:

Definition at line 3551 of file test_email.py.

03551 
03552     def test_quopri_body_check(self):
03553         for c in self.blit:
03554             self.assertFalse(quoprimime.body_check(c),
03555                         'Should not be body quopri encoded: %s' % chr(c))
03556         for c in self.bnon:
03557             self.assertTrue(quoprimime.body_check(c),
03558                             'Should be body quopri encoded: %s' % chr(c))

Here is the call graph for this function:

Definition at line 3543 of file test_email.py.

03543 
03544     def test_quopri_header_check(self):
03545         for c in self.hlit:
03546             self.assertFalse(quoprimime.header_check(c),
03547                         'Should not be header quopri encoded: %s' % chr(c))
03548         for c in self.hnon:
03549             self.assertTrue(quoprimime.header_check(c),
03550                             'Should be header quopri encoded: %s' % chr(c))

Here is the call graph for this function:

Definition at line 3591 of file test_email.py.

03591 
03592     def test_quote_unquote_idempotent(self):
03593         for x in range(256):
03594             c = chr(x)
03595             self.assertEqual(quoprimime.unquote(quoprimime.quote(c)), c)

Here is the call graph for this function:


Member Data Documentation

Definition at line 3535 of file test_email.py.

Definition at line 3540 of file test_email.py.

Definition at line 3524 of file test_email.py.

Definition at line 3531 of file test_email.py.


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