From 88c99e0b838acbc502d0cde149a04d5e6c81c835 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Fri, 27 Aug 2010 13:45:52 -0300 Subject: [PATCH] Check that arguments and keyword arguments are not passed simultaneously in jsonrpc_client_call() --- scrapy/tests/test_utils_jsonrpc.py | 3 +++ scrapy/utils/jsonrpc.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/scrapy/tests/test_utils_jsonrpc.py b/scrapy/tests/test_utils_jsonrpc.py index f8f8b13fb..fe62fb319 100644 --- a/scrapy/tests/test_utils_jsonrpc.py +++ b/scrapy/tests/test_utils_jsonrpc.py @@ -36,6 +36,9 @@ class JsonRpcUtilsTestCase(unittest.TestCase): crawler = CrawlerMock([]) self.json_decoder = ScrapyJSONDecoder(crawler=crawler) + def test_jsonrpc_client_call_args_kwargs_raises(self): + self.assertRaises(ValueError, jsonrpc_client_call, 'url', 'test', 'one', kw=123) + def test_jsonrpc_client_call_request(self): ul = urllib_mock(1) jsonrpc_client_call('url', 'test', 'one', 2, _urllib=ul) diff --git a/scrapy/utils/jsonrpc.py b/scrapy/utils/jsonrpc.py index d9d4008c9..686a1d235 100644 --- a/scrapy/utils/jsonrpc.py +++ b/scrapy/utils/jsonrpc.py @@ -31,6 +31,8 @@ class JsonRpcError(Exception): def jsonrpc_client_call(url, method, *args, **kwargs): """Execute a JSON-RPC call on the given url""" _urllib = kwargs.pop('_urllib', urllib) + if args and kwargs: + raise ValueError("Pass *args or **kwargs but not both to jsonrpc_client_call") req = {'jsonrpc': '2.0', 'method': method, 'params': args or kwargs, 'id': 1} res = json.loads(_urllib.urlopen(url, json.dumps(req)).read()) if 'result' in res: