Exemplo n.º 1
0
    def post_xml(self, address, envelope, headers):
        """Post the envelope xml element to the given address with the headers.

        This method is intended to be overriden if you want to customize the
        serialization of the xml element. By default the body is formatted
        and encoded as utf-8. See ``zeep.wsdl.utils.etree_to_string``.

        """
        message = etree_to_string(envelope)
        return self.post(address, message, headers)
Exemplo n.º 2
0
Arquivo: soap.py Projeto: speker/core
    def process_error(self, doc, operation):
        fault_node = doc.find("soap-env:Body/soap-env:Fault", namespaces=self.nsmap)

        if fault_node is None:
            raise Fault(
                message="Unknown fault occured",
                code=None,
                actor=None,
                detail=etree_to_string(doc),
            )

        def get_text(name):
            child = fault_node.find(name)
            if child is not None:
                return child.text

        message = fault_node.findtext(
            "soap-env:Reason/soap-env:Text", namespaces=self.nsmap
        )
        code = fault_node.findtext(
            "soap-env:Code/soap-env:Value", namespaces=self.nsmap
        )

        # Extract the fault subcodes. These can be nested, as in subcodes can
        # also contain other subcodes.
        subcodes = []
        subcode_element = fault_node.find(
            "soap-env:Code/soap-env:Subcode", namespaces=self.nsmap
        )
        while subcode_element is not None:
            subcode_value_element = subcode_element.find(
                "soap-env:Value", namespaces=self.nsmap
            )
            subcode_qname = as_qname(
                subcode_value_element.text, subcode_value_element.nsmap, None
            )
            subcodes.append(subcode_qname)
            subcode_element = subcode_element.find(
                "soap-env:Subcode", namespaces=self.nsmap
            )

        # TODO: We should use the fault message as defined in the wsdl.
        detail_node = fault_node.find("soap-env:Detail", namespaces=self.nsmap)
        raise Fault(
            message=message,
            code=code,
            actor=None,
            detail=detail_node,
            subcodes=subcodes,
        )
Exemplo n.º 3
0
Arquivo: mime.py Projeto: speker/core
    def serialize(self, *args, **kwargs):
        value = self.body(*args, **kwargs)
        headers = {"Content-Type": self.content_type}

        data = ""
        if self.content_type == "application/x-www-form-urlencoded":
            items = serialize_object(value)
            data = six.moves.urllib.parse.urlencode(items)
        elif self.content_type == "text/xml":
            document = etree.Element("root")
            self.body.render(document, value)
            data = etree_to_string(list(document)[0])

        return SerializedMessage(path=self.operation.location,
                                 headers=headers,
                                 content=data)
Exemplo n.º 4
0
Arquivo: soap.py Projeto: speker/core
    def process_error(self, doc, operation):
        fault_node = doc.find("soap-env:Body/soap-env:Fault", namespaces=self.nsmap)

        if fault_node is None:
            raise Fault(
                message="Unknown fault occured",
                code=None,
                actor=None,
                detail=etree_to_string(doc),
            )

        def get_text(name):
            child = fault_node.find(name)
            if child is not None:
                return child.text

        raise Fault(
            message=get_text("faultstring"),
            code=get_text("faultcode"),
            actor=get_text("faultactor"),
            detail=fault_node.find("detail"),
        )
Exemplo n.º 5
0
 async def post_xml(self, address, envelope, headers):
     message = etree_to_string(envelope)
     response = await self.post(address, message, headers)
     return await self.new_response(response)
Exemplo n.º 6
0
    def post_xml(self, address, envelope, headers):
        message = etree_to_string(envelope)

        response = yield self.post(address, message, headers)

        raise gen.Return(response)