From 39fb254e019c920516bb317d4b48a8de7cac850e Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 28 Jan 2023 15:57:20 +0000 Subject: Fix the type annotations --- libmat2/office.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'libmat2/office.py') diff --git a/libmat2/office.py b/libmat2/office.py index 8ccaa02..87a0b7e 100644 --- a/libmat2/office.py +++ b/libmat2/office.py @@ -4,7 +4,7 @@ import logging import os import re import zipfile -from typing import Pattern, Any +from typing import Pattern, Any, Tuple, Dict import xml.etree.ElementTree as ET # type: ignore @@ -12,7 +12,8 @@ from .archive import ZipParser # pylint: disable=line-too-long -def _parse_xml(full_path: str) -> tuple[ET.ElementTree, dict[str, str]]: + +def _parse_xml(full_path: str) -> Tuple[ET.ElementTree, Dict[str, str]]: """ This function parses XML, with namespace support. """ namespace_map = dict() for _, (key, value) in ET.iterparse(full_path, ("start-ns", )): @@ -68,7 +69,6 @@ class MSOfficeParser(ZipParser): 'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml', } - def __init__(self, filename): super().__init__(filename) @@ -218,7 +218,7 @@ class MSOfficeParser(ZipParser): if 'w' not in namespace: return True - parent_map = {c:p for p in tree.iter() for c in p} + parent_map = {c: p for p in tree.iter() for c in p} elements_to_remove = list() for element in tree.iterfind('.//w:nsid', namespace): @@ -229,7 +229,6 @@ class MSOfficeParser(ZipParser): tree.write(full_path, xml_declaration=True) return True - @staticmethod def __remove_revisions(full_path: str) -> bool: try: @@ -319,7 +318,6 @@ class MSOfficeParser(ZipParser): for i in re.findall(r' bool: try: @@ -441,8 +439,8 @@ class MSOfficeParser(ZipParser): with open(full_path, encoding='utf-8') as f: try: - results = re.findall(r"<(.+)>(.+)", f.read(), re.I|re.M) - return {k:v for (k, v) in results} + results = re.findall(r"<(.+)>(.+)", f.read(), re.I | re.M) + return {k: v for (k, v) in results} except (TypeError, UnicodeDecodeError): # We didn't manage to parse the xml file return {file_path: 'harmful content', } @@ -459,7 +457,6 @@ class LibreOfficeParser(ZipParser): 'application/vnd.oasis.opendocument.image', } - def __init__(self, filename): super().__init__(filename) -- cgit v1.3