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

Class OneAndOnlyOne

src/docx/oxml/xmlchemy.py:483–508  ·  view source on GitHub ↗

Defines a required child element for MetaOxmlElement.

Source from the content-addressed store, hash-verified

481
482
483class OneAndOnlyOne(_BaseChildElement):
484 """Defines a required child element for MetaOxmlElement."""
485
486 def __init__(self, nsptagname: str):
487 super(OneAndOnlyOne, self).__init__(nsptagname, ())
488
489 def populate_class_members(self, element_cls: MetaOxmlElement, prop_name: str) -> None:
490 """Add the appropriate methods to `element_cls`."""
491 super(OneAndOnlyOne, self).populate_class_members(element_cls, prop_name)
492 self._add_getter()
493
494 @property
495 def _getter(self):
496 """Return a function object suitable for the "get" side of the property
497 descriptor."""
498
499 def get_child_element(obj: BaseOxmlElement):
500 child = obj.find(qn(self._nsptagname))
501 if child is None:
502 raise InvalidXmlError(
503 "required ``<%s>`` child element not present" % self._nsptagname
504 )
505 return child
506
507 get_child_element.__doc__ = "Required ``<%s>`` child element." % self._nsptagname
508 return get_child_element
509
510
511class OneOrMore(_BaseChildElement):

Callers 7

CT_TblClass · 0.90
CT_GraphicalObjectClass · 0.90
CT_InlineClass · 0.90
CT_PictureClass · 0.90
CT_PictureNonVisualClass · 0.90
CT_NumClass · 0.90
CT_ParentClass · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…