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

Class _Relationship

src/docx/opc/rel.py:114–153  ·  view source on GitHub ↗

Value object for relationship to part.

Source from the content-addressed store, hash-verified

112
113
114class _Relationship:
115 """Value object for relationship to part."""
116
117 def __init__(
118 self, rId: str, reltype: str, target: Part | str, baseURI: str, external: bool = False
119 ):
120 super(_Relationship, self).__init__()
121 self._rId = rId
122 self._reltype = reltype
123 self._target = target
124 self._baseURI = baseURI
125 self._is_external = bool(external)
126
127 @property
128 def is_external(self) -> bool:
129 return self._is_external
130
131 @property
132 def reltype(self) -> str:
133 return self._reltype
134
135 @property
136 def rId(self) -> str:
137 return self._rId
138
139 @property
140 def target_part(self) -> Part:
141 if self._is_external:
142 raise ValueError(
143 "target_part property on _Relationship is undefined when target mode is External"
144 )
145 return cast("Part", self._target)
146
147 @property
148 def target_ref(self) -> str:
149 if self._is_external:
150 return cast(str, self._target)
151 else:
152 target = cast("Part", self._target)
153 return target.partname.relative_ref(self._baseURI)

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…