Patch #1449244: Support Unicode strings in
email.message.Message.{set_charset,get_content_charset}.
This commit is contained in:
parent
74fb211445
commit
1300831c48
|
@ -238,7 +238,7 @@ class Message:
|
||||||
self.del_param('charset')
|
self.del_param('charset')
|
||||||
self._charset = None
|
self._charset = None
|
||||||
return
|
return
|
||||||
if isinstance(charset, str):
|
if isinstance(charset, basestring):
|
||||||
charset = email.charset.Charset(charset)
|
charset = email.charset.Charset(charset)
|
||||||
if not isinstance(charset, email.charset.Charset):
|
if not isinstance(charset, email.charset.Charset):
|
||||||
raise TypeError(charset)
|
raise TypeError(charset)
|
||||||
|
@ -756,7 +756,9 @@ class Message:
|
||||||
charset = charset[2]
|
charset = charset[2]
|
||||||
# charset character must be in us-ascii range
|
# charset character must be in us-ascii range
|
||||||
try:
|
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:
|
except UnicodeError:
|
||||||
return failobj
|
return failobj
|
||||||
# RFC 2046, $4.1.2 says charsets are not case sensitive
|
# RFC 2046, $4.1.2 says charsets are not case sensitive
|
||||||
|
|
|
@ -502,6 +502,13 @@ class TestMessageAPI(TestEmailBase):
|
||||||
msg.set_payload(x)
|
msg.set_payload(x)
|
||||||
self.assertEqual(msg.get_payload(decode=True), 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
|
# Test the email.Encoders module
|
||||||
|
|
|
@ -202,6 +202,9 @@ Extension Modules
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Patch #1449244: Support Unicode strings in
|
||||||
|
email.message.Message.{set_charset,get_content_charset}.
|
||||||
|
|
||||||
- Patch #1542681: add entries for "with", "as" and "CONTEXTMANAGERS" to
|
- Patch #1542681: add entries for "with", "as" and "CONTEXTMANAGERS" to
|
||||||
pydoc's help keywords.
|
pydoc's help keywords.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue