summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libmat2/office.py2
-rw-r--r--libmat2/pdf.py4
-rw-r--r--libmat2/web.py2
-rw-r--r--tests/test_libmat2.py17
4 files changed, 18 insertions, 7 deletions
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):
525 # see: https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/mc-ignorable-attribute 525 # see: https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/mc-ignorable-attribute
526 with open(full_path, 'rb') as f: 526 with open(full_path, 'rb') as f:
527 text = f.read() 527 text = f.read()
528 out = re.sub(b'mc:Ignorable="[^"]*"', b'', text, 1) 528 out = re.sub(b'mc:Ignorable="[^"]*"', b'', text, count=1)
529 with open(full_path, 'wb') as f: 529 with open(full_path, 'wb') as f:
530 f.write(out) 530 f.write(out)
531 531
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):
136 # It should(tm) be alright though, because cairo's output format 136 # It should(tm) be alright though, because cairo's output format
137 # for metadata is fixed. 137 # for metadata is fixed.
138 with open(out_file, 'rb') as f: 138 with open(out_file, 'rb') as f:
139 out = re.sub(rb'<<[\s\n]*/Producer.*?>>', b' << >>', f.read(), 0, 139 out = re.sub(rb'<<[\s\n]*/Producer.*?>>', b' << >>', f.read(),
140 re.DOTALL | re.IGNORECASE) 140 count=0, flags=re.DOTALL | re.IGNORECASE)
141 with open(out_file, 'wb') as f: 141 with open(out_file, 'wb') as f:
142 f.write(out) 142 f.write(out)
143 143
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):
20 content = f.read() 20 content = f.read()
21 except UnicodeDecodeError: # pragma: no cover 21 except UnicodeDecodeError: # pragma: no cover
22 raise ValueError 22 raise ValueError
23 cleaned = re.sub(r'/\*.*?\*/', '', content, 0, self.flags) 23 cleaned = re.sub(r'/\*.*?\*/', '', content, count=0, flags=self.flags)
24 with open(self.output_filename, 'w', encoding='utf-8') as f: 24 with open(self.output_filename, 'w', encoding='utf-8') as f:
25 f.write(cleaned) 25 f.write(cleaned)
26 return True 26 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):
508 'TrackID': 1, 508 'TrackID': 1,
509 'TrackLayer': 0, 509 'TrackLayer': 0,
510 'TransferCharacteristics': 'BT.709', 510 'TransferCharacteristics': 'BT.709',
511 'VideoFullRangeFlag': 0, 511 'VideoFullRangeFlag': 'Limited',
512 }, 512 },
513 'extra_expected_meta': {
514 'VideoFullRangeFlag': 0,
515 }
513 },{ 516 },{
514 'name': 'wmv', 517 'name': 'wmv',
515 'ffmpeg': 1, 518 'ffmpeg': 1,
@@ -522,7 +525,10 @@ class TestCleaning(unittest.TestCase):
522 'name': 'heic', 525 'name': 'heic',
523 'parser': images.HEICParser, 526 'parser': images.HEICParser,
524 'meta': {}, 527 'meta': {},
525 'expected_meta': {}, 528 'expected_meta': {
529 'ExifByteOrder': 'Big-endian (Motorola, MM)',
530 'Warning': 'Bad IFD0 directory',
531 },
526 } 532 }
527 ] 533 ]
528 534
@@ -558,7 +564,12 @@ class TestCleaning(unittest.TestCase):
558 if meta: 564 if meta:
559 for k, v in p2.get_meta().items(): 565 for k, v in p2.get_meta().items():
560 self.assertIn(k, case['expected_meta'], '"%s" is not in "%s" (%s)' % (k, case['expected_meta'], case['name'])) 566 self.assertIn(k, case['expected_meta'], '"%s" is not in "%s" (%s)' % (k, case['expected_meta'], case['name']))
561 self.assertIn(str(case['expected_meta'][k]), str(v)) 567 if str(case['expected_meta'][k]) in str(v):
568 continue
569 if 'extra_expected_meta' in case and k in case['extra_expected_meta']:
570 if str(case['extra_expected_meta'][k]) in str(v):
571 continue
572 self.assertTrue(False, "got a different value (%s) than excepted (%s) for %s" % (str(v), meta, k))
562 self.assertTrue(p2.remove_all()) 573 self.assertTrue(p2.remove_all())
563 574
564 os.remove(target) 575 os.remove(target)