Changeset 139
- Timestamp:
- 05/05/02 14:04:03 (6 years ago)
- Files:
-
- trunk/RBFoundation/RBFoundation/WeakBind.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBFoundation/RBFoundation/WeakBind.py
r104 r139 42 42 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 43 43 44 typesRequireBinding = (types.MethodType, types.UnboundMethodType, types.InstanceType) 44 typesMethods = (types.MethodType, types.UnboundMethodType) 45 typesInstances = (object, types.InstanceType) 46 typesRequireBinding = typesMethods + typesInstances 45 47 46 48 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 47 49 48 50 class BoundCallableBase(object): 51 """Ultimate baseclass of BoundCallable objects. Derive from this object if the class 52 handles references to itself, by itself.""" 49 53 pass 50 54 … … 53 57 class BoundCallable(BoundCallableBase): 54 58 im_self = None 59 im_func = None 55 60 56 61 def __init__(self, callback): 57 if isinstance(callback, (types.MethodType, types.UnboundMethodType)): 62 if callback is None: 63 self.im_func = None 64 elif isinstance(callback, typesMethods): 58 65 if callback.im_self is not None: 59 66 self.im_self = weakref.ref(callback.im_self) 60 67 self.im_func = callback.im_func 61 elif isinstance(callback, types .InstanceType):68 elif isinstance(callback, typesInstances): 62 69 self.im_self = weakref.ref(callback) 63 70 self.im_func = None 64 71 else: 65 72 self.im_func = callback 66 73 67 74 def __nonzero__(self): 68 result = self.im_func and (not self.im_self or self.im_self() is not None) and 1 or 0 69 return result 75 if self.im_self is not None: 76 return self.im_self() is not None and 1 or 0 77 else: 78 return self.im_func and 1 or 0 70 79 71 80 def __call__(self, *args, **kw):
