Skip to content
Snippets Groups Projects
Commit 5263e5b6 authored by Simon Magnin-Feysot's avatar Simon Magnin-Feysot
Browse files

refactor code and make it more recursive !

parent ebfa0fca
No related branches found
No related tags found
No related merge requests found
Pipeline #19545 failed
...@@ -63,34 +63,30 @@ def show_meta(filename: str): ...@@ -63,34 +63,30 @@ def show_meta(filename: str):
return return
p, mtype = parser_factory.get_parser(filename) # type: ignore p, mtype = parser_factory.get_parser(filename) # type: ignore
print("[+] Metadata for %s:" % filename)
metadata = p.get_meta().items()
if p is None: if p is None:
print("[-] %s's format (%s) is not supported" % (filename, mtype)) print("[-] %s's format (%s) is not supported" % (filename, mtype))
return return
print_meta(metadata)
print("[+] Metadata for %s:" % filename)
metadata = p.get_meta().items() def print_meta(metadata: dict):
if not metadata: if not metadata:
print(" No metadata found") print(" No metadata found")
return return
for k, v in metadata: for k, v in metadata:
zipmeta = v zipmeta = v
zipmeta_name = v zipmeta_name = k
try: # FIXME this is ugly. try: # FIXME this is ugly.
if not isinstance(zipmeta, dict): if not isinstance(zipmeta, dict):
print(" %s: %s" % (k, v)) print(" %s: %s" % (k, v))
else:
print_meta(v)
except UnicodeEncodeError: except UnicodeEncodeError:
print(" %s: harmful content" % k) print(" %s: harmful content" % k)
if mtype in recursive_mtype:
print("[+] Metadata for files inside the archive :")
if isinstance(zipmeta, dict):
for name, metas in zipmeta.items():
try: # FIXME this is ugly.
print(" %s" % name)
for meta_name, meta in metas.items():
print(" %s: %s" % (meta_name, meta))
except UnicodeEncodeError:
print(" %s: harmful content" % zipmeta_name)
def clean_meta(filename: str, is_lightweight: bool, policy: UnknownMemberPolicy) -> bool: def clean_meta(filename: str, is_lightweight: bool, policy: UnknownMemberPolicy) -> bool:
if not __check_file(filename, os.R_OK|os.W_OK): if not __check_file(filename, os.R_OK|os.W_OK):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment