[Git][reproducible-builds/diffoscope][master] 6 commits: comparators.json: Use File.file_header to tidy JSON matching.

Chris Lamb gitlab at salsa.debian.org
Sat Dec 15 23:15:33 CET 2018


Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
f581b2dd by Chris Lamb at 2018-12-15T21:58:56Z
comparators.json: Use File.file_header to tidy JSON matching.

- - - - -
f0ae5eba by Chris Lamb at 2018-12-15T22:00:19Z
comparators.ppu: Use file_header to simplify magic detection and version parsing.

- - - - -
aa55c7f8 by Chris Lamb at 2018-12-15T22:00:50Z
compators.wasm: Use File.file_header to simplify file detection.

- - - - -
237ca36e by Chris Lamb at 2018-12-15T22:01:18Z
Correct "positives" typo.

- - - - -
7472c24a by Chris Lamb at 2018-12-15T22:04:56Z
Drop debbindiff Breaks/Replaces; was removed in 2015, never part of a stable release, etc.

- - - - -
5f50be79 by Chris Lamb at 2018-12-15T22:05:52Z
Fix a test_mozzip_compressed_files test failure under Alpine Linux. (Closes: #916353, reproducible-builds/diffoscope#8)

- - - - -


6 changed files:

- debian/control
- diffoscope/comparators/fsimage.py
- diffoscope/comparators/json.py
- diffoscope/comparators/ppu.py
- diffoscope/comparators/wasm.py
- tests/comparators/test_zip.py


Changes:

=====================================
debian/control
=====================================
@@ -89,10 +89,6 @@ Package: diffoscope
 Architecture: all
 Suggests:
  libjs-jquery,
-Breaks:
- debbindiff (<< 29),
-Replaces:
- debbindiff (<< 29),
 Depends:
  python3-distutils | libpython3.5-stdlib | libpython3.6-stdlib (<< 3.6.5~rc1-2),
  python3-pkg-resources,


=====================================
diffoscope/comparators/fsimage.py
=====================================
@@ -83,7 +83,7 @@ class FsImageFile(File):
 
     @classmethod
     def recognizes(cls, file):
-        # Avoid DOS / MBR file type as it generate a lot of false possitives,
+        # Avoid DOS / MBR file type as it generate a lot of false positives,
         # manually check "System identifier string" instead
         with open(file.path, 'rb') as f:
             f.seek(54)


=====================================
diffoscope/comparators/json.py
=====================================
@@ -35,14 +35,12 @@ class JSONFile(File):
 
     @classmethod
     def recognizes(cls, file):
-        with open(file.path, 'rb') as f:
-            # Try fuzzy matching for JSON files
-            if not file.name.endswith('.json'):
-                buf = f.read(10)
-                if not any(x in buf for x in b'{['):
-                    return False
-                f.seek(0)
+        # Try fuzzy matching for files not called .json
+        if not file.name.endswith('.json'):
+            if b'{' not in file.file_header or b'[' not in file.file_header:
+                return False
 
+        with open(file.path, 'rb') as f:
             try:
                 file.parsed = json.loads(
                     f.read().decode('utf-8', errors='ignore'),


=====================================
diffoscope/comparators/ppu.py
=====================================
@@ -65,11 +65,12 @@ class PpuFile(File):
     def recognizes(cls, file):
         if not super().recognizes(file):
             return False
-        with open(file.path, 'rb') as f:
-            magic = f.read(3)
-            if magic != b"PPU":
-                return False
-            ppu_version = f.read(3).decode('ascii', errors='ignore')
+
+        if file.file_header.startswith(b'PPU'):
+            return False
+
+        ppu_version = f.file_header[3:6].decode('ascii', errors='ignore')
+
         if not hasattr(PpuFile, 'ppu_version'):
             try:
                 with profile('command', 'ppudump'):


=====================================
diffoscope/comparators/wasm.py
=====================================
@@ -42,9 +42,8 @@ class WasmFile(File):
     def recognizes(cls, file):
         if not super().recognizes(file):
             return False
-        with open(file.path, 'rb') as f:
-            magic = f.read(4)
-            return magic == WASM_MAGIC
+
+        return file.file_header.startswith(WASM_MAGIC)
 
     def compare_details(self, other, source=None):
         return [Difference.from_command(Wasm2Wat, self.path, other.path)]


=====================================
tests/comparators/test_zip.py
=====================================
@@ -105,10 +105,10 @@ def test_mozzip_metadata(mozzip_differences, mozzip1, mozzip2):
 
 @skip_unless_tools_exist('zipinfo')
 def test_mozzip_compressed_files(mozzip_differences):
-    assert mozzip_differences[1].source1 == 'dir/text'
-    assert mozzip_differences[1].source2 == 'dir/text'
+    assert mozzip_differences[-1].source1 == 'dir/text'
+    assert mozzip_differences[-1].source2 == 'dir/text'
     expected_diff = get_data('text_ascii_expected_diff')
-    assert mozzip_differences[1].unified_diff == expected_diff
+    assert mozzip_differences[-1].unified_diff == expected_diff
 
 
 @skip_unless_tools_exist('zipinfo')



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/compare/f0bf14f2cc772cbdb336908a31d18a4ab3f058f6...5f50be792e0fed289c4470fc668ebb613723cb89

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/compare/f0bf14f2cc772cbdb336908a31d18a4ab3f058f6...5f50be792e0fed289c4470fc668ebb613723cb89
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20181215/6fd060ea/attachment.html>


More information about the rb-commits mailing list