diff options
| author | Alex Marchant | 2024-09-12 17:28:16 -0400 |
|---|---|---|
| committer | jvoisin | 2024-09-13 14:28:57 +0200 |
| commit | d61fb7f77ae7521c0c3e8cffa3b45e4f18a41b3a (patch) | |
| tree | cadcdf408f7a15a253cb422707129a498c06632f /libmat2 | |
| parent | 1aed4ff2a519845496010d9717ddd2edee0b4e58 (diff) | |
Wait to remove elements until they are all processed
Diffstat (limited to 'libmat2')
| -rw-r--r-- | libmat2/office.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/libmat2/office.py b/libmat2/office.py index f796932..d067128 100644 --- a/libmat2/office.py +++ b/libmat2/office.py | |||
| @@ -283,9 +283,15 @@ class MSOfficeParser(ZipParser): | |||
| 283 | for children in element.iterfind('./*'): | 283 | for children in element.iterfind('./*'): |
| 284 | elements_ins.append((element, position, children)) | 284 | elements_ins.append((element, position, children)) |
| 285 | break | 285 | break |
| 286 | |||
| 286 | for (element, position, children) in elements_ins: | 287 | for (element, position, children) in elements_ins: |
| 287 | parent_map[element].insert(position, children) | 288 | parent_map[element].insert(position, children) |
| 288 | parent_map[element].remove(element) | 289 | |
| 290 | # the list can sometimes contain duplicate elements, so don't remove | ||
| 291 | # until all children have been processed | ||
| 292 | for (element, position, children) in elements_ins: | ||
| 293 | if element in parent_map[element]: | ||
| 294 | parent_map[element].remove(element) | ||
| 289 | 295 | ||
| 290 | tree.write(full_path, xml_declaration=True, encoding='utf-8') | 296 | tree.write(full_path, xml_declaration=True, encoding='utf-8') |
| 291 | return True | 297 | return True |
