weakrefutil.py (1085B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\util\weakrefutil.py 2 import types 3 import weakref 4 5 def CallableWeakRef(function): 6 if not callable(function): 7 raise TypeError('Function must be callable.') 8 if isinstance(function, types.FunctionType): 9 return weakref.ref(function) 10 if hasattr(function, '__self__'): 11 subref = weakref.ref(function.__self__) 12 name = function.__func__.__name__ 13 ret = lambda : getattr(subref(), name, None) 14 elif hasattr(function, '__inst__'): 15 subref = weakref.ref(function.__inst__) 16 name = function.__func__.__name__ 17 ret = lambda : getattr(subref(), name, None) 18 elif hasattr(function, '__self__'): 19 subref = weakref.ref(function.__self__) 20 name = function.__name__ 21 ret = lambda : getattr(subref(), name, None) 22 else: 23 if type(function) == types.InstanceType: 24 return weakref.ref(function) 25 raise RuntimeError('%s not supported!' % type(function)) 26 ret.isWeakRef = 1 27 return ret