# HG changeset patch # User Cédric Krier # Date 1570791867 -7200 # Node ID ebec469f4baa9523522bb5a81113bf9a381bfc87 # Parent e1b70835bc9eaa1af25f390ead9dee50c8fbf8fe Support file-magic as fallback to python-magic bug53 diff -r e1b70835bc9e -r ebec469f4baa CHANGES --- a/CHANGES Mon Jul 29 16:12:32 2019 +0200 +++ b/CHANGES Fri Oct 11 13:04:27 2019 +0200 @@ -1,3 +1,5 @@ +* Support file-magic as fallback to python-magic + 0.9.0 - 20190729 * Support out parameter of render * Write opendocument stream directly to the ZipFile diff -r e1b70835bc9e -r ebec469f4baa relatorio/templates/opendocument.py --- a/relatorio/templates/opendocument.py Mon Jul 29 16:12:32 2019 +0200 +++ b/relatorio/templates/opendocument.py Fri Oct 11 13:04:27 2019 +0200 @@ -950,7 +950,11 @@ binary_data, = image.xpath( './office:binary-data', namespaces=namespaces) data = base64.b64decode(binary_data.text) - mime_type = magic.from_buffer(data, mime=True) + if hasattr(magic, 'from_buffer'): + mime_type = magic.from_buffer(data, mime=True) + else: + # Not python-magic but file-magic + mime_type = magic.detect_from_content(data).mime_type name = 'Pictures/image%s%s' % ( i, mimetypes.guess_extension(mime_type)) image.remove(binary_data)