diff options
author | Barry Warsaw <barry@python.org> | 2002-10-10 15:14:22 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2002-10-10 15:14:22 (GMT) |
commit | dc8087b26ed7f7c89b8edd75612fa53d8f701eb0 (patch) | |
tree | 682c877d51ba307422bef6e58fd1fb8725641440 | |
parent | ee07cb1d700ef8454fe3d17f1226ad222b77f40f (diff) | |
download | cpython-dc8087b26ed7f7c89b8edd75612fa53d8f701eb0.zip cpython-dc8087b26ed7f7c89b8edd75612fa53d8f701eb0.tar.gz cpython-dc8087b26ed7f7c89b8edd75612fa53d8f701eb0.tar.bz2 |
New tests to verify that charsets are case insensitive, and that by
default get_body_encoding() cannot be SHORTEST.
-rw-r--r-- | Lib/email/test/test_email.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index 5bbb794..daf9e28 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -1689,6 +1689,40 @@ class TestMiscellaneous(unittest.TestCase): filename='foo\\wacky"name') eq(msg.get_filename(), 'foo\\wacky"name') + def test_get_body_encoding_with_bogus_charset(self): + charset = Charset('not a charset') + self.assertEqual(charset.get_body_encoding(), 'base64') + + def test_get_body_encoding_with_uppercase_charset(self): + eq = self.assertEqual + msg = Message() + msg['Content-Type'] = 'text/plain; charset=UTF-8' + eq(msg['content-type'], 'text/plain; charset=UTF-8') + charsets = msg.get_charsets() + eq(len(charsets), 1) + eq(charsets[0], 'utf-8') + charset = Charset(charsets[0]) + eq(charset.get_body_encoding(), 'base64') + msg.set_payload('hello world', charset=charset) + eq(msg.get_payload(), 'hello world') + eq(msg['content-transfer-encoding'], 'base64') + # Try another one + msg = Message() + msg['Content-Type'] = 'text/plain; charset="US-ASCII"' + charsets = msg.get_charsets() + eq(len(charsets), 1) + eq(charsets[0], 'us-ascii') + charset = Charset(charsets[0]) + eq(charset.get_body_encoding(), Encoders.encode_7or8bit) + msg.set_payload('hello world', charset=charset) + eq(msg.get_payload(), 'hello world') + eq(msg['content-transfer-encoding'], '7bit') + + def test_charsets_case_insensitive(self): + lc = Charset('us-ascii') + uc = Charset('US-ASCII') + self.assertEqual(lc.get_body_encoding(), uc.get_body_encoding()) + # Test the iterator/generators |