Example #1
0
    def callRemote(self, method, *args, **kwargs):
        """
        Remotely calls the method, with args. Given that we keep reference to
        the call via the Deferred, there's no need for id. It will coin some
        random anyway, just to satisfy the spec.

        According to the spec, we cannot use either args and kwargs at once.
        If there are kwargs, they get used and args are ignored.


        @type method: str
        @param method: Method name

        @type *args: list
        @param *args: List of agruments for the method. It gets ignored if
            kwargs is not empty.

        @type **kwargs: dict
        @param **kwargs: Dict of positional arguments for the method

        @rtype: t.i.d.Deferred
        @return: Deferred, that will fire with whatever the 'method' returned.
        @TODO support batch requests
        """

        if kwargs:
            json_request = jsonrpc.encodeRequest(method,
                                                 kwargs,
                                                 version=self.version)
        else:
            json_request = jsonrpc.encodeRequest(method,
                                                 args,
                                                 version=self.version)

        if self.verbose:
            log.msg('Sending: %s' % json_request)

        response_deferred = ResponseDeferred(verbose=self.verbose)
        factory = CallbackFactory(response_deferred.responseReceived)
        point = TCP4ClientEndpoint(reactor,
                                   self.hostname,
                                   self.port,
                                   timeout=self.timeout)
        d = point.connect(factory)
        d.addCallback(self.connectionMade, json_request)

        # response_deferred will be fired in responseReceived, after
        # we got response from the RPC server
        response_deferred.addCallback(jsonrpc.decodeResponse)
        return response_deferred
Example #2
0
    def callRemote(self, method, *args, **kwargs):
        """
        Remotely calls the method, with args. Given that we keep reference to
        the call via the Deferred, there's no need for id. It will coin some
        random anyway, just to satisfy the spec.

        According to the spec, we cannot use either args and kwargs at once.
        If there are kwargs, they get used and args are ignored.


        @type method: str
        @param method: Method name

        @type *args: list
        @param *args: List of agruments for the method. It gets ignored if
            kwargs is not empty.

        @type **kwargs: dict
        @param **kwargs: Dict of positional arguments for the method

        @rtype: t.i.d.Deferred
        @return: Deferred, that will fire with whatever the 'method' returned.
        @TODO support batch requests
        """

        if kwargs:
            json_request = jsonrpc.encodeRequest(method, kwargs,
                                                 version=self.version)
        else:
            json_request = jsonrpc.encodeRequest(method, args,
                                                 version=self.version)

        if self.verbose:
            log.msg('Sending: %s' % json_request)

        response_deferred = ResponseDeferred(verbose=self.verbose)
        factory = CallbackFactory(response_deferred.responseReceived)
        point = TCP4ClientEndpoint(reactor, self.hostname, self.port,
                                   timeout=self.timeout)
        d = point.connect(factory)
        d.addCallback(self.connectionMade, json_request)

        # response_deferred will be fired in responseReceived, after
        # we got response from the RPC server
        response_deferred.addCallback(jsonrpc.decodeResponse)
        return response_deferred
Example #3
0
    def callRemote(self, method, *args, **kwargs):
        """
        Remotely calls the method, with args. Given that we keep reference to
        the call via the Deferred, there's no need for id. It will coin some
        random anyway, just to satisfy the spec.

        @type method: str
        @param method: Method name

        @type *args: list
        @param *args: List of agruments for the method.

        @rtype: t.i.d.Deferred
        @return: Deferred, that will fire with whatever the 'method' returned.
        @TODO support batch requests
        """

        if kwargs:
            json_request = jsonrpc.encodeRequest(method,
                                                 kwargs,
                                                 version=self.version)
        else:
            json_request = jsonrpc.encodeRequest(method,
                                                 args,
                                                 version=self.version)

        body = StringProducer(json_request)

        headers_dict = {'Content-Type': ['application/json']}
        if not isinstance(self.credentials, Anonymous):
            headers_dict.update(self._getBasicHTTPAuthHeaders())
        headers = Headers(headers_dict)

        d = self.agent.request('POST', self.url, headers, body)
        d.addCallback(self.checkAuthError)
        d.addCallback(self.bodyFromResponse)
        d.addCallback(jsonrpc.decodeResponse)
        return d
Example #4
0
    def callRemote(self, method, *args, **kwargs):
        """
        Remotely calls the method, with args. Given that we keep reference to
        the call via the Deferred, there's no need for id. It will coin some
        random anyway, just to satisfy the spec.

        @type method: str
        @param method: Method name

        @type *args: list
        @param *args: List of agruments for the method.

        @rtype: t.i.d.Deferred
        @return: Deferred, that will fire with whatever the 'method' returned.
        @TODO support **kwargs
        """

        if kwargs:
            json_request = jsonrpc.encodeRequest(method, kwargs,
                                                 version=self.version)
        else:
            json_request = jsonrpc.encodeRequest(method, args,
                                                 version=self.version)

        agent = self.agent
        body = StringProducer(json_request)

        headers_dict = {'Content-Type': ['application/json'],
                        'Content-Length': [str(body.length)]}
        if not isinstance(self.credentials, Anonymous):
            headers_dict.update(self._getBasicHTTPAuthHeaders())
        headers = Headers(headers_dict)

        d = agent.request('POST', self.url, headers, body)
        d.addCallback(self.checkCodeOfResponse)
        d.addCallback(self.bodyFromResponse)
        d.addCallback(jsonrpc.decodeResponse)
        return d