]> granicus.if.org Git - python/commitdiff
Issue #27445: Don't pass str(_charset) to MIMEText.set_payload()
authorBerker Peksag <berker.peksag@gmail.com>
Thu, 8 Sep 2016 16:40:30 +0000 (19:40 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Thu, 8 Sep 2016 16:40:30 +0000 (19:40 +0300)
Patch by Claude Paroz.

Lib/email/mime/text.py
Lib/test/test_email/test_email.py
Misc/NEWS

index 479928ec945d77f092879deb4d70392fa4091f93..da03086ee8a7646c4a8c6a07e2c8eafa4a3c6ef0 100644 (file)
@@ -35,10 +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})
+                                  **{'charset': str(_charset)})
 
         self.set_payload(_text, _charset)
index 1e5366c2a4e69f92ed2ea1e9ee5e988ff5853efe..1d50feb593fa96ba0f5a81389db7419698ff7d90 100644 (file)
@@ -1652,9 +1652,12 @@ class TestMIMEText(unittest.TestCase):
         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'))
+        charset = Charset('utf-8')
+        charset.body_encoding = None
+        msg = MIMEText('hello there', _charset=charset)
         eq(msg.get_charset().input_charset, 'utf-8')
         eq(msg['content-type'], 'text/plain; charset="utf-8"')
+        eq(msg.get_payload(), 'hello there')
 
     def test_7bit_input(self):
         eq = self.assertEqual
index 15818383c4f06819b7ad13bc9ec21232b3a50c8a..a18ceb674e875ca61d16f35e0f2990d7ccb03071 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -60,6 +60,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #27445: Don't pass str(_charset) to MIMEText.set_payload().
+  Patch by Claude Paroz.
+
 - lib2to3.pgen3.driver.load_grammar() now creates a stable cache file
   between runs given the same Grammar.txt input regardless of the hash
   randomization setting.