1
0
mirror of synced 2024-11-24 10:14:24 +01:00

Another typing pass

This commit is contained in:
jvoisin 2023-01-28 17:22:26 +01:00
parent 39fb254e01
commit 3cb3f58084
5 changed files with 10 additions and 10 deletions

View File

@ -128,7 +128,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
# pylint: disable=unused-argument # pylint: disable=unused-argument
return member return member
def get_meta(self) -> dict[str, Union[str, Dict]]: def get_meta(self) -> Dict[str, Union[str, Dict]]:
meta = dict() # type: Dict[str, Union[str, Dict]] meta = dict() # type: Dict[str, Union[str, Dict]]
with self.archive_class(self.filename) as zin: with self.archive_class(self.filename) as zin:
@ -170,7 +170,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
# Sort the items to process, to reduce fingerprinting, # Sort the items to process, to reduce fingerprinting,
# and keep them in the `items` variable. # and keep them in the `items` variable.
items = list() # type: list[ArchiveMember] items = list() # type: List[ArchiveMember]
for item in sorted(self._get_all_members(zin), key=self._get_member_name): for item in sorted(self._get_all_members(zin), key=self._get_member_name):
# Some fileformats do require to have the `mimetype` file # Some fileformats do require to have the `mimetype` file
# as the first file in the archive. # as the first file in the archive.

View File

@ -78,7 +78,7 @@ def _get_bwrap_args(tempdir: str,
return args return args
def run(args: list[str], def run(args: List[str],
input_filename: str, input_filename: str,
output_filename: Optional[str] = None, output_filename: Optional[str] = None,
**kwargs) -> subprocess.CompletedProcess: **kwargs) -> subprocess.CompletedProcess:

View File

@ -148,7 +148,7 @@ class MSOfficeParser(ZipParser):
return False return False
xml_data = zin.read('[Content_Types].xml') xml_data = zin.read('[Content_Types].xml')
self.content_types = dict() # type: dict[str, str] self.content_types = dict() # type: Dict[str, str]
try: try:
tree = ET.fromstring(xml_data) tree = ET.fromstring(xml_data)
except ET.ParseError: except ET.ParseError:
@ -429,7 +429,7 @@ class MSOfficeParser(ZipParser):
return True return True
def _specific_get_meta(self, full_path: str, file_path: str) -> dict[str, Any]: def _specific_get_meta(self, full_path: str, file_path: str) -> Dict[str, Any]:
""" """
Yes, I know that parsing xml with regexp ain't pretty, Yes, I know that parsing xml with regexp ain't pretty,
be my guest and fix it if you want. be my guest and fix it if you want.
@ -509,7 +509,7 @@ class LibreOfficeParser(ZipParser):
return False return False
return True return True
def _specific_get_meta(self, full_path: str, file_path: str) -> dict[str, Any]: def _specific_get_meta(self, full_path: str, file_path: str) -> Dict[str, Any]:
""" """
Yes, I know that parsing xml with regexp ain't pretty, Yes, I know that parsing xml with regexp ain't pretty,
be my guest and fix it if you want. be my guest and fix it if you want.

View File

@ -2,7 +2,7 @@ import glob
import os import os
import mimetypes import mimetypes
import importlib import importlib
from typing import TypeVar, Optional from typing import TypeVar, Optional, List
from . import abstract, UNSUPPORTED_EXTENSIONS from . import abstract, UNSUPPORTED_EXTENSIONS
@ -34,7 +34,7 @@ def __load_all_parsers():
__load_all_parsers() __load_all_parsers()
def _get_parsers() -> list[T]: def _get_parsers() -> List[T]:
""" Get all our parsers!""" """ Get all our parsers!"""
def __get_parsers(cls): def __get_parsers(cls):
return cls.__subclasses__() + \ return cls.__subclasses__() + \

4
mat2
View File

@ -2,7 +2,7 @@
import os import os
import shutil import shutil
from typing import List, Union, Set from typing import List, Set, Dict
import sys import sys
import mimetypes import mimetypes
import argparse import argparse
@ -98,7 +98,7 @@ def show_meta(filename: str, sandbox: bool):
__print_meta(filename, p.get_meta()) __print_meta(filename, p.get_meta())
def __print_meta(filename: str, metadata: dict, depth: int = 1): def __print_meta(filename: str, metadata: Dict, depth: int = 1):
padding = " " * depth*2 padding = " " * depth*2
if not metadata: if not metadata:
__print_without_chars(padding + "No metadata found in %s." % filename) __print_without_chars(padding + "No metadata found in %s." % filename)