Django

Code

Show
Ignore:
Timestamp:
08/06/08 10:32:46 (5 months ago)
Author:
jacob
Message:

Major refactoring of django.dispatch with an eye towards speed. The net result is that signals are up to 90% faster.

Though some attempts and backwards-compatibility were made, speed trumped compatibility. Thus, as usual, check BackwardsIncompatibleChanges for the complete list of backwards-incompatible changes.

Thanks to Jeremy Dunck and Keith Busell for the bulk of the work; some ideas from Brian Herring's previous work (refs #4561) were incorporated.

Documentation is, sigh, still forthcoming.

Fixes #6814 and #3951 (with the new dispatch_uid argument to connect).

Files:

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 
     4Provides a way to safely weakref any function, including bound methods (which 
     5aren't handled by the core weakref module). 
     6""" 
     7 
    28import weakref, traceback 
    39 
     
    6167 
    6268    """ 
     69     
    6370    _allInstances = weakref.WeakValueDictionary() 
     71     
    6472    def __new__( cls, target, onDelete=None, *arguments,**named ): 
    6573        """Create new instance or return current instance 
     
    8492            base.__init__( target, onDelete, *arguments,**named) 
    8593            return base 
     94     
    8695    def __init__(self, target, onDelete=None): 
    8796        """Return a weak-reference-like instance for a bound method 
     
    123132        self.selfName = str(target.im_self) 
    124133        self.funcName = str(target.im_func.__name__) 
     134     
    125135    def calculateKey( cls, target ): 
    126136        """Calculate the reference key for this reference 
     
    131141        return (id(target.im_self),id(target.im_func)) 
    132142    calculateKey = classmethod( calculateKey ) 
     143     
    133144    def __str__(self): 
    134145        """Give a friendly representation of the object""" 
     
    138149            self.funcName, 
    139150        ) 
     151     
    140152    __repr__ = __str__ 
     153     
    141154    def __nonzero__( self ): 
    142155        """Whether we are still a valid reference""" 
    143156        return self() is not None 
     157     
    144158    def __cmp__( self, other ): 
    145159        """Compare with another reference""" 
     
    147161            return cmp( self.__class__, type(other) ) 
    148162        return cmp( self.key, other.key) 
     163     
    149164    def __call__(self): 
    150165        """Return a strong reference to the bound method 
     
    225240        return None 
    226241 
    227  
    228242def get_bound_method_weakref(target, onDelete): 
    229243    """Instantiates the appropiate BoundMethodWeakRef, depending on the details of 
     
    235249        # no luck, use the alternative implementation: 
    236250        return BoundNonDescriptorMethodWeakref(target=target, onDelete=onDelete) 
    237