Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
self.model = xsd_group.model
if self.model == 'all':
if self.max_occurs != 1:
self.parse_error("maxOccurs must be 1 for 'all' model groups")
if self.min_occurs not in (0, 1):
self.parse_error("minOccurs must be (0 | 1) for 'all' model groups")
if self.xsd_version == '1.0' and isinstance(self.parent, XsdGroup):
self.parse_error("in XSD 1.0 the 'all' model group cannot be nested")
self.append(xsd_group)
self.ref = xsd_group
else:
attrib = self.elem.attrib
try:
self.name = get_qname(self.target_namespace, attrib['name'])
except KeyError:
pass
else:
content_model = self._parse_child_component(self.elem, strict=True)
if self.parent is not None:
self.parse_error("attribute 'name' not allowed for a local group")
else:
if 'minOccurs' in attrib:
self.parse_error("attribute 'minOccurs' not allowed for a global group")
if 'maxOccurs' in attrib:
self.parse_error("attribute 'maxOccurs' not allowed for a global group")
if 'minOccurs' in content_model.attrib:
self.parse_error(
"attribute 'minOccurs' not allowed for the model of a global group", content_model
)
if 'maxOccurs' in content_model.attrib:
def load_xsd_globals(xsd_globals, schemas):
redefinitions = []
for schema in schemas:
target_namespace = schema.target_namespace
for elem in filter(lambda x: x.tag in (XSD_REDEFINE, XSD_OVERRIDE), schema.root):
location = elem.get('schemaLocation')
if location is None:
continue
for child in filter(lambda x: x.tag == tag and 'name' in x.attrib, elem):
qname = get_qname(target_namespace, child.attrib['name'])
redefinitions.append((qname, elem, child, schema, schema.includes[location]))
for elem in filter(lambda x: x.tag == tag and 'name' in x.attrib, schema.root):
qname = get_qname(target_namespace, elem.attrib['name'])
if qname not in xsd_globals:
xsd_globals[qname] = (elem, schema)
else:
try:
other_schema = xsd_globals[qname][1]
except (TypeError, IndexError):
pass
else:
# It's ignored or replaced in case of an override
if other_schema.override is schema:
continue
elif schema.override is other_schema:
missing_tags = set([e[0].name for e in validation_group if not e[0].is_optional()])
except (AttributeError, TypeError):
raise
while validation_group:
if consumed_child:
try:
child = next(elem_iterator)
except StopIteration:
if missing_tags:
yield XMLSchemaValidationError(
self, elem, "tag expected: %r" % tuple(missing_tags), elem, self.elem
)
return
else:
name = get_qname(target_namespace, child.tag)
consumed_child = False
for _index, (_element, _iterator, _container) in enumerate(validation_group):
if name == _element.name:
consumed_child = True
missing_tags.discard(name)
try:
validation_group[_index] = (next(_iterator), _iterator, _container)
except StopIteration:
validation_group = []
break
if _container.model == XSD_CHOICE_TAG:
# With choice model reduce the validation_group
# in order to match only the first matched tag.
validation_group = [
(e, g, c) for e, g, c in validation_group if c != _container or g == _iterator
def _parse(self):
super(XsdAttributeGroup, self)._parse()
elem = self.elem
any_attribute = None
attribute_group_refs = []
if elem.tag == XSD_ATTRIBUTE_GROUP:
if self.parent is not None:
return # Skip dummy definitions
try:
self.name = get_qname(self.target_namespace, elem.attrib['name'])
except KeyError:
self.parse_error("an attribute group declaration requires a 'name' attribute.")
return
else:
if self.schema.default_attributes == self.name and self.xsd_version > '1.0':
self.schema.default_attributes = self
attributes = ordered_dict_class()
for child in filter(lambda x: x.tag != XSD_ANNOTATION, elem):
if any_attribute is not None:
if child.tag == XSD_ANY_ATTRIBUTE:
self.parse_error("more anyAttribute declarations in the same attribute group")
else:
self.parse_error("another declaration after anyAttribute")
elif child.tag == XSD_ANY_ATTRIBUTE:
if child.tag == XSD_RESTRICTION:
xsd_type = schema.BUILDERS.restriction_class(child, schema, parent)
elif child.tag == XSD_LIST:
xsd_type = XsdList(child, schema, parent)
elif child.tag == XSD_UNION:
xsd_type = schema.BUILDERS.union_class(child, schema, parent)
else:
schema.parse_error("(restriction | list | union) expected", elem)
return schema.maps.types[XSD_ANY_SIMPLE_TYPE]
if annotation is not None:
xsd_type.annotation = annotation
try:
xsd_type.name = get_qname(schema.target_namespace, elem.attrib['name'])
except KeyError:
if parent is None:
schema.parse_error("missing attribute 'name' in a global simpleType", elem)
xsd_type.name = 'nameless_%s' % str(id(xsd_type))
else:
if parent is not None:
schema.parse_error("attribute 'name' not allowed for a local simpleType", elem)
xsd_type.name = None
if 'final' in elem.attrib:
try:
xsd_type._final = get_xsd_derivation_attribute(elem, 'final')
except ValueError as err:
xsd_type.parse_error(err, elem)
return xsd_type
def get_attribute(self, name):
if name[0] != '{':
return self.type.attributes[get_qname(self.type.schema.target_namespace, name)]
return self.type.attributes[name]
def qualified_name(self):
return get_qname(self.target_namespace, self.name)
namespace = ''
for e1 in children:
if skip_comments and e1.tag is lxml_etree_comment:
continue
try:
e2 = next(other_children)
except StopIteration:
assert False, "Node %r has more children than %r." % (elem, other)
if strict or e1 is elem:
assert e1.tag == e2.tag, "%r != %r: tags differ." % (e1, e2)
else:
namespace = get_namespace(e1.tag) or namespace
assert get_qname(namespace, e1.tag) == get_qname(namespace, e2.tag), \
"%r != %r: tags differ." % (e1, e2)
# Attributes
if e1.attrib != e2.attrib:
if strict:
raise AssertionError("%r != %r: attribute differ: %r != %r." % (e1, e2, e1.attrib, e2.attrib))
else:
assert sorted(e1.attrib.keys()) == sorted(e2.attrib.keys()), \
"%r != %r: attribute keys differ: %r != %r." % (e1, e2, e1.attrib.keys(), e2.attrib.keys())
for k in e1.attrib:
a1, a2 = e1.attrib[k].strip(), e2.attrib[k].strip()
if a1 != a2:
try:
assert float(a1) == float(a2)
except (AssertionError, ValueError, TypeError):
raise AssertionError(
if attr_name in attrib:
self.parse_error("attribute %r is not allowed when element reference is used." % attr_name)
return
if 'form' in attrib:
try:
self._form = get_xsd_form_attribute(self.elem, 'form')
except ValueError as err:
self.parse_error(err)
if (self.form or self.schema.element_form_default) == 'qualified':
self.qualified = True
try:
if self.parent is None or self.qualified:
self.name = get_qname(self.target_namespace, attrib['name'])
else:
self.name = attrib['name']
except KeyError:
pass
if 'default' in attrib and 'fixed' in attrib:
self.parse_error("'default' and 'fixed' attributes are mutually exclusive.")
if 'abstract' in attrib:
if self.parent is not None:
self.parse_error("local scope elements cannot have abstract attribute")
if self._parse_boolean_attribute('abstract'):
self._abstract = True
if 'block' in attrib:
try: