From 3bd9bec660550ac4f8b1b8935af57d96943f7d8e Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 21 Jun 2019 13:40:45 +0200 Subject: [PATCH] MIME type utils method now compatible with multiple version of python-magic --- platypush/utils/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/platypush/utils/__init__.py b/platypush/utils/__init__.py index 49cf6a169..292ac15ee 100644 --- a/platypush/utils/__init__.py +++ b/platypush/utils/__init__.py @@ -224,7 +224,13 @@ def get_mime_type(resource): with urllib.request.urlopen(resource) as response: return response.info().get_content_type() 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: return mime.mime_type