コード例 #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
コード例 #2
0
 def test_methodArgsVersion2(self):
     result = jsonrpc.encodeRequest('method', 'abcdef', version=2)
     self.assert_json_values(result,
                             jsonrpc='2.0',
                             params='abcdef',
                             method='method',
                             id=Regex(r'\d+'))
コード例 #3
0
 def test_all(self):
     result = jsonrpc.encodeRequest('method',
                                    'abcdef',
                                    id_=123,
                                    version=2.0)
     expected = '{"jsonrpc": "2.0", "params": "abcdef", "method": '
     expected += '"method", "id": 123}'
     self.assertEquals(result, expected)
コード例 #4
0
 def test_methodKwargs(self):
     result = jsonrpc.encodeRequest('method', {'first': 'a', 'second': 'b'})
     self.assert_json_values(result,
                             params={
                                 'first': 'a',
                                 'second': 'b'
                             },
                             method='method',
                             id=Regex(r'\d+'))
コード例 #5
0
 def test_all(self):
     result = jsonrpc.encodeRequest('method',
                                    'abcdef',
                                    id_=123,
                                    version=2.0)
     self.assert_json_values(result,
                             jsonrpc='2.0',
                             params='abcdef',
                             method='method',
                             id=123)
コード例 #6
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(b'POST', self.url.encode(), headers, body)
        d.addCallback(self.checkAuthError)
        d.addCallback(self.bodyFromResponse)
        d.addCallback(jsonrpc.decodeResponse)
        return d
コード例 #7
0
 def test_methodIdInt(self):
     result = jsonrpc.encodeRequest('method', id_=123)
     expected = '{"method": "method", "id": 123}'
     self.assert_json(result, expected)
コード例 #8
0
 def test_methodKwargs(self):
     result = jsonrpc.encodeRequest('method', {'first': 'a', 'second': 'b'})
     pattern = '\{"params": \{"second": "b", "first": "a"\}, '
     pattern += '"method": "method", "id": \d+\}'
     self.assertTrue(re.match(pattern, result))
コード例 #9
0
 def test_onlyMethod(self):
     result = jsonrpc.encodeRequest('method')
     pattern = r'\{"method": "method", "id": \d+\}'
     self.assertTrue(re.match(pattern, result))
コード例 #10
0
 def test_methodArgsId(self):
     result = jsonrpc.encodeRequest('method', 'abcdef', id_=123)
     self.assert_json_values(result,
                             params='abcdef',
                             method='method',
                             id=123)
コード例 #11
0
 def test_methodArgsVersion2(self):
     result = jsonrpc.encodeRequest('method', 'abcdef', version=2)
     pattern = '\{"jsonrpc": "2.0", "params": "abcdef", "method": '
     pattern += '"method", "id": \d+\}'
     self.assertTrue(re.match(pattern, result))
コード例 #12
0
 def test_methodArgs(self):
     result = jsonrpc.encodeRequest('method', ['abc', 'def'])
     pattern = '\{"params": \["abc", "def"\], "method": "method", '
     pattern += '"id": \d+\}'
     self.assertTrue(re.match(pattern, result))
コード例 #13
0
 def test_methodVersion3(self):
     result = jsonrpc.encodeRequest('method', version=3)
     self.assert_json_values(result, method='method', id=Regex(r'\d+'))
コード例 #14
0
ファイル: test_jsonrpc.py プロジェクト: GoodDingo/fastjsonrpc
 def test_methodKwargs(self):
     result = jsonrpc.encodeRequest('method', {'first': 'a', 'second': 'b'})
     pattern = '\{"params": \{"second": "b", "first": "a"\}, '
     pattern += '"method": "method", "id": \d+\}'
     self.assertTrue(re.match(pattern, result))
コード例 #15
0
ファイル: test_jsonrpc.py プロジェクト: GoodDingo/fastjsonrpc
 def test_methodVersion3(self):
     result = jsonrpc.encodeRequest('method', version=3)
     pattern = '\{"method": "method", "id": \d+\}'
     self.assertTrue(re.match(pattern, result))
コード例 #16
0
ファイル: test_jsonrpc.py プロジェクト: GoodDingo/fastjsonrpc
 def test_methodIdStr(self):
     result = jsonrpc.encodeRequest('method', id_='abc')
     expected = '{"method": "method", "id": "abc"}'
     self.assertEquals(result, expected)
