Significantly improve portability
This commit is contained in:
parent
70d236a062
commit
6c966f2afa
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user