PyXR

c:\python24\lib \ email \ test \ test_email_codecs.py



0001 # Copyright (C) 2002 Python Software Foundation
0002 # email package unit tests for (optional) Asian codecs
0003 
0004 import unittest
0005 from test.test_support import TestSkipped, run_unittest
0006 
0007 from email.test.test_email import TestEmailBase
0008 from email.Charset import Charset
0009 from email.Header import Header, decode_header
0010 
0011 
0012 class TestEmailAsianCodecs(TestEmailBase):
0013     def test_japanese_codecs(self):
0014         eq = self.ndiffAssertEqual
0015         j = Charset("euc-jp")
0016         g = Charset("iso-8859-1")
0017         h = Header("Hello World!")
0018         jhello = '\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc\xa5\xeb\xa5\xc9\xa1\xaa'
0019         ghello = 'Gr\xfc\xdf Gott!'
0020         h.append(jhello, j)
0021         h.append(ghello, g)
0022         # BAW: This used to -- and maybe should -- fold the two iso-8859-1
0023         # chunks into a single encoded word.  However it doesn't violate the
0024         # standard to have them as two encoded chunks and maybe it's
0025         # reasonable <wink> for each .append() call to result in a separate
0026         # encoded word.
0027         eq(h.encode(), """\
0028 Hello World! =?iso-2022-jp?b?GyRCJU8lbSE8JW8hPCVrJUkhKhsoQg==?=
0029  =?iso-8859-1?q?Gr=FC=DF?= =?iso-8859-1?q?_Gott!?=""")
0030         eq(decode_header(h.encode()),
0031            [('Hello World!', None),
0032             ('\x1b$B%O%m!<%o!<%k%I!*\x1b(B', 'iso-2022-jp'),
0033             ('Gr\xfc\xdf Gott!', 'iso-8859-1')])
0034         long = 'test-ja \xa4\xd8\xc5\xea\xb9\xc6\xa4\xb5\xa4\xec\xa4\xbf\xa5\xe1\xa1\xbc\xa5\xeb\xa4\xcf\xbb\xca\xb2\xf1\xbc\xd4\xa4\xce\xbe\xb5\xc7\xa7\xa4\xf2\xc2\xd4\xa4\xc3\xa4\xc6\xa4\xa4\xa4\xde\xa4\xb9'
0035         h = Header(long, j, header_name="Subject")
0036         # test a very long header
0037         enc = h.encode()
0038         # TK: splitting point may differ by codec design and/or Header encoding
0039         eq(enc , """\
0040 =?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKGyhC?=
0041  =?iso-2022-jp?b?GyRCMnE8VCROPjVHJyRyQlQkQyRGJCQkXiQ5GyhC?=""")
0042         # TK: full decode comparison
0043         eq(h.__unicode__().encode('euc-jp'), long)
0044 
0045 
0046 
0047 def suite():
0048     suite = unittest.TestSuite()
0049     suite.addTest(unittest.makeSuite(TestEmailAsianCodecs))
0050     return suite
0051 
0052 
0053 def test_main():
0054     run_unittest(TestEmailAsianCodecs)
0055 
0056 
0057 
0058 if __name__ == '__main__':
0059     unittest.main(defaultTest='suite')
0060 

Generated by PyXR 0.9.4
SourceForge.net Logo