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' or is_global: name = qname 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_builtins.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) self.schema._elm_instances.append(attr) # Only register global elements if is_global: self.schema.register_attribute(qname, attr) return attr
def test_pythonvalue(self): instance = builtins.AnyType() assert instance.pythonvalue( 'http://test.python-zeep.org') == 'http://test.python-zeep.org'
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