diff options
Diffstat (limited to 'libmat2/office.py')
| -rw-r--r-- | libmat2/office.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/libmat2/office.py b/libmat2/office.py index b3fde7e..1ececdf 100644 --- a/libmat2/office.py +++ b/libmat2/office.py | |||
| @@ -4,7 +4,9 @@ import shutil | |||
| 4 | import tempfile | 4 | import tempfile |
| 5 | import datetime | 5 | import datetime |
| 6 | import zipfile | 6 | import zipfile |
| 7 | import logging | ||
| 7 | from typing import Dict, Set, Pattern | 8 | from typing import Dict, Set, Pattern |
| 9 | |||
| 8 | try: # protect against DoS | 10 | try: # protect against DoS |
| 9 | from defusedxml import ElementTree as ET # type: ignore | 11 | from defusedxml import ElementTree as ET # type: ignore |
| 10 | except ImportError: | 12 | except ImportError: |
| @@ -17,6 +19,8 @@ from . import abstract, parser_factory | |||
| 17 | assert Set | 19 | assert Set |
| 18 | assert Pattern | 20 | assert Pattern |
| 19 | 21 | ||
| 22 | logging.basicConfig(level=logging.ERROR) | ||
| 23 | |||
| 20 | def _parse_xml(full_path: str): | 24 | def _parse_xml(full_path: str): |
| 21 | """ This function parse XML with namespace support. """ | 25 | """ This function parse XML with namespace support. """ |
| 22 | def parse_map(f): # etree support for ns is a bit rough | 26 | def parse_map(f): # etree support for ns is a bit rough |
| @@ -98,7 +102,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 98 | if self._specific_cleanup(full_path) is False: | 102 | if self._specific_cleanup(full_path) is False: |
| 99 | shutil.rmtree(temp_folder) | 103 | shutil.rmtree(temp_folder) |
| 100 | os.remove(self.output_filename) | 104 | os.remove(self.output_filename) |
| 101 | print("Something went wrong during deep cleaning of %s" % item.filename) | 105 | logging.info("Something went wrong during deep cleaning of %s", item.filename) |
| 102 | return False | 106 | return False |
| 103 | 107 | ||
| 104 | if item.filename in self.files_to_keep: | 108 | if item.filename in self.files_to_keep: |
| @@ -112,7 +116,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 112 | if not tmp_parser: | 116 | if not tmp_parser: |
| 113 | shutil.rmtree(temp_folder) | 117 | shutil.rmtree(temp_folder) |
| 114 | os.remove(self.output_filename) | 118 | os.remove(self.output_filename) |
| 115 | print("%s's format (%s) isn't supported" % (item.filename, mtype)) | 119 | logging.info("%s's format (%s) isn't supported", item.filename, mtype) |
| 116 | return False | 120 | return False |
| 117 | tmp_parser.remove_all() | 121 | tmp_parser.remove_all() |
| 118 | os.rename(tmp_parser.output_filename, full_path) | 122 | os.rename(tmp_parser.output_filename, full_path) |
