Skip to content

Commit 63a3852

Browse files
author
Steve Canny
committed
rels: add get_rel_of_type() method to RelsCollctn
No test coverage. Required by OpcPackage.main_document() method.
1 parent 3f4b490 commit 63a3852

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

opc/package.py

+15
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,21 @@ def add_relationship(self, reltype, target, rId, external=False):
249249
self._rels.append(rel)
250250
return rel
251251

252+
def get_rel_of_type(self, reltype):
253+
"""
254+
Return single relationship of type *reltype* from the collection.
255+
Raises |KeyError| if no matching relationship is found. Raises
256+
|ValueError| if more than one matching relationship is found.
257+
"""
258+
matching = [rel for rel in self._rels if rel.reltype == reltype]
259+
if len(matching) == 0:
260+
tmpl = "no relationship of type '%s' in collection"
261+
raise KeyError(tmpl % reltype)
262+
if len(matching) > 1:
263+
tmpl = "multiple relationships of type '%s' in collection"
264+
raise ValueError(tmpl % reltype)
265+
return matching[0]
266+
252267
@property
253268
def xml(self):
254269
"""

0 commit comments

Comments
 (0)