[diffoscope] 01/03: If both RE_FILE_TYPE and RE_FILE_EXTENSION are defined, AND them

Mattia Rizzolo mattia at debian.org
Mon Jan 16 16:18:50 CET 2017


This is an automated email from the git hooks/post-receive script.

mattia pushed a commit to branch master
in repository diffoscope.

commit 4dc30c24e57177d44e75dbbb8fd054e98bc406ca
Author: Mattia Rizzolo <mattia at debian.org>
Date:   Mon Jan 16 16:04:49 2017 +0100

    If both RE_FILE_TYPE and RE_FILE_EXTENSION are defined, AND them
---
 diffoscope/comparators/apk.py              |  5 -----
 diffoscope/comparators/utils/specialize.py | 12 +++++++++---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/diffoscope/comparators/apk.py b/diffoscope/comparators/apk.py
index dc65302..65e9773 100644
--- a/diffoscope/comparators/apk.py
+++ b/diffoscope/comparators/apk.py
@@ -93,11 +93,6 @@ class ApkFile(File):
     RE_FILE_EXTENSION = re.compile(r'\.apk$')
     CONTAINER_CLASS = ApkContainer
 
-    @staticmethod
-    def recognizes(file):
-        return ApkFile.RE_FILE_TYPE.match(file.magic_file_type) and \
-            ApkFile.RE_FILE_EXTENSION.search(file.name)
-
     def compare_details(self, other, source=None):
         zipinfo_difference = Difference.from_command(Zipinfo, self.path, other.path) or \
                              Difference.from_command(ZipinfoVerbose, self.path, other.path)
diff --git a/diffoscope/comparators/utils/specialize.py b/diffoscope/comparators/utils/specialize.py
index a30818d..d173ee0 100644
--- a/diffoscope/comparators/utils/specialize.py
+++ b/diffoscope/comparators/utils/specialize.py
@@ -39,10 +39,16 @@ def specialize(file):
                 flag = cls.recognizes(file)
         else:
             # No recognizes() method specified, try an auto recognition
-            if hasattr(cls, 'RE_FILE_TYPE'):
-                flag = bool(cls.RE_FILE_TYPE.search(file.magic_file_type))
+            def search_type(file):
+                return bool(cls.RE_FILE_TYPE.search(file.magic_file_type))
+            def search_ext(file):
+                return bool(cls.RE_FILE_EXTENSION.search(file.name))
+            if hasattr(cls, 'RE_FILE_TYPE') and hasattr(cls, 'RE_FILE_EXTENSION'):
+                flag = search_type(file) and search_ext(file)
+            elif hasattr(cls, 'RE_FILE_TYPE'):
+                flag = search_type(file)
             elif hasattr(cls, 'RE_FILE_EXTENSION'):
-                flag = bool(cls.RE_FILE_EXTENSION.search(file.name))
+                flag = search_ext(file)
 
         if not flag:
             continue

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list