def make_proxy(controller, type=_dummy, obj=_dummy):
""" return a tranparent proxy controlled by the given
'controller' callable. The proxy will appear
as a completely regular instance of the given
type but all operations on it are send to the
specified controller - which receives on
ProxyOperation instance on each such call.
A non-specified type will default to type(obj)
if obj is specified.
"""
if type is _dummy:
if obj is _dummy:
raise TypeError("you must specify a type or an instance obj of it")
type = origtype(obj)
def perform(opname, *args, **kwargs):
operation = ProxyOperation(tp, obj, opname, args, kwargs)
return controller(operation)
tp = tproxy(type, perform)
return tp
评论列表
文章目录