Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / lib / python2.4 / email / test / test_email_codecs.py
CommitLineData
86530b38
AT
1# Copyright (C) 2002 Python Software Foundation
2# email package unit tests for (optional) Asian codecs
3
4import unittest
5from test.test_support import TestSkipped, run_unittest
6
7from email.test.test_email import TestEmailBase
8from email.Charset import Charset
9from email.Header import Header, decode_header
10
11\f
12class 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(), """\
28Hello 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
47def suite():
48 suite = unittest.TestSuite()
49 suite.addTest(unittest.makeSuite(TestEmailAsianCodecs))
50 return suite
51
52
53def test_main():
54 run_unittest(TestEmailAsianCodecs)
55
56
57\f
58if __name__ == '__main__':
59 unittest.main(defaultTest='suite')