Package park :: Package util :: Module rpc

Source Code for Module park.util.rpc

 1  # Cribbed from xmlrpclib: remote method invocation 
 2  # TODO: ship docstrings and method signature back so that ipython usage 
 3  # is prettier. 
4 -class _Method(object):
5 """ 6 Remote method callable. 7 """
8 - def __init__(self, transport, basename):
9 """Use transport to call method""" 10 if basename.startswith("_"): 11 raise AttributeError("invalid attribute '%s'" % name) 12 self.__transport = transport 13 self.__basename = basename
14 - def __getattr__(self, name):
15 """Allow sub-names a.b.c""" 16 if name.startswith("_"): 17 raise AttributeError("invalid attribute '%s'" % name) 18 return _Method(self.__transport,".".join([self.__basename,name]))
19 - def __call__(self, *args, **kw):
20 """Perform call""" 21 return self._transport(self.__basename, args, kw)
22 -class RpcProxy(object):
23 """ 24 Proxy for remote procedure call, 25 """
26 - def _transport(self, method, args, kw):
27 """ 28 Marshall the call over the wire to the remote procedure. 29 30 Subclasses must implement this. 31 """ 32 raise NotImplementedError
33 - def __getattr__(self, method):
34 return _Method(self._transport, method)
35