aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mammoth/docx/body_xml.py7
-rw-r--r--mammoth/docx/relationships_xml.py4
-rw-r--r--tests/docx/relationships_xml_tests.py7
3 files changed, 9 insertions, 9 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"])
diff --git a/tests/docx/relationships_xml_tests.py b/tests/docx/relationships_xml_tests.py
index f2280d9..c3d0af0 100644
--- a/tests/docx/relationships_xml_tests.py
+++ b/tests/docx/relationships_xml_tests.py
@@ -1,8 +1,7 @@
from nose.tools import istest, assert_equal
from mammoth.docx.xmlparser import element as xml_element
-from mammoth.docx.relationships_xml import \
- read_relationships_xml_element, Relationship
+from mammoth.docx.relationships_xml import read_relationships_xml_element
@istest
@@ -16,6 +15,6 @@ def target_is_read_from_relationship_element():
])
relationships = read_relationships_xml_element(element)
assert_equal(
- Relationship(target="http://example.com"),
- relationships["rId8"],
+ "http://example.com",
+ relationships.find_target_by_relationship_id("rId8"),
)