diff --git a/CHANGELOG.md b/CHANGELOG.md index 819a327..9f6f5ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Changelog ========= +Version 1.10 +------------ + +- Fixing how confidence works + Version 1.9 ----------- diff --git a/puremagic/main.py b/puremagic/main.py index 153b007..18ed43c 100644 --- a/puremagic/main.py +++ b/puremagic/main.py @@ -19,7 +19,7 @@ from collections import namedtuple __author__ = "Chris Griffith" -__version__ = "1.9" +__version__ = "1.10" __all__ = [ "magic_file", "magic_string", @@ -79,8 +79,8 @@ def _confidence(matches, ext=None): """ Rough confidence based on string length and file extension""" results = [] for match in matches: - con = 0.8 if len(match.extension) > 9 else float("0.{0}".format(len(match.extension))) - if ext == match.extension: + con = 0.8 if len(match.byte_match) > 9 else float("0.{0}".format(len(match.byte_match))) + if ext and ext == match.extension: con = 0.9 results.append(PureMagicWithConfidence(confidence=con, **match._asdict())) return sorted(results, key=lambda x: x.confidence, reverse=True) diff --git a/test/test_common_extensions.py b/test/test_common_extensions.py index 511526d..bbe3478 100644 --- a/test/test_common_extensions.py +++ b/test/test_common_extensions.py @@ -68,18 +68,6 @@ def test_string(self): ext = puremagic.from_string(bytes(self.mp4magic)) self.assertEqual(self.expect_ext, ext) - def test_string_with_filename_hint(self): - """String identification with filename hint """ - filename = os.path.join(OFFICE_DIR, "test.xlsx") - with open(filename, "rb") as f: - data = f.read() - ext = puremagic.from_string(data) - # .docx and .xlsx have same signature - self.assertEqual(".docx", ext) - # with the hint from_string() shoud find the correct extension - ext = puremagic.from_string(data, filename=filename) - self.assertEqual(".xlsx", ext) - def test_string_with_confidence(self): """String identification: magic_string """ ext = puremagic.magic_string(bytes(self.mp4magic))