Esempio n. 1
0
    def _gotResult(self, result, request, methodName, ns):
        self.debug(f'_gotResult {result} {request} {methodName} {ns}')

        response = soap_lite.build_soap_call(
            methodName, result, ns=ns, is_response=True,
        )
        self._sendResponse(request, response)
Esempio n. 2
0
    def callRemote(self, soapmethod, *args, **kwargs):
        soapaction = soapmethod or self.soapaction
        if '#' not in soapaction:
            soapaction = '#'.join((self.namespace[1],soapaction))
        self.action = soapaction.split('#')[1]

        self.info("callRemote %r %r %r %r", self.soapaction, soapmethod, self.namespace, self.action)

        headers = { 'content-type': 'text/xml ;charset="utf-8"',
                    'SOAPACTION': '"%s"' % soapaction,}
        if kwargs.has_key('headers'):
            headers.update(kwargs['headers'])
            del kwargs['headers']

        payload = soap_lite.build_soap_call("{%s}%s" % (self.namespace[1], self.action), kwargs,
                                            encoding=None)

        self.info("callRemote soapaction %s %s: ", self.action, self.url)
        self.debug("callRemote payload: %s", payload)

        def gotError(failure, url):
            # failure.value should be an Error object
            self.error("error requesting %s %s %s [%s]", url, failure, failure.value.status, failure.value.response )

            if int(failure.value.status) == 500:
                # generic error, do we have abody?
                # if so parse and return.
                tree = parse_xml(failure.value.response)
                self.log_dom(tree.getroot())

            return failure

        return getPage(self.url, postdata=payload, method="POST",
                        headers=headers
                      ).addCallbacks(self._cbGotResult, gotError, None, None, [self.url], None)
Esempio n. 3
0
    def _gotResult(self, result, request, methodName, ns):
        self.debug('_gotResult %s %s %s %s', result, request, methodName, ns)

        response = soap_lite.build_soap_call(methodName,
                                             result,
                                             ns=ns,
                                             is_response=True)
        self._sendResponse(request, response)
Esempio n. 4
0
    def _gotResult(self, result, request, methodName, ns):
        self.debug('_gotResult', result, request, methodName, ns)

        response = soap_lite.build_soap_call("{%s}%s" % (ns, methodName), result,
                                                is_response=True,
                                                encoding=None)
        #print "SOAP-lite response", response
        self._sendResponse(request, response)
Esempio n. 5
0
 def test_build_soap_call_with_args(self):
   r1 = soap_lite.build_soap_call('TestMethod',
                                  arguments={'s1': 'val1',
                                             'b1': True,
                                             'f1': 1.32,
                                             'i1': 42},
                                  ns='TestNameSpace',
                                  is_response=True,
                                  pretty_print=False)
   self.assertSequenceEqual(SOAP_CALL_WITH_ARGS, r1)
   return
Esempio n. 6
0
 def test_build_soap_call_with_args(self):
     r1 = soap_lite.build_soap_call('TestMethod',
                                    arguments={
                                        's1': 'val1',
                                        'b1': True,
                                        'f1': 1.32,
                                        'i1': 42
                                    },
                                    ns='TestNameSpace',
                                    is_response=True,
                                    pretty_print=False)
     self.assertSequenceEqual(SOAP_CALL_WITH_ARGS, r1)
     return
Esempio n. 7
0
    def callRemote(self, soapmethod, arguments):
        soapaction = soapmethod or self.soapaction
        if '#' not in soapaction:
            soapaction = '#'.join((self.namespace[1], soapaction))
        self.action = soapaction.split('#')[1]

        self.info("callRemote %r %r %r %r", self.soapaction, soapmethod,
                  self.namespace, self.action)

        headers = {
            'content-type': 'text/xml ;charset="utf-8"',
            'SOAPACTION': '"%s"' % soapaction,
        }
        if arguments.has_key('headers'):
            headers.update(arguments['headers'])
            del arguments['headers']

        payload = soap_lite.build_soap_call("{%s}%s" %
                                            (self.namespace[1], self.action),
                                            arguments,
                                            encoding=None)

        self.info("callRemote soapaction: ", self.action, self.url)
        self.debug("callRemote payload: ", payload)

        def gotError(error, url):
            self.warning("error requesting url %r" % url)
            self.debug(error)
            try:
                tree = parse_xml(error.value.response)
                body = tree.find(
                    '{http://schemas.xmlsoap.org/soap/envelope/}Body')
                return failure.Failure(
                    Exception("%s - %s" % (
                        body.find(
                            './/{urn:schemas-upnp-org:control-1-0}errorCode').
                        text,
                        body.find(
                            './/{urn:schemas-upnp-org:control-1-0}errorDescription'
                        ).text)))
            except:
                import traceback
                self.debug(traceback.format_exc())
            return error

        return getPage(self.url,
                       postdata=payload,
                       method="POST",
                       headers=headers).addCallbacks(self._cbGotResult,
                                                     gotError, None, None,
                                                     [self.url], None)
