diff --git a/libmat2/office.py b/libmat2/office.py index d067128..1a793b4 100644 --- a/libmat2/office.py +++ b/libmat2/office.py @@ -525,7 +525,7 @@ class MSOfficeParser(ZipParser): # see: https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/mc-ignorable-attribute with open(full_path, 'rb') as f: text = f.read() - out = re.sub(b'mc:Ignorable="[^"]*"', b'', text, 1) + out = re.sub(b'mc:Ignorable="[^"]*"', b'', text, count=1) with open(full_path, 'wb') as f: f.write(out) diff --git a/libmat2/pdf.py b/libmat2/pdf.py index 2da21b5..0672214 100644 --- a/libmat2/pdf.py +++ b/libmat2/pdf.py @@ -136,8 +136,8 @@ class PDFParser(abstract.AbstractParser): # It should(tm) be alright though, because cairo's output format # for metadata is fixed. with open(out_file, 'rb') as f: - out = re.sub(rb'<<[\s\n]*/Producer.*?>>', b' << >>', f.read(), 0, - re.DOTALL | re.IGNORECASE) + out = re.sub(rb'<<[\s\n]*/Producer.*?>>', b' << >>', f.read(), + count=0, flags=re.DOTALL | re.IGNORECASE) with open(out_file, 'wb') as f: f.write(out) diff --git a/libmat2/web.py b/libmat2/web.py index e33288e..9bbd221 100644 --- a/libmat2/web.py +++ b/libmat2/web.py @@ -20,7 +20,7 @@ class CSSParser(abstract.AbstractParser): content = f.read() except UnicodeDecodeError: # pragma: no cover raise ValueError - cleaned = re.sub(r'/\*.*?\*/', '', content, 0, self.flags) + cleaned = re.sub(r'/\*.*?\*/', '', content, count=0, flags=self.flags) with open(self.output_filename, 'w', encoding='utf-8') as f: f.write(cleaned) return True diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py index 7855062..1925201 100644 --- a/tests/test_libmat2.py +++ b/tests/test_libmat2.py @@ -508,8 +508,11 @@ class TestCleaning(unittest.TestCase): 'TrackID': 1, 'TrackLayer': 0, 'TransferCharacteristics': 'BT.709', - 'VideoFullRangeFlag': 0, + 'VideoFullRangeFlag': 'Limited', }, + 'extra_expected_meta': { + 'VideoFullRangeFlag': 0, + } },{ 'name': 'wmv', 'ffmpeg': 1, @@ -522,7 +525,10 @@ class TestCleaning(unittest.TestCase): 'name': 'heic', 'parser': images.HEICParser, 'meta': {}, - 'expected_meta': {}, + 'expected_meta': { + 'ExifByteOrder': 'Big-endian (Motorola, MM)', + 'Warning': 'Bad IFD0 directory', + }, } ] @@ -558,7 +564,12 @@ class TestCleaning(unittest.TestCase): if meta: for k, v in p2.get_meta().items(): self.assertIn(k, case['expected_meta'], '"%s" is not in "%s" (%s)' % (k, case['expected_meta'], case['name'])) - self.assertIn(str(case['expected_meta'][k]), str(v)) + if str(case['expected_meta'][k]) in str(v): + continue + if 'extra_expected_meta' in case and k in case['extra_expected_meta']: + if str(case['extra_expected_meta'][k]) in str(v): + continue + self.assertTrue(False, "got a different value (%s) than excepted (%s) for %s" % (str(v), meta, k)) self.assertTrue(p2.remove_all()) os.remove(target)