You need to return a callable object instead.
The XML-RPC proxy returns an instance of an object that is callable, but can also be traversed over. So for xmlrpc.test.foo()
, you are wrapping xmlrpc.test
in a function; that function object does not have a foo
attribute because functions generally don't have such attributes.
Return a proxy object instead; the __call__
hook makes it a callable object, just like a function would be:
class WrapperProxy(object):
def __init__(self, wrapped):
self.wrapped = wrapped
def __getattr__(self, name):
attr = getattr(self.wrapped, name)
return type(self)(attr)
def __call__(self, *args, **kw):
return self.wrapped(*args, **kw)
class XMLRPC(object):
def __init__(self):
self.xmlrpc = xmlrpclib.ServerProxy("http://localhost:1025/RPC2")
def __getattr__(self, name):
attr = getattr(self.xmlrpc, name)
return WrapperProxy(attr)
or, merged into one object:
class XMLRPCWrapperProxy(object):
def __init__(self, wrapped=None):
if wrapped is None:
wrapped = xmlrpclib.ServerProxy("http://localhost:1025/RPC2")
self.wrapped = wrapped
def __getattr__(self, name):
attr = getattr(self.wrapped, name)
return type(self)(attr)
def __call__(self, *args, **kw):
return self.wrapped(*args, **kw)