MIME type utils method now compatible with multiple version of python-magic
This commit is contained in:
parent
4cd2e6949f
commit
3bd9bec660
1 changed files with 7 additions and 1 deletions
|
@ -224,7 +224,13 @@ def get_mime_type(resource):
|
||||||
with urllib.request.urlopen(resource) as response:
|
with urllib.request.urlopen(resource) as response:
|
||||||
return response.info().get_content_type()
|
return response.info().get_content_type()
|
||||||
else:
|
else:
|
||||||
mime = magic.detect_from_filename(resource)
|
if hasattr(magic, 'detect_from_filename'):
|
||||||
|
mime = magic.detect_from_filename(resource)
|
||||||
|
elif hasattr(magic, 'from_file'):
|
||||||
|
mime = magic.from_file(resource, mime=True)
|
||||||
|
else:
|
||||||
|
raise RuntimeError('The installed magic version provides neither detect_from_filename nor from_file')
|
||||||
|
|
||||||
if mime:
|
if mime:
|
||||||
return mime.mime_type
|
return mime.mime_type
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue