MCPcopy Index your code
hub / github.com/python-openxml/python-docx / _get_matching

Method _get_matching

src/docx/opc/rel.py:70–87  ·  view source on GitHub ↗

Return relationship of matching `reltype`, `target`, and `is_external` from collection, or None if not found.

(
        self, reltype: str, target: Part | str, is_external: bool = False
    )

Source from the content-addressed store, hash-verified

68 return rels_elm.xml
69
70 def _get_matching(
71 self, reltype: str, target: Part | str, is_external: bool = False
72 ) -> _Relationship | None:
73 """Return relationship of matching `reltype`, `target`, and `is_external` from
74 collection, or None if not found."""
75
76 def matches(rel: _Relationship, reltype: str, target: Part | str, is_external: bool):
77 if rel.reltype != reltype:
78 return False
79 if rel.is_external != is_external:
80 return False
81 rel_target = rel.target_ref if rel.is_external else rel.target_part
82 return rel_target == target
83
84 for rel in self.values():
85 if matches(rel, reltype, target, is_external):
86 return rel
87 return None
88
89 def _get_rel_of_type(self, reltype: str):
90 """Return single relationship of type `reltype` from the collection.

Callers 2

get_or_addMethod · 0.95
get_or_add_ext_relMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected