diff options
| author | jvoisin | 2018-07-02 00:22:05 +0200 |
|---|---|---|
| committer | jvoisin | 2018-07-02 00:22:05 +0200 |
| commit | 893f58554ab963f8abd4a08222a311014322fff1 (patch) | |
| tree | fe4ec24bc5089a6701ab985e1ad3f6a1151ea9a4 /libmat2/office.py | |
| parent | 11008f8fd436f0b8b00bc600a2cd7a77b55c7494 (diff) | |
Improve a bit the formatting of the code thanks to pyflakes3
Diffstat (limited to 'libmat2/office.py')
| -rw-r--r-- | libmat2/office.py | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/libmat2/office.py b/libmat2/office.py index acd8ca2..eae84f7 100644 --- a/libmat2/office.py +++ b/libmat2/office.py | |||
| @@ -26,7 +26,7 @@ def _parse_xml(full_path: str): | |||
| 26 | ns = parse_map(full_path) | 26 | ns = parse_map(full_path) |
| 27 | 27 | ||
| 28 | # Register the namespaces | 28 | # Register the namespaces |
| 29 | for k,v in ns.items(): | 29 | for k, v in ns.items(): |
| 30 | ET.register_namespace(k, v) | 30 | ET.register_namespace(k, v) |
| 31 | 31 | ||
| 32 | return ET.parse(full_path), ns | 32 | return ET.parse(full_path), ns |
| @@ -35,11 +35,11 @@ def _parse_xml(full_path: str): | |||
| 35 | class ArchiveBasedAbstractParser(abstract.AbstractParser): | 35 | class ArchiveBasedAbstractParser(abstract.AbstractParser): |
| 36 | # Those are the files that have a format that _isn't_ | 36 | # Those are the files that have a format that _isn't_ |
| 37 | # supported by MAT2, but that we want to keep anyway. | 37 | # supported by MAT2, but that we want to keep anyway. |
| 38 | files_to_keep = set() # type: Set[str] | 38 | files_to_keep = set() # type: Set[str] |
| 39 | 39 | ||
| 40 | # Those are the files that we _do not_ want to keep, | 40 | # Those are the files that we _do not_ want to keep, |
| 41 | # no matter if they are supported or not. | 41 | # no matter if they are supported or not. |
| 42 | files_to_omit = set() # type: Set[Pattern] | 42 | files_to_omit = set() # type: Set[Pattern] |
| 43 | 43 | ||
| 44 | def __init__(self, filename): | 44 | def __init__(self, filename): |
| 45 | super().__init__(filename) | 45 | super().__init__(filename) |
| @@ -48,7 +48,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 48 | except zipfile.BadZipFile: | 48 | except zipfile.BadZipFile: |
| 49 | raise ValueError | 49 | raise ValueError |
| 50 | 50 | ||
| 51 | def _specific_cleanup(self, full_path:str) -> bool: | 51 | def _specific_cleanup(self, full_path: str) -> bool: |
| 52 | """ This method can be used to apply specific treatment | 52 | """ This method can be used to apply specific treatment |
| 53 | to files present in the archive.""" | 53 | to files present in the archive.""" |
| 54 | return True | 54 | return True |
| @@ -128,19 +128,19 @@ class MSOfficeParser(ArchiveBasedAbstractParser): | |||
| 128 | 'application/vnd.openxmlformats-officedocument.presentationml.presentation' | 128 | 'application/vnd.openxmlformats-officedocument.presentationml.presentation' |
| 129 | } | 129 | } |
| 130 | files_to_keep = { | 130 | files_to_keep = { |
| 131 | '[Content_Types].xml', | 131 | '[Content_Types].xml', |
| 132 | '_rels/.rels', | 132 | '_rels/.rels', |
| 133 | 'word/_rels/document.xml.rels', | 133 | 'word/_rels/document.xml.rels', |
| 134 | 'word/document.xml', | 134 | 'word/document.xml', |
| 135 | 'word/fontTable.xml', | 135 | 'word/fontTable.xml', |
| 136 | 'word/settings.xml', | 136 | 'word/settings.xml', |
| 137 | 'word/styles.xml', | 137 | 'word/styles.xml', |
| 138 | } | 138 | } |
| 139 | files_to_omit = set(map(re.compile, { # type: ignore | 139 | files_to_omit = set(map(re.compile, { # type: ignore |
| 140 | '^docProps/', | 140 | '^docProps/', |
| 141 | })) | 141 | })) |
| 142 | 142 | ||
| 143 | def __remove_revisions(self, full_path:str) -> bool: | 143 | def __remove_revisions(self, full_path: str) -> bool: |
| 144 | """ In this function, we're changing the XML | 144 | """ In this function, we're changing the XML |
| 145 | document in two times, since we don't want | 145 | document in two times, since we don't want |
| 146 | to change the tree we're iterating on.""" | 146 | to change the tree we're iterating on.""" |
| @@ -152,7 +152,7 @@ class MSOfficeParser(ArchiveBasedAbstractParser): | |||
| 152 | elif tree.find('.//w:ins', ns) is None: | 152 | elif tree.find('.//w:ins', ns) is None: |
| 153 | return True | 153 | return True |
| 154 | 154 | ||
| 155 | parent_map = {c:p for p in tree.iter( ) for c in p} | 155 | parent_map = {c:p for p in tree.iter() for c in p} |
| 156 | 156 | ||
| 157 | elements = list([element for element in tree.iterfind('.//w:del', ns)]) | 157 | elements = list([element for element in tree.iterfind('.//w:del', ns)]) |
| 158 | for element in elements: | 158 | for element in elements: |
| @@ -174,7 +174,7 @@ class MSOfficeParser(ArchiveBasedAbstractParser): | |||
| 174 | 174 | ||
| 175 | return True | 175 | return True |
| 176 | 176 | ||
| 177 | def _specific_cleanup(self, full_path:str) -> bool: | 177 | def _specific_cleanup(self, full_path: str) -> bool: |
| 178 | if full_path.endswith('/word/document.xml'): | 178 | if full_path.endswith('/word/document.xml'): |
| 179 | return self.__remove_revisions(full_path) | 179 | return self.__remove_revisions(full_path) |
| 180 | return True | 180 | return True |
| @@ -214,21 +214,21 @@ class LibreOfficeParser(ArchiveBasedAbstractParser): | |||
| 214 | 'application/vnd.oasis.opendocument.image', | 214 | 'application/vnd.oasis.opendocument.image', |
| 215 | } | 215 | } |
| 216 | files_to_keep = { | 216 | files_to_keep = { |
| 217 | 'META-INF/manifest.xml', | 217 | 'META-INF/manifest.xml', |
| 218 | 'content.xml', | 218 | 'content.xml', |
| 219 | 'manifest.rdf', | 219 | 'manifest.rdf', |
| 220 | 'mimetype', | 220 | 'mimetype', |
| 221 | 'settings.xml', | 221 | 'settings.xml', |
| 222 | 'styles.xml', | 222 | 'styles.xml', |
| 223 | } | 223 | } |
| 224 | files_to_omit = set(map(re.compile, { # type: ignore | 224 | files_to_omit = set(map(re.compile, { # type: ignore |
| 225 | '^meta\.xml$', | 225 | r'^meta\.xml$', |
| 226 | '^Configurations2/', | 226 | '^Configurations2/', |
| 227 | '^Thumbnails/', | 227 | '^Thumbnails/', |
| 228 | })) | 228 | })) |
| 229 | 229 | ||
| 230 | 230 | ||
| 231 | def __remove_revisions(self, full_path:str) -> bool: | 231 | def __remove_revisions(self, full_path: str) -> bool: |
| 232 | tree, ns = _parse_xml(full_path) | 232 | tree, ns = _parse_xml(full_path) |
| 233 | 233 | ||
| 234 | if 'office' not in ns.keys(): # no revisions in the current file | 234 | if 'office' not in ns.keys(): # no revisions in the current file |
| @@ -242,7 +242,7 @@ class LibreOfficeParser(ArchiveBasedAbstractParser): | |||
| 242 | 242 | ||
| 243 | return True | 243 | return True |
| 244 | 244 | ||
| 245 | def _specific_cleanup(self, full_path:str) -> bool: | 245 | def _specific_cleanup(self, full_path: str) -> bool: |
| 246 | if os.path.basename(full_path) == 'content.xml': | 246 | if os.path.basename(full_path) == 'content.xml': |
| 247 | return self.__remove_revisions(full_path) | 247 | return self.__remove_revisions(full_path) |
| 248 | return True | 248 | return True |
