diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2014-09-26 21:57:29 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2014-09-26 21:57:29 (GMT) |
commit | fe21e4d4d76d3fd1efd16d124808d72a69588d7b (patch) | |
tree | 74e47a453633ae97d05f98cf18aeb361edb951e8 /Lib | |
parent | 081bbf6b28868774c1abca0a8469a517abb9f6cc (diff) | |
download | cpython-fe21e4d4d76d3fd1efd16d124808d72a69588d7b.zip cpython-fe21e4d4d76d3fd1efd16d124808d72a69588d7b.tar.gz cpython-fe21e4d4d76d3fd1efd16d124808d72a69588d7b.tar.bz2 |
Issue #16324: _charset parameter of MIMEText now also accepts email.charset.Charset instances.
Initial patch by Claude Paroz.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/email/mime/text.py | 3 | ||||
-rw-r--r-- | Lib/test/test_email/test_email.py | 4 |
2 files changed, 7 insertions, 0 deletions
diff --git a/Lib/email/mime/text.py b/Lib/email/mime/text.py index ec18b85..479928e 100644 --- a/Lib/email/mime/text.py +++ b/Lib/email/mime/text.py @@ -6,6 +6,7 @@ __all__ = ['MIMEText'] +from email.charset import Charset from email.mime.nonmultipart import MIMENonMultipart @@ -34,6 +35,8 @@ class MIMEText(MIMENonMultipart): _charset = 'us-ascii' except UnicodeEncodeError: _charset = 'utf-8' + if isinstance(_charset, Charset): + _charset = str(_charset) MIMENonMultipart.__init__(self, 'text', _subtype, **{'charset': _charset}) diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index c3ecd0ab..d16d461 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -1636,6 +1636,10 @@ class TestMIMEText(unittest.TestCase): msg = MIMEText('hello there', _charset='us-ascii') eq(msg.get_charset().input_charset, 'us-ascii') eq(msg['content-type'], 'text/plain; charset="us-ascii"') + # Also accept a Charset instance + msg = MIMEText('hello there', _charset=Charset('utf-8')) + eq(msg.get_charset().input_charset, 'utf-8') + eq(msg['content-type'], 'text/plain; charset="utf-8"') def test_7bit_input(self): eq = self.assertEqual |