__init__.py (939B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\weakness\__init__.py 2 import weakref 3 4 class WeakMethod(object): 5 6 def __init__(self, f): 7 self.class_method = f.__func__ 8 self.self_ref = weakref.ref(f.__self__) 9 10 def __call__(self, *args, **kwargs): 11 method_self = self.self_ref() 12 if method_self is None: 13 raise ReferenceError('weakly-referenced method no longer exists') 14 return self.class_method(method_self, *args, **kwargs) 15 16 def __eq__(self, other): 17 return self is other or getattr(other, '__func__', None) is self.class_method and getattr(other, '__self__', None) == self.self_ref() 18 19 def __ne__(self, other): 20 return not self.__eq__(other) 21 22 23 def callable_proxy(callable_object): 24 if hasattr(callable_object, '__func__'): 25 return WeakMethod(callable_object) 26 else: 27 return weakref.proxy(callable_object)