# HG changeset patch # User Ben Croston # Date 1315739864 -3600 # Node ID 636405ae3a66b9765c5fd1b4f45b6b81a9fe815f # Parent 072ee6d41aa776f85b1cf5fb4d9df38860fc4ef6 Don't accept args and kwargs in calls diff -r 072ee6d41aa7 -r 636405ae3a66 AuthRPC/client/__init__.py --- a/AuthRPC/client/__init__.py Mon Sep 05 21:32:16 2011 +0100 +++ b/AuthRPC/client/__init__.py Sun Sep 11 12:17:44 2011 +0100 @@ -46,14 +46,17 @@ request['id'] = str(uuid4()) request['method'] = self.name - if len(kwargs) is not 0: + if len(args) > 0 and len(kwargs) > 0: + raise ProtocolError('Cannot use both positional and keyword arguments.') + + if len(args) > 0: + params = copy.copy(args) + elif len(kwargs) > 0: params = copy.copy(kwargs) index = 0 for arg in args: params[str(index)] = arg index = index + 1 - elif len(args) is not 0: - params = copy.copy(args) else: params = None request['params'] = params @@ -135,6 +138,10 @@ def __init__(self): Exception.__init__(self,'HTTP 502 - Bad Gateway') +class ProtocolError(Exception): + """Raised when the JSONRPC protocol has been broken""" + pass + class ServerProxy(object): """ A client class to communicate with a AuthRPC server diff -r 072ee6d41aa7 -r 636405ae3a66 AuthRPC/tests.py --- a/AuthRPC/tests.py Mon Sep 05 21:32:16 2011 +0100 +++ b/AuthRPC/tests.py Sun Sep 11 12:17:44 2011 +0100 @@ -138,6 +138,12 @@ class ReturnNothing(AuthRPCTests): def runTest(self): self.assertEqual(self.client.returnnothing(), None) + +class ProtocolErrorTest(AuthRPCTests): + def runTest(self): + from client import ProtocolError + with self.assertRaises(ProtocolError): + self.client.test(1, '2', three=3) ##### client ^^^ ##### finished = False @@ -162,6 +168,7 @@ suite.addTest(BadRequestTest()) suite.addTest(EchoTest()) suite.addTest(ReturnNothing()) + suite.addTest(ProtocolErrorTest()) return suite if __name__ == '__main__':