Defines a repeating child element for MetaOxmlElement that must appear at least once.
| 501 | |
| 502 | |
| 503 | class OneOrMore(_BaseChildElement): |
| 504 | """Defines a repeating child element for MetaOxmlElement that must appear at least once.""" |
| 505 | |
| 506 | def populate_class_members(self, element_cls: Type[BaseOxmlElement], prop_name: str): |
| 507 | """Add the appropriate methods to *element_cls*.""" |
| 508 | super(OneOrMore, self).populate_class_members(element_cls, prop_name) |
| 509 | self._add_list_getter() |
| 510 | self._add_creator() |
| 511 | self._add_inserter() |
| 512 | self._add_adder() |
| 513 | self._add_public_adder() |
| 514 | delattr(element_cls, prop_name) |
| 515 | |
| 516 | def _add_public_adder(self) -> None: |
| 517 | """Add a public `.add_x()` method to the parent element class.""" |
| 518 | |
| 519 | def add_child(obj: BaseOxmlElement) -> BaseOxmlElement: |
| 520 | private_add_method = getattr(obj, self._add_method_name) |
| 521 | child = private_add_method() |
| 522 | return child |
| 523 | |
| 524 | add_child.__doc__ = ( |
| 525 | "Add a new ``<%s>`` child element unconditionally, inserted in t" |
| 526 | "he correct sequence." % self._nsptagname |
| 527 | ) |
| 528 | self._add_to_class(self._public_add_method_name, add_child) |
| 529 | |
| 530 | @lazyproperty |
| 531 | def _public_add_method_name(self): |
| 532 | """ |
| 533 | add_childElement() is public API for a repeating element, allowing |
| 534 | new elements to be added to the sequence. May be overridden to |
| 535 | provide a friendlier API to clients having domain appropriate |
| 536 | parameter names for required attributes. |
| 537 | """ |
| 538 | return "add_%s" % self._prop_name |
| 539 | |
| 540 | |
| 541 | class ZeroOrMore(_BaseChildElement): |
no outgoing calls
no test coverage detected
searching dependent graphs…