+def ref(target,callback=None):
+ #if hasattr(target,"im_self"):
+ # return BoundMethodWeakref(target)
+ if hasattr(target,"__self__"):
+ return BoundMethodWeakref(target)
+ else:
+ return weakref.ref(target,callback)
+
+class BoundMethodWeakref(object):
+ def __init__(self,callable):
+ #self.Self=weakref.ref(callable.im_self)
+ #self.Func=weakref.ref(callable.im_func)
+ self.Self=weakref.ref(callable.__self__)
+ self.Func=weakref.ref(callable.__func__)
+
+ def __call__(self):
+ target=self.Self()
+ if not target:return None
+ func=self.Func()
+ if func:
+ return func.__get__(self.Self())
+