Fixed Content-Type retrieval for Python 3.

This commit is contained in:
Jakub Roztocil 2013-04-12 14:01:24 -03:00
parent 72cf7c2cb7
commit 289e9b844e
2 changed files with 10 additions and 1 deletions

View File

@ -116,6 +116,9 @@ def filename_from_url(url, content_type):
else:
ext = mimetypes.guess_extension(content_type)
if ext == '.htm': # Python 3
ext = '.html'
if ext:
fn += ext

View File

@ -87,7 +87,13 @@ class HTTPMessage(object):
@property
def content_type(self):
"""Return the message content type."""
ct = self._orig.headers.get('Content-Type', '')
ct = self._orig.headers.get(
b'Content-Type',
self._orig.headers.get(
'Content-Type',
''
)
)
if isinstance(ct, bytes):
ct = ct.decode()
return ct