예제 #1
0
파일: visitor.py 프로젝트: leomarp/Test2
    def visit_attribute(
        self, node: etree._Element, parent: etree._Element
    ) -> typing.Union[xsd_elements.Attribute, xsd_elements.RefAttribute]:
        """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(r"([^\[]+)", array_type)
            if match:
                array_type = match.groups()[0]
                qname = as_qname(array_type, node.nsmap)
                array_type = 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(list(node))
        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:
            assert name is not None
            self.register_attribute(name, attr)
        return attr
예제 #2
0
파일: visitor.py 프로젝트: leomarp/Test2
 def _get_type(self, name):
     assert name is not None
     name = self._create_qname(name)
     return UnresolvedType(name, self.schema)