summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/email/mime/text.py3
-rw-r--r--Lib/test/test_email/test_email.py4
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