summaryrefslogtreecommitdiff
path: root/alot/helper.py
diff options
context:
space:
mode:
authorHamish Downer <dmishd@gmail.com>2013-04-02 22:28:33 +0100
committerHamish Downer <dmishd@gmail.com>2013-04-02 22:28:33 +0100
commit799372199ea53c2291a4471d6523a373633a859d (patch)
tree86718dcd4f8898788b4db5956aac6b3adbdc44e1 /alot/helper.py
parent7a9da3b0fcc0edca4fcfd8bf0818992dea88a5fc (diff)
Support two different versions of magic
The API for magic has changed at some point. Debian and Ubuntu still have an old version, but only the new version can be installed via pip. This commit allows us to use either version.
Diffstat (limited to 'alot/helper.py')
-rw-r--r--alot/helper.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/alot/helper.py b/alot/helper.py
index 7f288a4d..9eede32d 100644
--- a/alot/helper.py
+++ b/alot/helper.py
@@ -391,9 +391,14 @@ def guess_encoding(blob):
:returns: encoding
:rtype: str
"""
- m = magic.open(magic.MAGIC_MIME_ENCODING)
- m.load()
- return m.buffer(blob)
+ if hasattr(magic, 'open'):
+ m = magic.open(magic.MAGIC_MIME_TYPE)
+ m.load()
+ return m.buffer(blob)
+ elif hasattr(magic, 'from_buffer'):
+ return magic.from_buffer(blob, mime=True)
+ else:
+ raise Exception('Unknown magic API')
# TODO: make this work on blobs, not paths