コード例 #17
0
ファイル: test_jsonrpc.py プロジェクト: GoodDingo/fastjsonrpc
 def test_methodArgs(self):
     result = jsonrpc.encodeRequest('method', ['abc', 'def'])
     pattern = '\{"params": \["abc", "def"\], "method": "method", '
     pattern += '"id": \d+\}'
     self.assertTrue(re.match(pattern, result))
コード例 #18
0
ファイル: test_jsonrpc.py プロジェクト: GoodDingo/fastjsonrpc
 def test_methodIdInt(self):
     result = jsonrpc.encodeRequest('method', id_=123)
     expected = '{"method": "method", "id": 123}'
     self.assertEquals(result, expected)
コード例 #19
0
ファイル: test_jsonrpc.py プロジェクト: GoodDingo/fastjsonrpc
 def test_onlyMethod(self):
     result = jsonrpc.encodeRequest('method')
     pattern = '\{"method": "method", "id": \d+\}'
     self.assertTrue(re.match(pattern, result))
コード例 #20
0
 def test_methodIdVersion(self):
     result = jsonrpc.encodeRequest('method', version=2.0, id_=123)
     expected = '{"jsonrpc": "2.0", "method": "method", "id": 123}'
     self.assertEquals(result, expected)
コード例 #21
0
 def test_methodIdStr(self):
     result = jsonrpc.encodeRequest('method', id_='abc')
     expected = '{"method": "method", "id": "abc"}'
     self.assert_json(result, expected)
コード例 #22
0
 def test_methodVersion3(self):
     result = jsonrpc.encodeRequest('method', version=3)
     pattern = '\{"method": "method", "id": \d+\}'
     self.assertTrue(re.match(pattern, result))
コード例 #23
0
 def test_methodArgs(self):
     result = jsonrpc.encodeRequest('method', ['abc', 'def'])
     self.assert_json_values(result,
                             params=['abc', 'def'],
                             method='method',
                             id=Regex(r'\d+'))
コード例 #24
0
ファイル: test_jsonrpc.py プロジェクト: GoodDingo/fastjsonrpc
 def test_methodArgsId(self):
     result = jsonrpc.encodeRequest('method', 'abcdef', id_=123)
     expected = '{"params": "abcdef", "method": "method", "id": 123}'
     self.assertEquals(result, expected)
コード例 #25
0
 def test_methodVersion2int(self):
     result = jsonrpc.encodeRequest('method', version=2)
     self.assert_json_values(result,
                             jsonrpc='2.0',
                             method='method',
                             id=Regex(r'\d+'))
コード例 #26
0
ファイル: test_jsonrpc.py プロジェクト: GoodDingo/fastjsonrpc
 def test_methodArgsVersion2(self):
     result = jsonrpc.encodeRequest('method', 'abcdef', version=2)
     pattern = '\{"jsonrpc": "2.0", "params": "abcdef", "method": '
     pattern += '"method", "id": \d+\}'
     self.assertTrue(re.match(pattern, result))
コード例 #27
0
 def test_methodIdVersion(self):
     result = jsonrpc.encodeRequest('method', version=2.0, id_=123)
     self.assert_json_values(result, jsonrpc='2.0', method='method', id=123)
コード例 #28
0
ファイル: test_jsonrpc.py プロジェクト: GoodDingo/fastjsonrpc
 def test_all(self):
     result = jsonrpc.encodeRequest('method', 'abcdef', id_=123,
                                    version=2.0)
     expected = '{"jsonrpc": "2.0", "params": "abcdef", "method": '
     expected += '"method", "id": 123}'
     self.assertEquals(result, expected)
コード例 #29
0
ファイル: test_jsonrpc.py プロジェクト: GoodDingo/fastjsonrpc
 def test_methodIdVersion(self):
     result = jsonrpc.encodeRequest('method', version=2.0, id_=123)
     expected = '{"jsonrpc": "2.0", "method": "method", "id": 123}'
     self.assertEquals(result, expected)
コード例 #30
0
 def test_methodArgsId(self):
     result = jsonrpc.encodeRequest('method', 'abcdef', id_=123)
     expected = '{"params": "abcdef", "method": "method", "id": 123}'
     self.assertEquals(result, expected)