summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2014-02-07 17:46:17 (GMT)
committerR David Murray <rdmurray@bitdance.com>2014-02-07 17:46:17 (GMT)
commit15a693a6f8f5986c512557747112331ceb5c0b8c (patch)
treee85910ccacdbd73c4aabb05b2b2bef3c2311c92d /Lib/test/test_email
parent27e9de669be928b09d71fdd31f84da7b86f9a1fc (diff)
downloadcpython-15a693a6f8f5986c512557747112331ceb5c0b8c.zip
cpython-15a693a6f8f5986c512557747112331ceb5c0b8c.tar.gz
cpython-15a693a6f8f5986c512557747112331ceb5c0b8c.tar.bz2
#20531: Apply the 3.3 version of the #19063 fix.
So passing unicode to set_payload works again (but still doesn't do what you want when the message is serialized).
Diffstat (limited to 'Lib/test/test_email')
-rw-r--r--Lib/test/test_email/test_email.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index c66b524..ce91476 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -92,6 +92,38 @@ class TestMessageAPI(TestEmailBase):
msg.set_payload('This is a string payload', charset)
self.assertEqual(msg.get_charset().input_charset, 'iso-8859-1')
+ def test_set_payload_with_8bit_data_and_charset(self):
+ data = b'\xd0\x90\xd0\x91\xd0\x92'
+ charset = Charset('utf-8')
+ msg = Message()
+ msg.set_payload(data, charset)
+ self.assertEqual(msg['content-transfer-encoding'], 'base64')
+ self.assertEqual(msg.get_payload(decode=True), data)
+ self.assertEqual(msg.get_payload(), '0JDQkdCS\n')
+
+ def test_set_payload_with_non_ascii_and_charset_body_encoding_none(self):
+ data = b'\xd0\x90\xd0\x91\xd0\x92'
+ charset = Charset('utf-8')
+ charset.body_encoding = None # Disable base64 encoding
+ msg = Message()
+ msg.set_payload(data.decode('utf-8'), charset)
+ self.assertEqual(msg['content-transfer-encoding'], '8bit')
+ self.assertEqual(msg.get_payload(decode=True), data)
+
+ def test_set_payload_with_8bit_data_and_charset_body_encoding_none(self):
+ data = b'\xd0\x90\xd0\x91\xd0\x92'
+ charset = Charset('utf-8')
+ charset.body_encoding = None # Disable base64 encoding
+ msg = Message()
+ msg.set_payload(data, charset)
+ self.assertEqual(msg['content-transfer-encoding'], '8bit')
+ self.assertEqual(msg.get_payload(decode=True), data)
+
+ def test_set_payload_to_list(self):
+ msg = Message()
+ msg.set_payload([])
+ self.assertEqual(msg.get_payload(), [])
+
def test_get_charsets(self):
eq = self.assertEqual