Esempio n. 1
0
    def parse(self, xmlelement, schema, allow_none=False, context=None):
        """Process the given xmlelement. If it has an xsi:type attribute then
        use that for further processing. This should only be done for subtypes
        of the defined type but for now we just accept everything.

        This is the entrypoint for parsing an xml document.

        :param xmlelement: The XML element to parse
        :type xmlelements: lxml.etree._Element
        :param schema: The parent XML schema
        :type schema: zeep.xsd.Schema
        :param allow_none: Allow none
        :type allow_none: bool
        :param context: Optional parsing context (for inline schemas)
        :type context: zeep.xsd.context.XmlParserContext
        :return: dict or None

        """
        context = context or XmlParserContext()
        instance_type = qname_attr(xmlelement, xsi_ns('type'))
        xsd_type = None
        if instance_type:
            xsd_type = schema.get_type(instance_type, fail_silently=True)
        xsd_type = xsd_type or self.type
        return xsd_type.parse_xmlelement(
            xmlelement, schema, allow_none=allow_none, context=context,
            schema_type=self.type)
    def _deserialize_headers(self, xmlelement):
        """Deserialize the values in the SOAP:Header element"""
        if not self.header or xmlelement is None:
            return {}

        context = XmlParserContext(settings=self.wsdl.settings)
        result = self.header.parse(xmlelement, self.wsdl.types, context=context)
        if result is not None:
            return {"header": result}
        return {}
Esempio n. 3
0
    def _deserialize_body(self, xmlelement):

        if not self._is_body_wrapped:
            # TODO: For now we assume that the body only has one child since
            # only one part is specified in the wsdl. This should be handled
            # way better
            xmlelement = list(xmlelement)[0]

        context = XmlParserContext(settings=self.wsdl.settings)
        result = self.body.parse(xmlelement, self.wsdl.types, context=context)
        return {"body": result}
Esempio n. 4
0
    def parse(self, xmlelement, schema, allow_none=False, context=None):
        """Process the given xmlelement. If it has an xsi:type attribute then
        use that for further processing. This should only be done for subtypes
        of the defined type but for now we just accept everything.

        """
        context = context or XmlParserContext()
        instance_type = qname_attr(xmlelement, xsi_ns('type'))
        xsd_type = None
        if instance_type:
            xsd_type = schema.get_type(instance_type, fail_silently=True)
        xsd_type = xsd_type or self.type
        return xsd_type.parse_xmlelement(
            xmlelement, schema, allow_none=allow_none, context=context)
    def _deserialize_body(self, body_element):
        """The name of the wrapper element is not defined. The WS-I defines
        that it should be the operation name with the 'Response' string as
        suffix. But lets just do it really stupid for now and use the first
        element.

        """
        process_multiref(body_element)

        response_element = list(body_element)[0]
        if self.body:
            context = XmlParserContext(self.wsdl.settings)
            result = self.body.parse(response_element, self.wsdl.types, context=context)
            return {"body": result}
        return {"body": None}
Esempio n. 6
0
    def parse(self, xmlelement, schema, allow_none=False, context=None):
        """Process the given xmlelement. If it has an xsi:type attribute then
        use that for further processing. This should only be done for subtypes
        of the defined type but for now we just accept everything.

        """
        context = context or XmlParserContext()
        instance_type = qname_attr(
            xmlelement, '{http://www.w3.org/2001/XMLSchema-instance}type')
        if instance_type:
            xsd_type = schema.get_type(instance_type)
        else:
            xsd_type = self.type
        return xsd_type.parse_xmlelement(xmlelement,
                                         schema,
                                         allow_none=allow_none,
                                         context=context)