summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-03-14 06:59:51 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-03-14 06:59:51 (GMT)
commit7441a7aedd251d529eb14eff9a16708e9cb32409 (patch)
tree1d525eb5ac468752cacf460b4228a0150ee48814 /Lib/test
parent21c71bac5f684b0ec1665d841d05f91e078c3964 (diff)
downloadcpython-7441a7aedd251d529eb14eff9a16708e9cb32409.zip
cpython-7441a7aedd251d529eb14eff9a16708e9cb32409.tar.gz
cpython-7441a7aedd251d529eb14eff9a16708e9cb32409.tar.bz2
#14291: if a header has non-ascii unicode, default to CTE using utf-8
In Python2, if a unicode string was assigned as the value of a header, email would automatically CTE encode it using the UTF8 charset. This capability was lost in the Python3 translation, and this patch restores it. Patch by Ali Ikinci, assisted by R. David Murray. I also added a fix for the mailbox test that was depending (with a comment that it was a bad idea to so depend) on non-ASCII causing message_from_string to raise an error. It now uses support.patch to induce an error during message serialization.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_mailbox.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index e09aea4..8f76e18 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -111,10 +111,10 @@ class TestMailbox(TestBase):
self.assertMailboxEmpty()
def test_add_that_raises_leaves_mailbox_empty(self):
- # XXX This test will start failing when Message learns to handle
- # non-ASCII string headers, and a different internal failure will
- # need to be found or manufactured.
- with self.assertRaises(ValueError):
+ def raiser(*args, **kw):
+ raise Exception("a fake error")
+ support.patch(self, email.generator.BytesGenerator, 'flatten', raiser)
+ with self.assertRaises(Exception):
self._box.add(email.message_from_string("From: Alphöso"))
self.assertEqual(len(self._box), 0)
self._box.close()