diff options
| author | jvoisin | 2018-07-19 22:52:40 +0200 |
|---|---|---|
| committer | jvoisin | 2018-07-19 22:55:08 +0200 |
| commit | 565cb66d1405bc334681e59ae41f8631b96e7d51 (patch) | |
| tree | 12833110bbce2bd9fb14e5dab52b9797e0826f1c /libmat2/office.py | |
| parent | 052a356750541d5f985cfa7f995afc4083f42a13 (diff) | |
Minor simplification in how we're handling xml for office files
Diffstat (limited to 'libmat2/office.py')
| -rw-r--r-- | libmat2/office.py | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/libmat2/office.py b/libmat2/office.py index 1ececdf..c6c4688 100644 --- a/libmat2/office.py +++ b/libmat2/office.py | |||
| @@ -22,17 +22,11 @@ assert Pattern | |||
| 22 | logging.basicConfig(level=logging.ERROR) | 22 | logging.basicConfig(level=logging.ERROR) |
| 23 | 23 | ||
| 24 | def _parse_xml(full_path: str): | 24 | def _parse_xml(full_path: str): |
| 25 | """ This function parse XML with namespace support. """ | 25 | """ This function parse XML, with namespace support. """ |
| 26 | def parse_map(f): # etree support for ns is a bit rough | ||
| 27 | namespace_map = dict() | ||
| 28 | for _, (key, value) in ET.iterparse(f, ("start-ns", )): | ||
| 29 | namespace_map[key] = value | ||
| 30 | return namespace_map | ||
| 31 | 26 | ||
| 32 | namespace_map = parse_map(full_path) | 27 | namespace_map = dict() |
| 33 | 28 | for _, (key, value) in ET.iterparse(full_path, ("start-ns", )): | |
| 34 | # Register the namespaces | 29 | namespace_map[key] = value |
| 35 | for key, value in namespace_map.items(): | ||
| 36 | ET.register_namespace(key, value) | 30 | ET.register_namespace(key, value) |
| 37 | 31 | ||
| 38 | return ET.parse(full_path), namespace_map | 32 | return ET.parse(full_path), namespace_map |
