home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_447 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.7 KB  |  62 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import unittest
  5. from test.test_support import TestSkipped, run_unittest
  6. from email.test.test_email import TestEmailBase
  7. from email.charset import Charset
  8. from email.header import Header, decode_header
  9. from email.message import Message
  10.  
  11. try:
  12.     unicode('foo', 'euc-jp')
  13. except LookupError:
  14.     raise TestSkipped
  15.  
  16.  
  17. class TestEmailAsianCodecs(TestEmailBase):
  18.     
  19.     def test_japanese_codecs(self):
  20.         eq = self.ndiffAssertEqual
  21.         j = Charset('euc-jp')
  22.         g = Charset('iso-8859-1')
  23.         h = Header('Hello World!')
  24.         jhello = '\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc\xa5\xeb\xa5\xc9\xa1\xaa'
  25.         ghello = 'Gr\xfc\xdf Gott!'
  26.         h.append(jhello, j)
  27.         h.append(ghello, g)
  28.         eq(h.encode(), 'Hello World! =?iso-2022-jp?b?GyRCJU8lbSE8JW8hPCVrJUkhKhsoQg==?=\n =?iso-8859-1?q?Gr=FC=DF?= =?iso-8859-1?q?_Gott!?=')
  29.         eq(decode_header(h.encode()), [
  30.             ('Hello World!', None),
  31.             ('\x1b$B%O%m!<%o!<%k%I!*\x1b(B', 'iso-2022-jp'),
  32.             ('Gr\xfc\xdf Gott!', 'iso-8859-1')])
  33.         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'
  34.         h = Header(long, j, header_name = 'Subject')
  35.         enc = h.encode()
  36.         eq(enc, '=?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKGyhC?=\n =?iso-2022-jp?b?GyRCMnE8VCROPjVHJyRyQlQkQyRGJCQkXiQ5GyhC?=')
  37.         eq(h.__unicode__().encode('euc-jp'), long)
  38.  
  39.     
  40.     def test_payload_encoding(self):
  41.         jhello = '\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc\xa5\xeb\xa5\xc9\xa1\xaa'
  42.         jcode = 'euc-jp'
  43.         msg = Message()
  44.         msg.set_payload(jhello, jcode)
  45.         ustr = unicode(msg.get_payload(), msg.get_content_charset())
  46.         self.assertEqual(jhello, ustr.encode(jcode))
  47.  
  48.  
  49.  
  50. def suite():
  51.     suite = unittest.TestSuite()
  52.     suite.addTest(unittest.makeSuite(TestEmailAsianCodecs))
  53.     return suite
  54.  
  55.  
  56. def test_main():
  57.     run_unittest(TestEmailAsianCodecs)
  58.  
  59. if __name__ == '__main__':
  60.     unittest.main(defaultTest = 'suite')
  61.  
  62.