Ticket #9015: signal_connection_patch.2.diff

File signal_connection_patch.2.diff, 1.1 KB (added by zvoase, 11 years ago)

Patch-v2.diff

  • django/dispatch/dispatcher.py

     
    2828        if providing_args is None:
    2929            providing_args = []
    3030        self.providing_args = set(providing_args)
    31 
     31   
     32    def deco_connect(self, *args, **kwargs):
     33        """Decorate a receiver, connecting it to sender for signal."""
     34        # ``deco_connect`` is being called with a function.
     35        if args:
     36            self.connect(*args, **kwargs)
     37            # Return the receiver, if being used for decoration.
     38            return args[0]
     39        # Create a wrapper which closes over the given kwargs, a sort-of
     40        # implementation of currying.
     41        def connection_wrapper(receiver):
     42            self.connect(receiver, **kwargs)
     43            return receiver
     44        # Return this wrapper so that it can be used to decorate a function.
     45        return connection_wrapper
     46   
    3247    def connect(self, receiver, sender=None, weak=True, dispatch_uid=None):
    3348        """Connect receiver to sender for signal
    3449   
Back to Top