# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import division, absolute_import, with_statement, print_function, unicode_literals
try:
    import magic
except:
    print("python-magic module not installed...")
    magic = False

__author__ = "Drew Bonasera"
__license__ = "MPL 2.0"

TYPE = "Metadata"
NAME = "libmagic"
DEFAULTCONF = {
    'magicfile':None,
    'ENABLED': True
    }

def check(conf=DEFAULTCONF):
    if not conf['ENABLED']:
        return False
    if magic:
        return True
    else:
        return False

def scan(filelist, conf=DEFAULTCONF):
    if conf['magicfile']:
        try:
            maaagic = magic.Magic(magic_file=conf['magicfile'])
        except:
            print("ERROR: Failed to use magic file", conf['magicfile'])
            maaagic = magic.Magic()
    else:
        maaagic = magic.Magic()
    results = []
    for fname in filelist:
        results.append((fname, maaagic.from_file(fname).decode('UTF-8', 'replace')))

    metadata = {}
    metadata["Name"] = NAME
    metadata["Type"] = TYPE
    metadata["Include"] = False
    return (results, metadata)


@@ -1097,24 +1097,10 @@
 sult
-s.append((fname,
+ =
  maa
@@ -1124,35 +1124,144 @@
 ame)
-.decode('UTF-8', 'replace')
+%0D%0A        if not isinstance(result, str):%0D%0A            result = result.decode('UTF-8', 'replace')%0D%0A        results.append((fname, result
 ))%0D%0A
@@ -1368,24 +1368,24 @@
 %22%5D = False%0D%0A
+
     return (
@@ -1404,10 +1404,8 @@
 adata)%0D%0A
-%0D%0A

Fix #21