コード例 #1
0
ファイル: soap.py プロジェクト: vashek/python-zeep
    def process_error(self, doc):
        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)
        subcodes = []
        subcode_element = fault_node.find('soap-env:Code/soap-env:Subcode',
                                          namespaces=self.nsmap)
        while subcode_element is not None:
            subcodes.append(
                subcode_element.findtext('soap-env:Value',
                                         namespaces=self.nsmap))
            subcode_element = subcode_element.find('soap-env:Subcode',
                                                   namespaces=self.nsmap)

        raise Fault(message=message,
                    code=code,
                    actor=None,
                    detail=fault_node.find('Detail'),
                    subcodes=subcodes)
コード例 #2
0
ファイル: soap.py プロジェクト: josemlp91/python-zeep
    def process_error(self, doc):
        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)
        subcodes = []
        subcode_element = fault_node.find('soap-env:Code/soap-env:Subcode', namespaces=self.nsmap)
        while subcode_element is not None:
            subcodes.append(subcode_element.findtext('soap-env:Value', namespaces=self.nsmap))
            subcode_element = subcode_element.find('soap-env:Subcode', namespaces=self.nsmap)

        raise Fault(
            message=message,
            code=code,
            actor=None,
            detail=fault_node.find('Detail'),
            subcodes=subcodes)
コード例 #3
0
ファイル: soap.py プロジェクト: tobirl/python-zeep
    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

        def setEncoding(string):
            if isinstance(string, basestring):
                return string.encode(sys.stdout.encoding)

        raise Fault(
            message=setEncoding(get_text('faultstring')),
            code=setEncoding(get_text('faultcode')),
            actor=setEncoding(get_text('faultactor')),
            detail=setEncoding(fault_node.find('detail')))
コード例 #4
0
def test_sign_message_egress(certificate_example, envelope):
    plugin = zeep_plugins.SignMessagePlugin(*certificate_example)
    envelope, _ = plugin.egress(envelope, None, 'test', None)

    xml_str = utils.etree_to_string(envelope).decode()

    assert '<Signature xmlns="http://www.w3.org/2000/09/xmldsig#" Id="Firma">' in xml_str
コード例 #5
0
 def _process_rating(self, rating_request):
     DCTRequest  = self.client.get_element('ns0:DCTRequest')
     document = etree.Element('root')
     DCTRequest.render(document, rating_request)
     request_to_send = etree_to_string(list(document)[0])
     headers = {'Content-Type': 'text/xml'}
     response = self.client.transport.post(self.url, request_to_send, headers=headers)
     if self.debug_logger:
         self.debug_logger(request_to_send, 'dhl_rating_request')
         self.debug_logger(response.content, 'dhl_rating_response')
     response_element_xml = fromstring(response.content)
     Response = self.client.get_element(response_element_xml.tag)
     response_zeep = Response.type.parse_xmlelement(response_element_xml)
     dict_response = {'tracking_number': 0.0,
                      'price': 0.0,
                      'currency': False}
     # This condition handle both 'ShipmentValidateErrorResponse' and
     # 'ErrorResponse', we could handle them differently if needed as
     # the 'ShipmentValidateErrorResponse' is something you cannot do,
     # and 'ErrorResponse' are bad values given in the request.
     if hasattr(response_zeep, 'GetQuoteResponse'):
         return response_zeep
     else:
         condition = response_zeep.Response.Status.Condition[0]
         error_msg = "%s: %s" % (condition.ConditionCode, condition.ConditionData)
         raise UserError(error_msg)
コード例 #6
0
    async def post_xml(self, address, envelope, headers):
        message = etree_to_string(envelope)
        response = await self.post(address, message, headers)

        from pretend import stub
        return stub(content=await response.read(),
                    status_code=response.status,
                    headers=response.headers)
コード例 #7
0
ファイル: transports.py プロジェクト: grottas/facturark
    def post_xml(self, address, envelope, headers):
        message = etree_to_string(envelope)
        response = self.post(address, message, headers)
        content_type = response.headers['Content-Type']
        response.headers['Content-Type'] = content_type.replace(
            "Multipart/Related", "multipart/related")

        return response
コード例 #8
0
def get_envelopepart(envelope):
    """The Envelope part"""
    part = MIMEApplication(etree_to_string(envelope), 'xop+xml',
                           encode_7or8bit)
    part.set_param('charset', 'UTF-8')
    part.set_param('type', 'application/soap+xml')
    part.add_header('Content-Transfer-Encoding', '8bit')
    part.add_header('Content-ID', '<soap-env:Envelope>')
    return part
