Subclass, or use it as an internal implementation detail.
Hey man, I read your linked article, and have a comment about this:
from jsonrpc.proxy import ServiceProxy
import test_api
server = ServiceProxy('jsonrpc://127.0.0.1:9002', test_api.Service)
print server.echo('a dogcow says "Moof!"')
print server.add(1, 7)
server.disconnect()
But that was only one of the reasons I decided to write my own ;-)
Like you, I did the same thing: copied the one or two parts of
xmlrpclib that I needed. It's not a long-term plan, though, and I
did it while prototyping because I wasn't sure how I might need to change
things. I had decided to change xmlrpclib.Fault, but then changed
my mind and reverted, so there's no reason not to do an import (guess I'll
go change that now...). FWIW, I'm also using a few of xmlrpclib's
error codes.
Here's what they do in twisted.web.xmlrpc:
# Useful so people don't need to import xmlrpclib directly Fault = xmlrpclib.Fault Binary = xmlrpclib.Binary Boolean = xmlrpclib.Boolean DateTime = xmlrpclib.DateTimeAnd, finally, one last bit of code ;-) This is what I did for marshalling/unmarshalling, and I'd be interested to see how you did things differently:
def dumps(obj, **kws):
if isinstance(obj, Exception):
obj = {'fault': obj.__class__.__name__,
'faultCode': obj.faultCode,
'faultString': obj.faultString}
return simplejson.dumps(obj, **kws)
def loads(s, **kws):
unmarshalled = simplejson.loads(s, **kws)
if unmarshalled.has_key('fault'):
raise Fault(unmarshalled['faultCode'],
unmarshalled['faultString'])
return unmarshalled
Hey Matt,
``object_hook``, if specified, will be called with the result of every JSON object decoded and its return value will be used in place of the given ``dict``. This can be used to provide custom deserializations (e.g. to support JSON-RPC class hinting).This is very cool and I'm going to write stuff to use this. Thought you'd appreciate a heads-up ;-)
Anyone know what's up with the javascript implementations of json-rpc
clients?
are they operating off a different spec? I tried getting one to
talk to a python server and it seems to
want something called system.listmethods -- very confusing.