parser_factory
now returns the mtype too
This commit is contained in:
parent
6c29e0eae2
commit
6868f20065
7
main.py
7
main.py
@ -20,9 +20,8 @@ def create_arg_parser():
|
||||
return parser
|
||||
|
||||
def show_meta(filename:str):
|
||||
p = parser_factory.get_parser(filename)
|
||||
p, mtype = parser_factory.get_parser(filename)
|
||||
if p is None:
|
||||
mtype, _ = mimetypes.guess_type(filename)
|
||||
print("[-] %s's format (%s) is not supported" % (filename, mtype))
|
||||
return
|
||||
for k,v in p.get_meta().items():
|
||||
@ -38,9 +37,9 @@ def main():
|
||||
return 0
|
||||
|
||||
for f in args.files:
|
||||
p = parser_factory.get_parser(f)
|
||||
p, mtype = parser_factory.get_parser(f)
|
||||
if p is None:
|
||||
print("[-] %s's format (%s) is not supported" % (f, "meh"))
|
||||
print("[-] %s's format (%s) is not supported" % (f, mtype))
|
||||
continue
|
||||
p.remove_all()
|
||||
|
||||
|
@ -38,9 +38,9 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
|
||||
|
||||
def _clean_internal_file(self, item:zipfile.ZipInfo, temp_folder:str, zin:zipfile.ZipFile, zout:zipfile.ZipFile):
|
||||
zin.extract(member=item, path=temp_folder)
|
||||
tmp_parser = parser_factory.get_parser(os.path.join(temp_folder, item.filename))
|
||||
tmp_parser, mtype = parser_factory.get_parser(os.path.join(temp_folder, item.filename))
|
||||
if tmp_parser is None:
|
||||
print("%s isn't supported" % item.filename)
|
||||
print("%s's format (%s) isn't supported" % (item.filename, mtype))
|
||||
return
|
||||
tmp_parser.remove_all()
|
||||
zinfo = zipfile.ZipInfo(item.filename)
|
||||
|
@ -15,6 +15,6 @@ def get_parser(filename: str):
|
||||
mtype, _ = mimetypes.guess_type(filename)
|
||||
for c in abstract.AbstractParser.__subclasses__():
|
||||
if mtype in c.mimetypes:
|
||||
return c(filename)
|
||||
return c(filename), mtype
|
||||
print('factory: %s is not supported' % mtype)
|
||||
return None
|
||||
return None, mtype
|
||||
|
@ -72,7 +72,7 @@ class TestDeepCleaning(unittest.TestCase):
|
||||
for subdir, dirs, files in os.walk(tempdir):
|
||||
for f in files:
|
||||
complete_path = os.path.join(subdir, f)
|
||||
inside_p = parser_factory.get_parser(complete_path)
|
||||
inside_p, _ = parser_factory.get_parser(complete_path)
|
||||
if inside_p is None:
|
||||
continue
|
||||
print('[+] %s is clean inside %s' %(complete_path, p.filename))
|
||||
|
Loading…
Reference in New Issue
Block a user