MCPcopy Create free account
hub / github.com/scanny/python-pptx / get_or_add

Method get_or_add

src/pptx/opc/package.py:526–535  ·  view source on GitHub ↗

Return str rId of `reltype` to `target_part`. The rId of an existing matching relationship is used if present. Otherwise, a new relationship is added and that rId is returned.

(self, reltype: str, target_part: Part)

Source from the content-addressed store, hash-verified

524 return len(self._rels)
525
526 def get_or_add(self, reltype: str, target_part: Part) -> str:
527 """Return str rId of `reltype` to `target_part`.
528
529 The rId of an existing matching relationship is used if present. Otherwise, a new
530 relationship is added and that rId is returned.
531 """
532 existing_rId = self._get_matching(reltype, target_part)
533 return (
534 self._add_relationship(reltype, target_part) if existing_rId is None else existing_rId
535 )
536
537 def get_or_add_ext_rel(self, reltype: str, target_ref: str) -> str:
538 """Return str rId of external relationship of `reltype` to `target_ref`.

Calls 2

_get_matchingMethod · 0.95
_add_relationshipMethod · 0.95