Back to index

python3.2  3.2.2
Public Member Functions
email.test.test_email_codecs.TestEmailAsianCodecs Class Reference
Inheritance diagram for email.test.test_email_codecs.TestEmailAsianCodecs:
Inheritance graph
[legend]
Collaboration diagram for email.test.test_email_codecs.TestEmailAsianCodecs:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_japanese_codecs
def test_payload_encoding_utf8
def test_payload_encoding
def ndiffAssertEqual

Detailed Description

Definition at line 22 of file test_email_codecs.py.


Member Function Documentation

def email.test.test_email.TestEmailBase.ndiffAssertEqual (   self,
  first,
  second 
) [inherited]
Like assertEqual except use ndiff for readable output.

Definition at line 57 of file test_email.py.

00057 
00058     def ndiffAssertEqual(self, first, second):
00059         """Like assertEqual except use ndiff for readable output."""
00060         if first != second:
00061             sfirst = str(first)
00062             ssecond = str(second)
00063             rfirst = [repr(line) for line in sfirst.splitlines()]
00064             rsecond = [repr(line) for line in ssecond.splitlines()]
00065             diff = difflib.ndiff(rfirst, rsecond)
00066             raise self.failureException(NL + NL.join(diff))

Here is the call graph for this function:

Definition at line 23 of file test_email_codecs.py.

00023 
00024     def test_japanese_codecs(self):
00025         eq = self.ndiffAssertEqual
00026         jcode = "euc-jp"
00027         gcode = "iso-8859-1"
00028         j = Charset(jcode)
00029         g = Charset(gcode)
00030         h = Header("Hello World!")
00031         jhello = str(b'\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc'
00032                      b'\xa5\xeb\xa5\xc9\xa1\xaa', jcode)
00033         ghello = str(b'Gr\xfc\xdf Gott!', gcode)
00034         h.append(jhello, j)
00035         h.append(ghello, g)
00036         # BAW: This used to -- and maybe should -- fold the two iso-8859-1
00037         # chunks into a single encoded word.  However it doesn't violate the
00038         # standard to have them as two encoded chunks and maybe it's
00039         # reasonable <wink> for each .append() call to result in a separate
00040         # encoded word.
00041         eq(h.encode(), """\
00042 Hello World! =?iso-2022-jp?b?GyRCJU8lbSE8JW8hPCVrJUkhKhsoQg==?=
00043  =?iso-8859-1?q?Gr=FC=DF_Gott!?=""")
00044         eq(decode_header(h.encode()),
00045            [(b'Hello World!', None),
00046             (b'\x1b$B%O%m!<%o!<%k%I!*\x1b(B', 'iso-2022-jp'),
00047             (b'Gr\xfc\xdf Gott!', gcode)])
00048         subject_bytes = (b'test-ja \xa4\xd8\xc5\xea\xb9\xc6\xa4\xb5'
00049             b'\xa4\xec\xa4\xbf\xa5\xe1\xa1\xbc\xa5\xeb\xa4\xcf\xbb\xca\xb2'
00050             b'\xf1\xbc\xd4\xa4\xce\xbe\xb5\xc7\xa7\xa4\xf2\xc2\xd4\xa4\xc3'
00051             b'\xa4\xc6\xa4\xa4\xa4\xde\xa4\xb9')
00052         subject = str(subject_bytes, jcode)
00053         h = Header(subject, j, header_name="Subject")
00054         # test a very long header
00055         enc = h.encode()
00056         # TK: splitting point may differ by codec design and/or Header encoding
00057         eq(enc , """\
00058 =?iso-2022-jp?b?dGVzdC1qYSAbJEIkWEVqOUYkNSRsJD8lYSE8JWskTztKGyhC?=
00059  =?iso-2022-jp?b?GyRCMnE8VCROPjVHJyRyQlQkQyRGJCQkXiQ5GyhC?=""")
00060         # TK: full decode comparison
00061         eq(str(h).encode(jcode), subject_bytes)

Here is the call graph for this function:

Definition at line 70 of file test_email_codecs.py.

00070 
00071     def test_payload_encoding(self):
00072         jcode  = 'euc-jp'
00073         jhello = str(b'\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc'
00074                      b'\xa5\xeb\xa5\xc9\xa1\xaa', jcode)
00075         msg = Message()
00076         msg.set_payload(jhello, jcode)
00077         ustr = msg.get_payload(decode=True).decode(msg.get_content_charset())
00078         self.assertEqual(jhello, ustr)
00079 
00080 


Here is the call graph for this function:

Definition at line 62 of file test_email_codecs.py.

00062 
00063     def test_payload_encoding_utf8(self):
00064         jhello = str(b'\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc'
00065                      b'\xa5\xeb\xa5\xc9\xa1\xaa', 'euc-jp')
00066         msg = Message()
00067         msg.set_payload(jhello, 'utf-8')
00068         ustr = msg.get_payload(decode=True).decode(msg.get_content_charset())
00069         self.assertEqual(jhello, ustr)

Here is the call graph for this function:


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