Changeset 8223 for django/trunk/django/dispatch/saferef.py
- Timestamp:
- 08/06/08 10:32:46 (5 months ago)
- Files:
-
- django/trunk/django/dispatch/saferef.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/dispatch/saferef.py
r8046 r8223 1 """Refactored "safe reference" from dispatcher.py""" 1 """ 2 "Safe weakrefs", originally from pyDispatcher. 3 4 Provides a way to safely weakref any function, including bound methods (which 5 aren't handled by the core weakref module). 6 """ 7 2 8 import weakref, traceback 3 9 … … 61 67 62 68 """ 69 63 70 _allInstances = weakref.WeakValueDictionary() 71 64 72 def __new__( cls, target, onDelete=None, *arguments,**named ): 65 73 """Create new instance or return current instance … … 84 92 base.__init__( target, onDelete, *arguments,**named) 85 93 return base 94 86 95 def __init__(self, target, onDelete=None): 87 96 """Return a weak-reference-like instance for a bound method … … 123 132 self.selfName = str(target.im_self) 124 133 self.funcName = str(target.im_func.__name__) 134 125 135 def calculateKey( cls, target ): 126 136 """Calculate the reference key for this reference … … 131 141 return (id(target.im_self),id(target.im_func)) 132 142 calculateKey = classmethod( calculateKey ) 143 133 144 def __str__(self): 134 145 """Give a friendly representation of the object""" … … 138 149 self.funcName, 139 150 ) 151 140 152 __repr__ = __str__ 153 141 154 def __nonzero__( self ): 142 155 """Whether we are still a valid reference""" 143 156 return self() is not None 157 144 158 def __cmp__( self, other ): 145 159 """Compare with another reference""" … … 147 161 return cmp( self.__class__, type(other) ) 148 162 return cmp( self.key, other.key) 163 149 164 def __call__(self): 150 165 """Return a strong reference to the bound method … … 225 240 return None 226 241 227 228 242 def get_bound_method_weakref(target, onDelete): 229 243 """Instantiates the appropiate BoundMethodWeakRef, depending on the details of … … 235 249 # no luck, use the alternative implementation: 236 250 return BoundNonDescriptorMethodWeakref(target=target, onDelete=onDelete) 237
