(original) (raw)

*** python\dist\src\Lib\xmlrpclib.py Wed Dec 19 13:40:04 2001 --- python-rpc-introspect\dist\src\Lib\xmlrpclib.py Mon Mar 18 14:51:26 2002 *************** *** 98,103 **** --- 98,104 ---- ServerProxy Represents a logical connection to an XML-RPC server + MultiCall Executor of boxcared xmlrpc requests Boolean boolean wrapper to generate a "boolean" XML-RPC value DateTime dateTime wrapper for an ISO 8601 string or time tuple or localtime integer value to generate a "dateTime.iso8601" *************** *** 125,131 **** loads Convert an XML-RPC packet to unmarshalled data plus a method name (None if not present). """ ! import re, string, time, operator from types import * --- 126,132 ---- loads Convert an XML-RPC packet to unmarshalled data plus a method name (None if not present). """ ! from __future__ import generators import re, string, time, operator from types import * *************** *** 820,825 **** --- 821,836 ---- def __call__(self, *args): return self.__send(self.__name, args) + class _MultiCallMethod: + # some lesser magic to store calls made to a MultiCall object + # for batch execution + def __init__(self, call_list, name): + self.__call_list = call_list + self.__name = name + def __getattr__(self, name): + return _MultiCallMethod(self.__call_list, "%s.%s" % (self.__name, name)) + def __call__(self, *args): + self.__call_list.append((self.__name, args)) class Transport: """Handles an HTTP transaction to an XML-RPC server.""" *************** *** 919,924 **** --- 930,984 ---- host, x509 = host connection.putheader("Host", host) + def MultiCallIterator(results): + """Iterates over the results of a multicall. Exceptions are + thrown in response to xmlrpc faults.""" + + for i in results: + if type(i) == type({}): + raise Fault(i['faultCode'], i['faultString']) + elif type(i) == type([]): + yield i[0] + else: + raise ValueError,\ + "unexpected type in multicall result" + + class MultiCall: + """server -> a object used to boxcar method calls + + server should be a ServerProxy object. + + Methods can be added to the MultiCall using normal + method call syntax e.g.: + + multicall = MultiCall(server_proxy) + multicall.add(2,3) + multicall.get_address("Guido") + + To execute the multicall, call the MultiCall object e.g.: + + add_result, address = multicall() + """ + + def __init__(self, server): + self.__server = server + self.__call_list = [] + + def __repr__(self): + return "" % id(self) + + __str__ = __repr__ + + def __getattr__(self, name): + return _MultiCallMethod(self.__call_list, name) + + def __call__(self): + marshalled_list = [] + for name, args in self.__call_list: + marshalled_list.append({'methodName' : name, 'params' : args}) + + return MultiCallIterator(self.__server.system.multicall(marshalled_list)) + class ServerProxy: """uri [,options] -> a logical connection to an XML-RPC server *************** *** 987,993 **** ) __str__ = __repr__ ! def __getattr__(self, name): # magic method dispatcher return _Method(self.__request, name) --- 1047,1053 ---- ) __str__ = __repr__ ! def __getattr__(self, name): # magic method dispatcher return _Method(self.__request, name)