[diffoscope] 02/05: Move parsing to JSONFile.recognizes

Chris Lamb chris at chris-lamb.co.uk
Sat Aug 6 21:10:01 CEST 2016


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

lamby pushed a commit to branch master
in repository diffoscope.

commit e4c2d9c6a89a6e5021f00038a341875f57e6ff04
Author: Chris Lamb <lamby at debian.org>
Date:   Sat Aug 6 20:08:59 2016 +0100

    Move parsing to JSONFile.recognizes
---
 diffoscope/comparators/json.py | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/diffoscope/comparators/json.py b/diffoscope/comparators/json.py
index 055a2a7..a1235c6 100644
--- a/diffoscope/comparators/json.py
+++ b/diffoscope/comparators/json.py
@@ -29,16 +29,18 @@ class JSONFile(File):
 
     @staticmethod
     def recognizes(file):
-        return JSONFile.RE_FILE_EXTENSION.search(file.name)
+        if JSONFile.RE_FILE_EXTENSION.search(file.name) is None:
+            return False
 
-    def compare_details(self, other, source=None):
-        def dumps(path):
-            with open(path) as f:
-                return json.dumps(json.load(f), indent=4, sort_keys=True)
+        with open(file.path) as f:
+            file.parsed = json.load(f)
+
+        return True
 
+    def compare_details(self, other, source=None):
         return [Difference.from_text(
-            dumps(self.path),
-            dumps(other.path),
+            json.dumps(self.parsed, indent=4, sort_keys=True),
+            json.dumps(other.parsed, indent=4, sort_keys=True),
             self,
             other,
         )]

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


More information about the diffoscope mailing list