; z;c@sdZdkZdkZdkZdkZdeifdYZdeifdYZe djo@eddfZ e i e e i d d e i ndS( sSimple XML-RPC Server. This module can be used to create simple XML-RPC servers by creating a server and either installing functions, a class instance, or by extending the SimpleXMLRPCRequestHandler class. A list of possible usage patterns follows: 1. Install functions: server = SimpleXMLRPCServer(("localhost", 8000)) server.register_function(pow) server.register_function(lambda x,y: x+y, 'add') server.serve_forever() 2. Install an instance: class MyFuncs: def __init__(self): # make all of the string functions available through # string.func_name import string self.string = string def pow(self, x, y): return pow(x, y) def add(self, x, y) : return x + y server = SimpleXMLRPCServer(("localhost", 8000)) server.register_instance(MyFuncs()) server.serve_forever() 3. Install an instance with custom dispatch method: class Math: def _dispatch(self, method, params): if method == 'pow': return apply(pow, params) elif method == 'add': return params[0] + params[1] else: raise 'bad method' server = SimpleXMLRPCServer(("localhost", 8000)) server.register_instance(Math()) server.serve_forever() 4. Subclass SimpleXMLRPCRequestHandler: class MathHandler(SimpleXMLRPCRequestHandler): def _dispatch(self, method, params): try: # We are forcing the 'export_' prefix on methods that are # callable through XML-RPC to prevent potential security # problems func = getattr(self, 'export_' + method) except AttributeError: raise Exception('method "%s" is not supported' % method) else: return apply(func, params) def log_message(self, format, *args): pass # maybe do something fancy like write the messages to a file def export_add(self, x, y): return x + y server = SimpleXMLRPCServer(("localhost", 8000), MathHandler) server.serve_forever() NsSimpleXMLRPCRequestHandlercBs/tZdZdZdZdddZRS(sgSimple XML-RPC request handler class. Handles all HTTP POST requests and attempts to decode them as XML-RPC requests. XML-RPC requests are dispatched to the _dispatch method, which may be overriden by subclasses. The default implementation attempts to dispatch XML-RPC calls to the functions or instance installed in the server. cCs6y|iit|id}ti|\}}y|i ||}|f}Wn2ti ti ddtitif}nXti |dd}Wn|id|inqX|id|idd|id tt||i|ii||ii|iidd S( sHandles the HTTP POST request. Attempts to interpret all HTTP POST requests as XML-RPC calls, which are forwarded to the _dispatch method for handling. scontent-lengthis%s:%ssmethodresponseiis Content-typestext/xmlsContent-lengthN(sselfsrfilesreadsintsheaderssdatas xmlrpclibsloadssparamssmethods _dispatchsresponsesdumpssFaultssyssexc_types exc_values send_responses end_headerss send_headersstrslenswfileswritesflushs connectionsshutdown(sselfsresponsesparamssdatasmethod((sN/mnt/gmirror/ports/net/py-xmlrpclib/work/xmlrpclib-1.0.1/SimpleXMLRPCServer.pysdo_POSTYs( /    cCsd}t}y|ii|}Wntj o|iitj oot |iido&t t |iid||fSqy||ii|}Wqt j oqXqnX|tj ot ||Sntd|dS(s Dispatches the XML-RPC method. XML-RPC calls are forwarded to a registered function that matches the called XML-RPC method name. If no such function exists then the call is forwarded to the registered instance, if available. If the registered instance has a _dispatch method then that method will be called with the name of the XML-RPC method and it's parameters as a tuple e.g. instance._dispatch('add',(2,3)) If the registered instance does not have a _dispatch method then the instance will be searched to find a matching method and, if found, will be called. Methods beginning with an '_' are considered private and will not be called by SimpleXMLRPCServer. cCsUxJ|idD]9}|idotd|qt||}qW|SdS(sresolve_dotted_attribute(math, 'cos.__doc__') => math.cos.__doc__ Resolves a dotted attribute name to an object. Raises an AttributeError if any attribute in the chain starts with a '_'. s.s_s(attempt to access private attribute "%s"N(sattrssplitsis startswithsAttributeErrorsgetattrsobj(sobjsattrsi((sN/mnt/gmirror/ports/net/py-xmlrpclib/work/xmlrpclib-1.0.1/SimpleXMLRPCServer.pysresolve_dotted_attributess _dispatchsmethod "%s" is not supportedN(sresolve_dotted_attributesNonesfuncsselfsserversfuncssmethodsKeyErrorsinstanceshasattrsapplysgetattrsparamssAttributeErrors Exception(sselfsmethodsparamssfuncsresolve_dotted_attribute((sN/mnt/gmirror/ports/net/py-xmlrpclib/work/xmlrpclib-1.0.1/SimpleXMLRPCServer.pys _dispatchs$    s-cCs+|iiotii|||ndS(s$Selectively log an accepted request.N(sselfsservers logRequestssBaseHTTPServersBaseHTTPRequestHandlers log_requestscodessize(sselfscodessize((sN/mnt/gmirror/ports/net/py-xmlrpclib/work/xmlrpclib-1.0.1/SimpleXMLRPCServer.pys log_requests (s__name__s __module__s__doc__sdo_POSTs _dispatchs log_request(((sN/mnt/gmirror/ports/net/py-xmlrpclib/work/xmlrpclib-1.0.1/SimpleXMLRPCServer.pysSimpleXMLRPCRequestHandlerMs  ( @sSimpleXMLRPCServercBs2tZdZeddZdZedZRS(sSimple XML-RPC server. Simple XML-RPC server that allows functions and a single instance to be installed to handle requests. icCs5h|_||_t|_tii|||dS(N( sselfsfuncss logRequestssNonesinstances SocketServers TCPServers__init__saddrsrequestHandler(sselfsaddrsrequestHandlers logRequests((sN/mnt/gmirror/ports/net/py-xmlrpclib/work/xmlrpclib-1.0.1/SimpleXMLRPCServer.pys__init__s   cCs ||_dS(sRegisters an instance to respond to XML-RPC requests. Only one instance can be installed at a time. If the registered instance has a _dispatch method then that method will be called with the name of the XML-RPC method and it's parameters as a tuple e.g. instance._dispatch('add',(2,3)) If the registered instance does not have a _dispatch method then the instance will be searched to find a matching method and, if found, will be called. Methods beginning with an '_' are considered private and will not be called by SimpleXMLRPCServer. If a registered function matches a XML-RPC request, then it will be called instead of the registered instance. N(sinstancesself(sselfsinstance((sN/mnt/gmirror/ports/net/py-xmlrpclib/work/xmlrpclib-1.0.1/SimpleXMLRPCServer.pysregister_instancescCs+|tjo |i}n||i|ssadd(s__doc__s xmlrpclibs SocketServersBaseHTTPServerssyssBaseHTTPRequestHandlersSimpleXMLRPCRequestHandlers TCPServersSimpleXMLRPCServers__name__sserversregister_functionspows serve_forever(s SocketServers xmlrpclibsSimpleXMLRPCServersserverssyssSimpleXMLRPCRequestHandlersBaseHTTPServer((sN/mnt/gmirror/ports/net/py-xmlrpclib/work/xmlrpclib-1.0.1/SimpleXMLRPCServer.pys?Cs    z3