コード例 #9
0
    async def post_xml(self, address, envelope, headers):
        message = etree_to_string(envelope)
        response = await self.post(address, message, headers)

        from pretend import stub
        return stub(
            content=await response.read(),
            status_code=response.status,
            headers=response.headers)
コード例 #10
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)
コード例 #11
0
ファイル: transports.py プロジェクト: leomarp/Test2
    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)
コード例 #12
0
 def post_xml(self, address, envelope, headers):
     # Search for values that startswith FILETAG
     filetags = envelope.xpath(
         "//*[starts-with(text(), '{}')]".format(FILETAG))
     # if there is some attached file we set the attachments
     if filetags:
         message = self.set_attachs(filetags, envelope, headers)
     # else just the envelope
     else:
         message = etree_to_string(envelope)
     # post the data.
     return self.post(address, message, headers)
コード例 #13
0
    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,
        )
コード例 #14
0
    def _create_soap_part(self, envelope) -> bytes:
        """ レスポンスボディのうち、SOAP部分を作成する """
        mime_message_header = self.NEW_LINE_FOR_SWA_BODY.join([
            self._format_bytes(b'--%a', (self.boundary, )),
            b'Content-Type: text/xml; charset=utf-8',
            b'Content-Transfer-Encoding: 8bit',
            self._format_bytes(b'Content-ID: %a', (self.soap_content_id, )),
            b'',
        ])

        # etree_to_string()にて、envelopeをbytes型の送信データへ変換する
        return self.NEW_LINE_FOR_SWA_BODY.join([
            mime_message_header,
            etree_to_string(envelope),
        ])
コード例 #15
0
    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(document.getchildren()[0])

        return SerializedMessage(path=self.operation.location,
                                 headers=headers,
                                 content=data)
コード例 #16
0
ファイル: mime.py プロジェクト: Rahulk1p/python_utility
    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)
コード例 #17
0
ファイル: messages.py プロジェクト: josemlp91/python-zeep
    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(document.getchildren()[0])

        return SerializedMessage(
            path=self.operation.location, headers=headers, content=data)
コード例 #18
0
    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),
            )

        raise Fault(
            message=self.get_text(fault_node, "faultstring"),
            code=self.get_text(fault_node, "faultcode"),
            actor=self.get_text(fault_node, "faultactor"),
            detail=self.get_child_node(fault_node, "detail"),
        )
コード例 #19
0
ファイル: soap.py プロジェクト: simonschmidt/python-zeep
    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'))
コード例 #20
0
ファイル: soap.py プロジェクト: mattpepin/python-zeep
    def process_error(self, doc):
        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'))
コード例 #21
0
ファイル: soap.py プロジェクト: Rahulk1p/python_utility
    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"),
        )
コード例 #22
0
def soap_endpoint():

    if request.method == 'GET':
        with open('person.wsdl', 'r') as fp:
            return Response(fp.read(), mimetype='text/xml')

    document = soap_utils.parse_xml(request.data)
    operation_name = soap_utils.operation_name(document)
    operation = binding.get(operation_name)

    request_object = operation.input.deserialize(document)

    if operation_name == 'get_person':
        response_object = get_person(request_object)

    elif operation_name == 'get_ssn':
        response_object = get_ssn(request_object)

    else:
        raise NotImplementedError()

    to_return = operation.output.serialize(response_object)
    return Response(etree_to_string(to_return.content), mimetype='text/xml')
コード例 #23
0
ファイル: soap.py プロジェクト: tobirl/python-zeep
    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

        def setEncoding(string):
            if isinstance(string, basestring):
                return string.encode(sys.stdout.encoding)

        raise Fault(message=setEncoding(get_text('faultstring')),
                    code=setEncoding(get_text('faultcode')),
                    actor=setEncoding(get_text('faultactor')),
                    detail=setEncoding(fault_node.find('detail')))
コード例 #24
0
ファイル: soap.py プロジェクト: mvantellingen/python-zeep
    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)
