MCPcopy Create free account
hub / github.com/sissaschool/xmlschema / _parse_reference

Method _parse_reference

xmlschema/validators/xsdbase.py:407–441  ·  view source on GitHub ↗

Helper method for referable components. Returns `True` if a valid reference QName is found without any error, otherwise returns `None`. Sets an id-related name for the component ('nameless_ ') if both the attributes 'ref' and 'name' are missing.

(self)

Source from the content-addressed store, hash-verified

405 return
406
407 def _parse_reference(self) -> Optional[bool]:
408 """
409 Helper method for referable components. Returns `True` if a valid reference QName
410 is found without any error, otherwise returns `None`. Sets an id-related name for
411 the component ('nameless_<id of the instance>') if both the attributes 'ref' and
412 'name' are missing.
413 """
414 ref = self.elem.get('ref')
415 if ref is None:
416 if 'name' in self.elem.attrib:
417 return None
418 elif self.parent is None:
419 msg = _("missing attribute 'name' in a global %r")
420 self.parse_error(msg % type(self))
421 else:
422 msg = _("missing both attributes 'name' and 'ref' in local %r")
423 self.parse_error(msg % type(self))
424 elif 'name' in self.elem.attrib:
425 msg = _("attributes 'name' and 'ref' are mutually exclusive")
426 self.parse_error(msg)
427 elif self.parent is None:
428 msg = _("attribute 'ref' not allowed in a global %r")
429 self.parse_error(msg % type(self))
430 else:
431 try:
432 self.name = self.schema.resolve_qname(ref)
433 except (KeyError, ValueError, RuntimeError) as err:
434 self.parse_error(err)
435 else:
436 if self._parse_child_component(self.elem, strict=False) is not None:
437 msg = _("a reference component cannot have child definitions/declarations")
438 self.parse_error(msg)
439 return True
440
441 return None
442
443 def _parse_child_component(self, elem: ElementType, strict: bool = True) \
444 -> Optional[ElementType]:

Callers 6

_parse_attributesMethod · 0.45
_parseMethod · 0.45
_parseMethod · 0.45
_parseMethod · 0.45
_parseMethod · 0.45
_parseMethod · 0.45

Calls 4

resolve_qnameMethod · 0.80
getMethod · 0.45
parse_errorMethod · 0.45

Tested by

no test coverage detected