ok, let's try to not make any further confusion. Let's agree on what web2py
needs to provide and how to call it.
First things first: gluon.contrib.simplejsonrpc supports only 1.1, so
*only*positional arguments sent as lists.
jsonrpclib instead supports 2.0 spec, so *both* positional arguments sent
as lists and keyword arguments sent as dicts.
Second thing: it's hard to follow some example if the example is never
going to work :P
data = db(db.t_test.ALL).select()
return dict(data=data)
will go on exception no matter what.
data = db().select(db.t_test.ALL)
return dict(data=data)
works as intended.
Third: decorated functions usually need to have arguments.
can we set on a
@service.jsonrpc
def testlist(arg1, arg2):
data = db().select(db.t_test.ALL)
return dict(data=data, arg=arg1, arg2=arg2)
? Right!
Now, I think with a simple patch we can escape the "pass parameters as a
mapping or as a list" problem in gluon/tools.py
if isinstance(params, dict):
s = methods[method](**params)
elif isinstance(params, list):
s = methods[method](*params)
That should restore functionality for who calls functions only with
"positional" style, while retaining the "keywords" style feature. This
means that using contrib.simplejsonrpc you'll be able to call
s.testlist(1,2)
but not
s.testlist(arg1=1, arg2=2)
NB: This is just because simplejsonrpc adheres only to the 1.1 spec
With jsonrpclib, however, both will work ok (yeah!)
If this is fine, we can further fine-tune responses (e.g. 'version': '2.0'
instead of 'version': '1.1') or having 2 separate @service decorators as
Jonathan suggested.
Do we have a deal ?
--