Generates the XML string if this is a reference to a defaults class. To prevent global defaults from clashing, we turn all global defaults into a properly named defaults class. Therefore, care must be taken when this attribute is not explicitly defined. If the parent element can be
(self, prefix_root)
| 344 | self._reference_namespace._force_clear() # pylint: disable=protected-access |
| 345 | |
| 346 | def _defaults_string(self, prefix_root): |
| 347 | """Generates the XML string if this is a reference to a defaults class. |
| 348 | |
| 349 | To prevent global defaults from clashing, we turn all global defaults |
| 350 | into a properly named defaults class. Therefore, care must be taken when |
| 351 | this attribute is not explicitly defined. If the parent element can be |
| 352 | traced up to a body with a nontrivial 'childclass' then must continue to |
| 353 | leave this attribute undefined. |
| 354 | |
| 355 | Args: |
| 356 | prefix_root: A `NameScope` object to be treated as root |
| 357 | for the purpose of calculating the prefix. |
| 358 | |
| 359 | Returns: |
| 360 | A string to be used in the generated XML. |
| 361 | """ |
| 362 | self._check_dead_reference() |
| 363 | prefix = self._parent.namescope.full_prefix(prefix_root) |
| 364 | if not self._value: |
| 365 | defaults_root = self._parent.parent |
| 366 | while defaults_root is not None: |
| 367 | if (hasattr(defaults_root, constants.CHILDCLASS) |
| 368 | and defaults_root.childclass): |
| 369 | break |
| 370 | defaults_root = defaults_root.parent |
| 371 | if defaults_root is None: |
| 372 | # This element doesn't belong to a childclass'd body. |
| 373 | global_class = self._parent.root.default.dclass or '' |
| 374 | out_string = (prefix + global_class) or constants.PREFIX_SEPARATOR |
| 375 | else: |
| 376 | out_string = None |
| 377 | else: |
| 378 | out_string = prefix + self._value |
| 379 | return out_string |
| 380 | |
| 381 | def to_xml_string(self, prefix_root, **kwargs): |
| 382 | self._check_dead_reference() |
no test coverage detected