Esempio n. 8
0
    def callRemote(self, soapmethod, arguments):
        soapaction = soapmethod or self.soapaction
        if '#' not in soapaction:
            soapaction = '#'.join((self.namespace[1], soapaction))
        self.action = soapaction.split('#')[1]

        self.info("callRemote %r %r %r %r", self.soapaction, soapmethod, self.namespace, self.action)

        headers = {'content-type': 'text/xml ;charset="utf-8"',
                   'SOAPACTION': '"%s"' % soapaction, }
        if 'headers' in arguments:
            headers.update(arguments['headers'])
            del arguments['headers']

        payload = soap_lite.build_soap_call(self.action, arguments, ns=self.namespace[1])

        self.info("callRemote soapaction:  %s %s", self.action, self.url)
        self.debug("callRemote payload:  %s", payload)

        def gotError(error, url):
            self.warning("error requesting url %r", url)
            self.debug(error)
            try:
                tree = etree.fromstring(error.value.response)
                body = tree.find('{http://schemas.xmlsoap.org/soap/envelope/}Body')
                return failure.Failure(Exception("%s - %s" % (
                  body.find('.//{urn:schemas-upnp-org:control-1-0}errorCode').text,
                  body.find('.//{urn:schemas-upnp-org:control-1-0}errorDescription').text)))
            except:
                import traceback
                self.debug(traceback.format_exc())
            return error

        return getPage(self.url, postdata=payload, method="POST", headers=headers).addCallbacks(self._cbGotResult,
                                                                                                gotError, None, None,
                                                                                                [self.url], None)
Esempio n. 9
0
    def _gotResult(self, result, request, methodName, ns):
        self.debug('_gotResult %s %s %s %s', result, request, methodName, ns)

        response = soap_lite.build_soap_call(methodName, result, ns=ns, is_response=True)
        self._sendResponse(request, response)
Esempio n. 10
0
    def callRemote(self, soapmethod, arguments):
        '''
        You can use the method :meth:`callRemote` like

        .. code-block:: python

            proxy.callRemote('foobar', 1, 2)

        to call remote method 'foobar' with args 1 and 2.

        Also you can call the method :meth:`callRemote` with named arguments

        .. code-block:: python

            proxy.callRemote('foobar', x=1)

        .. note:: The named arguments feature it will be useful to pass some
                  headers (if needed) to our soap calls.
        '''
        soapaction = soapmethod or self.soapaction
        if '#' not in soapaction:
            soapaction = '#'.join((self.namespace[1], soapaction))
        self.action = soapaction.split('#')[1].encode('ascii')

        self.info(f'callRemote {self.soapaction} {soapmethod} '
                  f'{self.namespace} {self.action}')

        headers = {
            'content-type': 'text/xml ;charset="utf-8"',
            'SOAPACTION': f'"{soapaction}"',
        }
        if 'headers' in arguments:
            headers.update(arguments['headers'])
            del arguments['headers']

        payload = soap_lite.build_soap_call(self.action,
                                            arguments,
                                            ns=self.namespace[1])
        self.debug(f'callRemote payload is:  {payload}')

        def gotError(error, url):
            self.error(f'callRemote error requesting url {url}')
            self.debug(error)
            try:
                self.error(
                    f'\t-> error.value.response is: {error.value.response}')
                try:
                    tree = etree.fromstring(error.value.response)
                except Exception:
                    self.warning(
                        'callRemote: error on parsing soap result, probably'
                        ' has encoding declaration, trying with another'
                        ' method...')
                    tree = parse_with_lxml(error.value.response,
                                           encoding='utf-8')
                body = tree.find(
                    '{http://schemas.xmlsoap.org/soap/envelope/}Body')
                return failure.Failure(
                    Exception(
                        '%s - %s' %
                        (body.find('.//{urn:schemas-upnp-org:control-1-0}'
                                   'errorCode').text,
                         body.find('.//{urn:schemas-upnp-org:control-1-0}'
                                   'errorDescription').text)))
            except Exception as e:
                self.error(f'callRemote error on getting traceback: {e}')
                import traceback
                self.debug(traceback.format_exc())
            return error

        return getPage(self.url,
                       postdata=payload,
                       method=b'POST',
                       headers=headers).addCallbacks(self._cbGotResult,
                                                     gotError, None, None,
                                                     [self.url], None)