def visit_extension_complex_content(self, node, parent): """ <extension base = QName id = ID {any attributes with non-schema Namespace}...> Content: (annotation?, ( (group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))) </extension> """ base_name = qname_attr(node, 'base') try: base = self.schema.get_type(base_name) children = base._children except KeyError: children = [xsd_types.UnresolvedType(base_name)] for child in node.iterchildren(): if child.tag == tags.annotation: continue item = self.process(child, node) if child.tag == tags.group: children.extend(item) elif child.tag in (tags.choice, tags.sequence, tags.all): children.extend(item) elif child.tag in (tags.attribute, ): children.append(item) return children
def visit_extension_simple_content(self, node, parent): """ <extension base = QName id = ID {any attributes with non-schema Namespace}...> Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?)) </extension> """ base_name = qname_attr(node, 'base') try: base = self.schema.get_type(base_name) if isinstance(base, xsd_types.ComplexType): children = base._children else: children = [xsd_elements.Element(None, base)] except KeyError: children = [xsd_types.UnresolvedType(base_name)] for child in node.iterchildren(): if child.tag == tags.annotation: continue item = self.process(child, node) if child.tag in (tags.attribute, ): children.append(item) return children
def _get_type(self, name): name = self._create_qname(name) try: retval = self.schema.get_type(name) except (exceptions.NamespaceError, exceptions.LookupError): retval = xsd_types.UnresolvedType(name, self.schema) return retval
def visit_attribute(self, node, parent): """Declares an attribute. <attribute default = string fixed = string form = (qualified | unqualified) id = ID name = NCName ref = QName type = QName use = (optional | prohibited | required): optional {any attributes with non-schema Namespace...}> Content: (annotation?, (simpleType?)) </attribute> """ attribute_form = node.get('form', self.schema._attribute_form) if attribute_form == 'qualified': name = qname_attr(node, 'name', self.schema._target_namespace) else: name = etree.QName(node.get('name')) xsd_type = None for child in node.iterchildren(): if child.tag == tags.annotation: continue elif child.tag == tags.simpleType: assert xsd_type is None xsd_type = self.visit_simple_type(child, node) if xsd_type is None: node_type = qname_attr(node, 'type') try: xsd_type = self.schema.get_type(node_type) except KeyError: xsd_type = xsd_types.UnresolvedType(node_type) attr = xsd_elements.Attribute(name, type_=xsd_type) self.schema._elm_instances.append(attr) return attr
def visit_extension_complex_content(self, node, parent): """ <extension base = QName id = ID {any attributes with non-schema Namespace}...> Content: (annotation?, ( (group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))) </extension> """ base_name = qname_attr(node, 'base') base_type = self._get_type(base_name) if isinstance(base_type, xsd_types.ComplexType): children = list(base_type._children) elif isinstance(base_type, xsd_types.UnresolvedType): children = [xsd_types.UnresolvedType(base_name)] else: children = [xsd_elements.Element(None, base_type)] for child in node.iterchildren(): if child.tag == tags.annotation: continue item = self.process(child, node) if child.tag == tags.group: children.extend(item) elif child.tag in (tags.choice, tags.sequence, tags.all): children.extend(item) elif child.tag in (tags.attribute, ): children.append(item) return base_type, children
def visit_list(self, node, parent): """ <list id = ID itemType = QName {any attributes with non-schema Namespace}...> Content: (annotation?, (simpleType?)) </list> The use of the simpleType element child and the itemType attribute is mutually exclusive. """ item_type = qname_attr(node, 'itemType') if item_type: try: xsd_type = self.schema.get_type(item_type.text) except KeyError: xsd_type = xsd_types.UnresolvedType(item_type.text) else: subnodes = node.getchildren() child = subnodes[-1] xsd_type = self.process(child, node) return xsd_types.ListType(xsd_type)
def visit_attribute(self, node, parent): """Declares an attribute. Definition:: <attribute default = string fixed = string form = (qualified | unqualified) id = ID name = NCName ref = QName type = QName use = (optional | prohibited | required): optional {any attributes with non-schema Namespace...}> Content: (annotation?, (simpleType?)) </attribute> :param node: The XML node :type node: lxml.etree._Element :param parent: The parent XML node :type parent: lxml.etree._Element """ is_global = parent.tag == tags.schema # Check of wsdl:arayType array_type = node.get('{http://schemas.xmlsoap.org/wsdl/}arrayType') if array_type: match = re.match('([^\[]+)', array_type) if match: array_type = match.groups()[0] qname = as_qname(array_type, node.nsmap) array_type = xsd_types.UnresolvedType(qname, self.schema) # If the elment has a ref attribute then all other attributes cannot # be present. Short circuit that here. # Ref is prohibited on global elements (parent = schema) if not is_global: result = self.process_ref_attribute(node, array_type=array_type) if result: return result attribute_form = node.get('form', self.document._attribute_form) if attribute_form == 'qualified' or is_global: name = qname_attr(node, 'name', self.document._target_namespace) else: name = etree.QName(node.get('name')) annotation, items = self._pop_annotation(node.getchildren()) if items: xsd_type = self.visit_simple_type(items[0], node) else: node_type = qname_attr(node, 'type') if node_type: xsd_type = self._get_type(node_type) else: xsd_type = xsd_types.AnyType() # TODO: We ignore 'prohobited' for now required = node.get('use') == 'required' default = node.get('default') attr = xsd_elements.Attribute(name, type_=xsd_type, default=default, required=required) # Only register global elements if is_global: self.register_attribute(name, attr) return attr
def _get_type(self, name): assert name is not None name = self._create_qname(name) return xsd_types.UnresolvedType(name, self.schema)
def _get_type(self, name): try: return self.schema.get_type(name) except KeyError: return xsd_types.UnresolvedType(name)
def visit_attribute(self, node, parent): """Declares an attribute. <attribute default = string fixed = string form = (qualified | unqualified) id = ID name = NCName ref = QName type = QName use = (optional | prohibited | required): optional {any attributes with non-schema Namespace...}> Content: (annotation?, (simpleType?)) </attribute> """ is_global = parent.tag == tags.schema # If the elment has a ref attribute then all other attributes cannot # be present. Short circuit that here. # Ref is prohibited on global elements (parent = schema) if not is_global: result = self.process_ref_attribute(node) if result: return result attribute_form = node.get('form', self.schema._attribute_form) qname = qname_attr(node, 'name', self.schema._target_namespace) if attribute_form == 'qualified': name = qname else: name = etree.QName(node.get('name')) xsd_type = None for child in node.iterchildren(): if child.tag == tags.annotation: continue elif child.tag == tags.simpleType: assert xsd_type is None xsd_type = self.visit_simple_type(child, node) if xsd_type is None: node_type = qname_attr(node, 'type') try: xsd_type = self.schema.get_type(node_type) except KeyError: xsd_type = xsd_types.UnresolvedType(node_type) # TODO: We ignore 'prohobited' for now required = node.get('use') == 'required' default = node.get('default') attr = xsd_elements.Attribute(name, type_=xsd_type, default=default, required=required) self.schema._elm_instances.append(attr) # Only register global elements if is_global: self.schema.register_attribute(qname, attr) return attr
def visit_element(self, node, parent): """ <element abstract = Boolean : false block = (#all | List of (extension | restriction | substitution)) default = string final = (#all | List of (extension | restriction)) fixed = string form = (qualified | unqualified) id = ID maxOccurs = (nonNegativeInteger | unbounded) : 1 minOccurs = nonNegativeInteger : 1 name = NCName nillable = Boolean : false ref = QName substitutionGroup = QName type = QName {any attributes with non-schema Namespace}...> Content: (annotation?, ( (simpleType | complexType)?, (unique | key | keyref)*)) </element> """ is_global = parent.tag == tags.schema # If the elment has a ref attribute then all other attributes cannot # be present. Short circuit that here. # Ref is prohibited on global elements (parent = schema) if not is_global: result = self.process_ref_element(node) if result: return result element_form = node.get('form', self.schema._element_form) if element_form == 'qualified' or is_global: qname = qname_attr(node, 'name', self.schema._target_namespace) else: qname = etree.QName(node.get('name')) children = node.getchildren() xsd_type = None if children: value = None for child in children: if child.tag == tags.annotation: continue elif child.tag in (tags.simpleType, tags.complexType): assert not value xsd_type = self.process(child, node) if not xsd_type: node_type = qname_attr(node, 'type') if node_type: try: xsd_type = self.schema.get_type(node_type.text) except KeyError: xsd_type = xsd_types.UnresolvedType(node_type.text) else: xsd_type = xsd_builtins.AnyType() # minOccurs / maxOccurs are not allowed on global elements if not is_global: min_occurs, max_occurs = _process_occurs_attrs(node) else: max_occurs = 1 min_occurs = 1 nillable = node.get('nillable') == 'true' cls = xsd_elements.Element if max_occurs == 1 else xsd_elements.ListElement element = cls(name=qname, type_=xsd_type, min_occurs=min_occurs, max_occurs=max_occurs, nillable=nillable) self.schema._elm_instances.append(element) # Only register global elements if is_global: self.schema.register_element(qname, element) return element
def _get_type(self, name): name = self._create_qname(name) retval = self.schema.get_type(name, default=None) if retval is None: retval = xsd_types.UnresolvedType(name, self.schema) return retval