summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2018-06-25 21:07:41 +0200
committerHelmut Grohne <helmut@subdivi.de>2018-06-25 21:07:41 +0200
commite77a1ebf8bda10494088bb6c72873d8ef214e0f3 (patch)
treeaaa770d96c7aeb3dfed58de651b37470108dfda3
parent5df1185e5fa0830b546b4ef6af3cdadc655c16c8 (diff)
downloaddebian-dedup-e77a1ebf8bda10494088bb6c72873d8ef214e0f3.tar.gz
adapt to python3-magic/2:0.4.15-1 API
-rw-r--r--dedup/filemagic.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/dedup/filemagic.py b/dedup/filemagic.py
index 4cc9357..c5a6357 100644
--- a/dedup/filemagic.py
+++ b/dedup/filemagic.py
@@ -3,6 +3,12 @@ the file type."""
import magic
+# It changed API a few times...
+try:
+ _magic_identify = magic.from_buffer
+except AttributeError:
+ _magic_identify = magic.none_magic.buffer
+
class FileDigester(object):
"""A hashlib-like class to guess a filetype using the magic module."""
FILE_BYTES_MAX = 1024 * 1024 # copied from file source
@@ -13,7 +19,7 @@ class FileDigester(object):
def _compute_identification(self):
try:
- return magic.none_magic.buffer(self.buff)
+ return _magic_identify(self.buff)
except UnicodeDecodeError:
return "magic identification is not valid UTF-8"