diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2007-03-13 10:24:00 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2007-03-13 10:24:00 (GMT) |
commit | bdd0f39de559ddedc9d952020da71a8a6973c34c (patch) | |
tree | 8c007be2896eaaa213a1e9f00f97420962d3c176 /Lib/email | |
parent | 18c47f6a3b3cc848dc2fc09329954378e483dce1 (diff) | |
download | cpython-bdd0f39de559ddedc9d952020da71a8a6973c34c.zip cpython-bdd0f39de559ddedc9d952020da71a8a6973c34c.tar.gz cpython-bdd0f39de559ddedc9d952020da71a8a6973c34c.tar.bz2 |
Patch #1449244: Support Unicode strings in
email.message.Message.{set_charset,get_content_charset}.
Will backport.
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/message.py | 6 | ||||
-rw-r--r-- | Lib/email/test/test_email.py | 7 |
2 files changed, 11 insertions, 2 deletions
diff --git a/Lib/email/message.py b/Lib/email/message.py index 79c5c4c..88ae183 100644 --- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -238,7 +238,7 @@ class Message: self.del_param('charset') self._charset = None return - if isinstance(charset, str): + if isinstance(charset, basestring): charset = email.charset.Charset(charset) if not isinstance(charset, email.charset.Charset): raise TypeError(charset) @@ -756,7 +756,9 @@ class Message: charset = charset[2] # charset character must be in us-ascii range try: - charset = unicode(charset, 'us-ascii').encode('us-ascii') + if isinstance(charset, str): + charset = unicode(charset, 'us-ascii') + charset = charset.encode('us-ascii') except UnicodeError: return failobj # RFC 2046, $4.1.2 says charsets are not case sensitive diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index eb2a73c..14b8a1b 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -502,6 +502,13 @@ class TestMessageAPI(TestEmailBase): msg.set_payload(x) self.assertEqual(msg.get_payload(decode=True), x) + def test_get_content_charset(self): + msg = Message() + msg.set_charset('us-ascii') + self.assertEqual('us-ascii', msg.get_content_charset()) + msg.set_charset(u'us-ascii') + self.assertEqual('us-ascii', msg.get_content_charset()) + # Test the email.Encoders module |