Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | # Copyright (C) 2002 Python Software Foundation |
2 | # email package unit tests for (optional) Asian codecs | |
3 | ||
4 | import unittest | |
5 | from test.test_support import TestSkipped, run_unittest | |
6 | ||
7 | from email.test.test_email import TestEmailBase | |
8 | from email.Charset import Charset | |
9 | from email.Header import Header, decode_header | |
10 | ||
11 | \f | |
12 | class TestEmailAsianCodecs(TestEmailBase): | |
13 | def test_japanese_codecs(self): | |
14 | eq = self.ndiffAssertEqual | |
15 | j = Charset("euc-jp") | |
16 | g = Charset("iso-8859-1") | |
17 | h = Header("Hello World!") | |
18 | jhello = '\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc\xa5\xeb\xa5\xc9\xa1\xaa' | |
19 | ghello = 'Gr\xfc\xdf Gott!' | |
20 | h.append(jhello, j) | |
21 | h.append(ghello, g) | |
22 | # BAW: This used to -- and maybe should -- fold the two iso-8859-1 | |
23 | # chunks into a single encoded word. However it doesn't violate the | |
24 | # standard to have them as two encoded chunks and maybe it's | |
25 | # reasonable <wink> for each .append() call to result in a separate | |
26 | # encoded word. | |
27 | eq(h.encode(), """\ | |
28 | Hello World! =?iso-2022-jp?b?GyRCJU8lbSE8JW8hPCVrJUkhKhsoQg==?= | |
29 | =?iso-8859-1?q?Gr=FC=DF?= =?iso-8859-1?q?_Gott!?=""") | |
30 | eq(decode_header(h.encode()), | |
31 | [('Hello World!', None), | |
32 | ('\x1b$B%O%m!<%o!<%k%I!*\x1b(B', 'iso-2022-jp'), | |
33 | ('Gr\xfc\xdf Gott!', 'iso-8859-1')]) | |
34 | 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' | |
35 | h = Header(long, j, header_name="Subject") | |
36 | # test a very long header | |
37 | enc = h.encode() | |
38 | # TK: splitting point may differ by codec design and/or Header encoding | |
39 | eq(enc , """\ | |
40 | =?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKGyhC?= | |
41 | =?iso-2022-jp?b?GyRCMnE8VCROPjVHJyRyQlQkQyRGJCQkXiQ5GyhC?=""") | |
42 | # TK: full decode comparison | |
43 | eq(h.__unicode__().encode('euc-jp'), long) | |
44 | ||
45 | ||
46 | \f | |
47 | def suite(): | |
48 | suite = unittest.TestSuite() | |
49 | suite.addTest(unittest.makeSuite(TestEmailAsianCodecs)) | |
50 | return suite | |
51 | ||
52 | ||
53 | def test_main(): | |
54 | run_unittest(TestEmailAsianCodecs) | |
55 | ||
56 | ||
57 | \f | |
58 | if __name__ == '__main__': | |
59 | unittest.main(defaultTest='suite') |