diff options
| author | Michael Williamson <mike@zwobble.org> | 2018-01-19 19:36:56 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2018-01-19 19:36:56 +0000 |
| commit | 882f1aff778b56bbc15222baa0555616f8e102ac (patch) | |
| tree | 931fa395a4ec7a3307cf4a8d96491d5918888ed2 /mammoth | |
| parent | ceb05a609ee9323ab0ecea9aee473939f1149461 (diff) | |
Replace __getitem__ with find_target_by_relationship_id on Relationships
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/docx/body_xml.py | 7 | ||||
| -rw-r--r-- | mammoth/docx/relationships_xml.py | 4 |
2 files changed, 6 insertions, 5 deletions
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py index cfe3493..cdba409 100644 --- a/mammoth/docx/body_xml.py +++ b/mammoth/docx/body_xml.py @@ -341,7 +341,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f )) if relationship_id is not None: - href = relationships[relationship_id].target + href = relationships.find_target_by_relationship_id(relationship_id) if anchor is not None: href = replace_fragment(href, anchor) @@ -414,7 +414,8 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f return _find_linked_image(link_relationship_id) def _find_embedded_image(relationship_id): - image_path = uri_to_zip_entry_name("word", relationships[relationship_id].target) + target = relationships.find_target_by_relationship_id(relationship_id) + image_path = uri_to_zip_entry_name("word", target) def open_image(): image_file = docx_file.open(image_path) @@ -427,7 +428,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f def _find_linked_image(relationship_id): - image_path = relationships[relationship_id].target + image_path = relationships.find_target_by_relationship_id(relationship_id) def open_image(): return files.open(image_path) diff --git a/mammoth/docx/relationships_xml.py b/mammoth/docx/relationships_xml.py index bb9c3ed..8bf3a89 100644 --- a/mammoth/docx/relationships_xml.py +++ b/mammoth/docx/relationships_xml.py @@ -5,8 +5,8 @@ class Relationships(object): def __init__(self, relationships): self._relationships = relationships - def __getitem__(self, key): - return self._relationships[key] + def find_target_by_relationship_id(self, key): + return self._relationships[key].target Relationship = collections.namedtuple("Relationship", ["target"]) |
