From e77a1ebf8bda10494088bb6c72873d8ef214e0f3 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Mon, 25 Jun 2018 21:07:41 +0200 Subject: adapt to python3-magic/2:0.4.15-1 API --- dedup/filemagic.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'dedup') 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" -- cgit v1.2.3