summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-12-11 21:34:34 (GMT)
committerR David Murray <rdmurray@bitdance.com>2013-12-11 21:34:34 (GMT)
commitd5c4c7411af644fe7607695eb58ef91fd29066c3 (patch)
tree725b1c22ba6f5acf3cf5a9b7cdfb39e652b2606a /Lib/test/test_email
parent31a655411a79b00517cdcd0a2752824d183db792 (diff)
downloadcpython-d5c4c7411af644fe7607695eb58ef91fd29066c3.zip
cpython-d5c4c7411af644fe7607695eb58ef91fd29066c3.tar.gz
cpython-d5c4c7411af644fe7607695eb58ef91fd29066c3.tar.bz2
#19063: partially fix set_payload handling of non-ASCII string input.
This is a backward compatible partial fix, the complete fix requires raising an error instead of accepting the invalid input, so the real fix is only suitable for 3.4.
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 cd4f757..6af6278 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