File tree 3 files changed +14
-2
lines changed 3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -238,7 +238,7 @@ def set_charset(self, charset):
238
238
self .del_param ('charset' )
239
239
self ._charset = None
240
240
return
241
- if isinstance (charset , str ):
241
+ if isinstance (charset , basestring ):
242
242
charset = email .charset .Charset (charset )
243
243
if not isinstance (charset , email .charset .Charset ):
244
244
raise TypeError (charset )
@@ -756,7 +756,9 @@ def get_content_charset(self, failobj=None):
756
756
charset = charset [2 ]
757
757
# charset character must be in us-ascii range
758
758
try :
759
- charset = unicode (charset , 'us-ascii' ).encode ('us-ascii' )
759
+ if isinstance (charset , str ):
760
+ charset = unicode (charset , 'us-ascii' )
761
+ charset = charset .encode ('us-ascii' )
760
762
except UnicodeError :
761
763
return failobj
762
764
# RFC 2046, $4.1.2 says charsets are not case sensitive
Original file line number Diff line number Diff line change @@ -502,6 +502,13 @@ def test_broken_base64_payload(self):
502
502
msg .set_payload (x )
503
503
self .assertEqual (msg .get_payload (decode = True ), x )
504
504
505
+ def test_get_content_charset (self ):
506
+ msg = Message ()
507
+ msg .set_charset ('us-ascii' )
508
+ self .assertEqual ('us-ascii' , msg .get_content_charset ())
509
+ msg .set_charset (u'us-ascii' )
510
+ self .assertEqual ('us-ascii' , msg .get_content_charset ())
511
+
505
512
506
513
507
514
# Test the email.Encoders module
Original file line number Diff line number Diff line change @@ -168,6 +168,9 @@ Core and builtins
168
168
Library
169
169
-------
170
170
171
+ - Patch #1449244: Support Unicode strings in
172
+ email.message.Message.{set_charset,get_content_charset}.
173
+
171
174
- Patch #1542681: add entries for "with", "as" and "CONTEXTMANAGERS" to
172
175
pydoc's help keywords.
173
176
You can’t perform that action at this time.
0 commit comments