get_content_charset(): RFC 2046 $4.1.2 says charsets are not case
sensitive. Coerce the argument to lower case.
This commit is contained in:
parent
14fc464ec9
commit
ee07cb1d70
|
@ -760,8 +760,9 @@ class Message:
|
||||||
def get_content_charset(self, failobj=None):
|
def get_content_charset(self, failobj=None):
|
||||||
"""Return the charset parameter of the Content-Type header.
|
"""Return the charset parameter of the Content-Type header.
|
||||||
|
|
||||||
If there is no Content-Type header, or if that header has no charset
|
The returned string is always coerced to lower case. If there is no
|
||||||
parameter, failobj is returned.
|
Content-Type header, or if that header has no charset parameter,
|
||||||
|
failobj is returned.
|
||||||
"""
|
"""
|
||||||
missing = []
|
missing = []
|
||||||
charset = self.get_param('charset', missing)
|
charset = self.get_param('charset', missing)
|
||||||
|
@ -769,8 +770,9 @@ class Message:
|
||||||
return failobj
|
return failobj
|
||||||
if isinstance(charset, TupleType):
|
if isinstance(charset, TupleType):
|
||||||
# RFC 2231 encoded, so decode it, and it better end up as ascii.
|
# RFC 2231 encoded, so decode it, and it better end up as ascii.
|
||||||
return unicode(charset[2], charset[0]).encode('us-ascii')
|
charset = unicode(charset[2], charset[0]).encode('us-ascii')
|
||||||
return charset
|
# RFC 2046, $4.1.2 says charsets are not case sensitive
|
||||||
|
return charset.lower()
|
||||||
|
|
||||||
def get_charsets(self, failobj=None):
|
def get_charsets(self, failobj=None):
|
||||||
"""Return a list containing the charset(s) used in this message.
|
"""Return a list containing the charset(s) used in this message.
|
||||||
|
|
Loading…
Reference in New Issue