[diffoscope] 04/04: Save some complicated logic by setting default RE_FILE_{EXTENSION, TYPE}
Chris Lamb
chris at chris-lamb.co.uk
Tue Jan 17 01:13:39 CET 2017
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository diffoscope.
commit 36d1c9647d0cc68a4413462dfa6cde69591f5418
Author: Chris Lamb <lamby at debian.org>
Date: Tue Jan 17 09:05:59 2017 +1100
Save some complicated logic by setting default RE_FILE_{EXTENSION,TYPE}
Signed-off-by: Chris Lamb <lamby at debian.org>
---
diffoscope/comparators/utils/file.py | 3 +++
diffoscope/comparators/utils/specialize.py | 13 ++-----------
2 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/diffoscope/comparators/utils/file.py b/diffoscope/comparators/utils/file.py
index 25c0f1a..1c59df8 100644
--- a/diffoscope/comparators/utils/file.py
+++ b/diffoscope/comparators/utils/file.py
@@ -40,6 +40,9 @@ logger = logging.getLogger(__name__)
class File(object, metaclass=abc.ABCMeta):
+ RE_FILE_TYPE = re.compile(r'.*')
+ RE_FILE_EXTENSION = re.compile(r'.*')
+
if hasattr(magic, 'open'): # use Magic-file-extensions from file
@classmethod
def guess_file_type(self, path):
diff --git a/diffoscope/comparators/utils/specialize.py b/diffoscope/comparators/utils/specialize.py
index d173ee0..b30c707 100644
--- a/diffoscope/comparators/utils/specialize.py
+++ b/diffoscope/comparators/utils/specialize.py
@@ -38,17 +38,8 @@ def specialize(file):
with profile('recognizes', file):
flag = cls.recognizes(file)
else:
- # No recognizes() method specified, try an auto recognition
- 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 = search_ext(file)
+ flag = cls.RE_FILE_TYPE.search(file.magic_file_type) and \
+ cls.RE_FILE_EXTENSION.search(file.name)
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