コード例 #25
0
ファイル: soap.py プロジェクト: mattpepin/python-zeep
    def send(self, client, options, operation, args, kwargs):
        """Called from the service

        :param client: The client with which the operation was called
        :type client: zeep.client.Client
        :param options: The binding options
        :type options: dict
        :param operation: The operation object from which this is a reply
        :type operation: zeep.wsdl.definitions.Operation
        :param args: The *args to pass to the operation
        :type args: tuple
        :param kwargs: The **kwargs to pass to the operation
        :type kwargs: dict

        """
        operation_obj = self.get(operation)
        if not operation_obj:
            raise ValueError("Operation %r not found" % operation)

        # Create the SOAP envelope
        serialized = operation_obj.create(*args, **kwargs)
        serialized.headers['Content-Type'] = self.content_type

        envelope = serialized.content
        headers = serialized.headers

        # Apply plugins

        # Apply WSSE
        if client.wsse:
            envelope, http_headers = client.wsse.sign(envelope, headers)

        content = etree_to_string(envelope)
        response = client.transport.post(options['address'], content, headers)

        return self.process_reply(client, operation_obj, response)
コード例 #26
0
ファイル: transports.py プロジェクト: fiebiga/python-zeep
 def post_xml(self, address, message, headers):
     message = etree_to_string(message, **self.post_xml_format_options)
     return self.post(address, message, headers)
コード例 #27
0
ファイル: transport.py プロジェクト: tobirl/python-zeep
 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)
コード例 #28
0
 def egress(self, envelope, http_headers, operation, binding_options):
     self.debug_logger(etree_to_string(envelope).decode(), 'ups_request')
     return envelope, http_headers
コード例 #29
0
ファイル: transports.py プロジェクト: leomarp/Test2
 async def post_xml(self, address, envelope, headers):
     message = etree_to_string(envelope)
     response = await self.post(address, message, headers)
     return self.new_response(response)
コード例 #30
0
ファイル: transport.py プロジェクト: ovnicraft/python-zeep
    def post_xml(self, address, envelope, headers):
        message = etree_to_string(envelope)

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

        raise gen.Return(response)
コード例 #31
0
ファイル: soap.py プロジェクト: creditshelf/python-zeep
    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)

        from xml.etree import ElementTree

        try:
            tech_message = detail_node.find(
                "ns2:servicefault/ns2:body/ns2:errorkey/ns2:designation",
                namespaces={
                    "ns2":
                    "https://onlineservice.creditreform.de/webservice/0600-0021"
                }).text + " "
        except Exception:
            tech_message = ""

        try:
            tech_errorkey_message = detail_node.find(
                "ns2:servicefault/ns2:body/ns2:fault/ns2:errorkey/ns2:key",
                namespaces={
                    "ns2":
                    "https://onlineservice.creditreform.de/webservice/0600-0021"
                }).text + ". "
        except Exception:
            tech_errorkey_message = ""

        try:
            tech_fault_message = detail_node.find(
                "ns2:servicefault/ns2:body/ns2:fault/ns2:errorkey/ns2:designation",
                namespaces={
                    "ns2":
                    "https://onlineservice.creditreform.de/webservice/0600-0021"
                }).text
        except Exception:
            tech_fault_message = ""

        try:
            tech_detail_message = detail_node.find(
                "ns2:servicefault/ns2:body/ns2:fault/ns2:errorfield",
                namespaces={
                    "ns2":
                    "https://onlineservice.creditreform.de/webservice/0600-0021"
                }).text
        except Exception:
            tech_detail_message = ""

        tech_fault = tech_message + tech_errorkey_message + tech_fault_message + tech_detail_message

        try:
            validation_message = detail_node.find(
                "tns:validationfault",
                namespaces={
                    "tns":
                    "https://onlineservice.creditreform.de/webservice/0600-0021"
                }).text
        except Exception:
            validation_message = ""

        detail_node = tech_fault + validation_message

        raise Fault(message=message,
                    code=code,
                    actor=None,
                    detail=detail_node,
                    subcodes=subcodes)
コード例 #32
0
    def post_xml(self, address, envelope, headers):
        message = etree_to_string(envelope)

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

        raise gen.Return(response)
コード例 #33
0
 def post_xml(self, address, envelope, headers):
     """Update URL of tge webservice to public IP and then POST it"""
     message = etree_to_string(envelope)
     return self.post(
         address.replace('CEV-MSSQL', '66.76.19.198'), message, headers)
コード例 #34
0
 def ingress(self, envelope, http_headers, operation):
     self.debug_logger(etree_to_string(envelope).decode(), 'ups_response')
     return envelope, http_headers