Here's what I ended up with on the server side (in web2py, it goes in
models/jsonrpc.py):

-----------------------------
import gluon.contrib.simplejson as simplejson
import types

class JSONRPCService:
    def response(self, id, result):
        return simplejson.dumps({'version': '1.1', 'id':id,
'result':result, 'error':None})
    def error(self, id, code, message):
        return simplejson.dumps({'id': id,
                                 'version': '1.1',
                                 'error': {'name': 'JSONRPCError',
                                           'code': code,
                                           'message': message
                                           }
                                     })

    def __init__(self):
        self.methods={}

    def serve(self):
        import sys
        data = simplejson.loads(request.body.read())
        id, method, params = data["id"], data["method"], data
["params"]
        if method in self.methods:
            try:
                result =self.methods[method](*params)
                return self.response(id, result)
            except BaseException:
                etype, eval, etb = sys.exc_info()
                return self.error(id, 100, '%s: %s' %(etype.__name__,
eval))
            except:
                etype, eval, etb = sys.exc_info()
                return self.error(id, 100, 'Exception %s: %s' %(etype,
eval))
        else:
            return self.error(id, 100, 'method "%s" does not exist' %
method)

    def __call__(self,func):
        self.methods[func.__name__]=func
        return func

    def listmethods(self):
        return self.methods.keys()

jsonrpc=JSONRPCService()

---------------------------------------------------------

There's going to have to be different server classes because of the
different api's of django, web2py, web.py.  The one I posted above is
not truly complete (it doesn't do service description for example),
but it seems to do the basics correctly when tested with the pyjamas
JSONRPC client. The client from http://lkcl.net/jsonrpclib.tgz also
seems to work fine. I haven't tried any other clients.

Unfortunately I won't have any more time to spend on this for a while,
but I'm hoping this helps get things in the right direction. I sent
massimo a complete version of the working pyjamas-based ToDo app that
he started, so he should be able to post that or incorporate changes
into the next release.

Chris

On Feb 9, 4:59 am, lkcl <luke.leigh...@googlemail.com> wrote:
> chris -
>
> On Feb 9, 12:47 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > Chris,
>
> > would you fix my todo example and email it back to me? I will repost
> > it.
>
>  chris, hi,
>
>  i'd like to know how that works, because there are now three
> JSONRPCservice classes kicking about: one for web2py, one for django
> and one for .... ohh, what was it... web.py that was it.
>
> also, this:
>  http://lkcl.net/jsonrpclib.tgz
>
> i added exception handling to it but it would be nice if you could
> check it over and perhaps use it to do some regression tests of
> web2py's jsonrpc service.
>
> l.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to