【发布时间】:2014-05-19 13:41:47
【问题描述】:
我正在尝试包装我的 xml-rpc 服务器 (python 2.7) 我正在使用post中的代码
这是我的代码:
class XMLRPCWrapperProxy(object):
def __init__(self, wrapped=None):
if wrapped is None:
wrapped = xmlrpclib.ServerProxy('http://xxx.xxx.xxx.xxx:xxxx')
self.tf = wrapped
def __getattr__(self, name):
print "before"
attr = getattr(self.tf, name)
print "after"
return type(self)(attr)
def __call__(self, *args, **kw):
return self.tf(*args, **kw)
server_w = XMLRPCWrapperProxy()
server_w.tf.do_function1()
server_w.tf.do_function2(param1)
server_w.tf.do_function3()
server_w.tf.do_function4(param1)
我想wrap do_fuxntion... 调用,但由于某种原因我看不到打印语句,我想我正在包装 self.tf 而不是调用方法,知道如何扭曲任何方法调用吗?
【问题讨论】:
-
投反对票的人,你能解释一下你的投反对票吗?