1
""" XMLRPC MultiCall support for Python 2.3. Copied from xmlrpclib.py of Python 2.4.3. """
4
from xmlrpclib import MultiCall
6
from xmlrpclib import Fault
8
class _MultiCallMethod:
9
# some lesser magic to store calls made to a MultiCall object
11
def __init__(self, call_list, name):
12
self.__call_list = call_list
14
def __getattr__(self, name):
15
return _MultiCallMethod(self.__call_list, "%s.%s" % (self.__name, name))
16
def __call__(self, *args):
17
self.__call_list.append((self.__name, args))
19
class MultiCallIterator:
20
"""Iterates over the results of a multicall. Exceptions are
21
thrown in response to xmlrpc faults."""
23
def __init__(self, results):
24
self.results = results
26
def __getitem__(self, i):
27
item = self.results[i]
28
if type(item) == type({}):
29
raise Fault(item['faultCode'], item['faultString'])
30
elif type(item) == type([]):
34
"unexpected type in multicall result"
37
"""server -> a object used to boxcar method calls
39
server should be a ServerProxy object.
41
Methods can be added to the MultiCall using normal
42
method call syntax e.g.:
44
multicall = MultiCall(server_proxy)
46
multicall.get_address("Guido")
48
To execute the multicall, call the MultiCall object e.g.:
50
add_result, address = multicall()
53
def __init__(self, server):
54
self.__server = server
58
return "<MultiCall at %x>" % id(self)
62
def __getattr__(self, name):
63
return _MultiCallMethod(self.__call_list, name)
67
for name, args in self.__call_list:
68
marshalled_list.append({'methodName' : name, 'params' : args})
70
return MultiCallIterator(self.__server.system.multicall(marshalled_list))