diff options
Diffstat (limited to 'mammoth/docx')
| -rw-r--r-- | mammoth/docx/relationships_xml.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/mammoth/docx/relationships_xml.py b/mammoth/docx/relationships_xml.py index 75069fc..bb9c3ed 100644 --- a/mammoth/docx/relationships_xml.py +++ b/mammoth/docx/relationships_xml.py @@ -1,3 +1,6 @@ +import collections + + class Relationships(object): def __init__(self, relationships): self._relationships = relationships @@ -5,6 +8,16 @@ class Relationships(object): def __getitem__(self, key): return self._relationships[key] -class Relationship(object): - def __init__(self, target): - self.target = target + +Relationship = collections.namedtuple("Relationship", ["target"]) + + +def read_relationships_xml_element(element): + children = element.find_children("relationships:Relationship") + return Relationships(dict(map(_read_relationship, children))) + + +def _read_relationship(element): + relationship_id = element.attributes["Id"] + relationship = Relationship(target=element.attributes["Target"]) + return relationship_id, relationship |
