[Twisted-web] system.multicall support for the XML-RPC server
Dave Benjamin
dave at ramenlabs.com
Fri May 1 14:29:30 EDT 2009
Hello,
The Twisted XML-RPC server does not come with system.multicall, a de facto
standard method which allows a batch of methods to be called in a single
request.
I wrote an implementation which handles deferred results and ensures that
exceptions in one method call do not prevent the other methods from
executing.
I had to add to the XMLRPCIntrospection class in order to include my
method in the system namespace, even though it is not really an
introspection method. It's also possible to subclass XMLRPCIntrospection
from outside of xmlrpc.py and use putSubHandler instead of
xmlrpc.addIntrospection to create the "system" namespace.
Anyhow, let me know what you think. Patch follows. Thanks for making
Twisted such a joy to read and use.
Dave
--- /usr/share/pyshared/twisted/web/xmlrpc.py 2008-09-05
02:18:26.000000000 -0700
+++ xmlrpc.py 2009-05-01 10:58:39.000000000 -0700
@@ -246,6 +246,33 @@
xmlrpc_methodSignature.signature = [['array', 'string'],
['string', 'string']]
+ def xmlrpc_multicall(self, calls):
+ """
+ Boxcar multiple RPC calls in one request.
+ """
+ results = []
+ for call in calls:
+ name = call['methodName']
+ params = call['params']
+ method = self._xmlrpc_parent._getFunction(name)
+ try:
+ d = defer.maybeDeferred(method, *params)
+ g = defer.waitForDeferred(d)
+ yield g
+ result = [g.getResult()]
+ except Fault, f:
+ result = {'faultCode': f.faultCode,
+ 'faultString': f.faultString}
+ except Exception, e:
+ log.err(e)
+ result = {'faultCode': self.FAILURE,
+ 'faultString': 'error'}
+ results.append(result)
+ yield results
+
+ xmlrpc_multicall = defer.deferredGenerator(xmlrpc_multicall)
+ xmlrpc_multicall.signature = [['array', 'array']]
+
def addIntrospection(xmlrpc):
"""
More information about the Twisted-web
mailing list