Ticket #4521: signal-class.patch

File signal-class.patch, 2.8 KB (added by (removed), 8 years ago)

add django.dispatch.signal func to return a singleton with docstring/label bound in, and usable (str|repr)

  • django/db/models/signals.py

    === modified file 'django/db/models/signals.py'
     
    1 class_prepared = object()
    2 
    3 pre_init= object()
    4 post_init = object()
    5 
    6 pre_save = object()
    7 post_save = object()
    8 
    9 pre_delete = object()
    10 post_delete = object()
    11 
    12 post_syncdb = object()
     1from django.dispatch import signal
     2
     3class_prepared = signal("class_prepared")
     4
     5pre_init= signal('pre_init')
     6post_init = signal('post_init')
     7
     8pre_save = signal('pre_save')
     9post_save = signal('post_save')
     10
     11pre_delete = signal('pre_delete')
     12post_delete = signal('post_delete')
     13
     14post_syncdb = signal('post_syncdb')
  • django/dispatch/__init__.py

    === modified file 'django/dispatch/__init__.py'
     
    44__author__ = "Patrick K. O'Brien"
    55__license__ = "BSD-style, see license.txt for details"
    66
     7class _signal(object):
     8    def __init__(self, label):
     9        self.label = label
     10
     11    def __str__(self):
     12        return self.label
     13
     14    def __repr__(self):
     15        return "<signal signal=%r @#%x>" % (self.label, id(self))
     16
     17def signal(signal_name, docstring=None):
     18    if docstring is None:
     19        return _signal(signal_name)
     20    class signal(_signal):
     21        __doc__ = docstring
     22    return signal(signal_name)
  • django/dispatch/dispatcher.py

    === modified file 'django/dispatch/dispatcher.py'
     
    2626        vs. the original code.)
    2727"""
    2828import types, weakref
    29 from django.dispatch import saferef, robustapply, errors
     29from django.dispatch import saferef, robustapply, errors, signal
    3030
    3131__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
    3232__cvsid__ = "$Id: dispatcher.py,v 1.9 2005/09/17 04:55:57 mcfletch Exp $"
    3333__version__ = "$Revision: 1.9 $"[11:-2]
    3434
    35 
    36 class _Parameter:
    37     """Used to represent default parameter values."""
    38     def __repr__(self):
    39         return self.__class__.__name__
    40 
    41 class _Any(_Parameter):
     35Any = signal('Any',
    4236    """Singleton used to signal either "Any Sender" or "Any Signal"
    4337
    4438    The Any object can be used with connect, disconnect,
    4539    send, or sendExact to signal that the parameter given
    4640    Any should react to all senders/signals, not just
    4741    a particular sender/signal.
    48     """
    49 Any = _Any()
     42    """)
    5043
    51 class _Anonymous(_Parameter):
     44Anonymous = signal('Anonymous',
    5245    """Singleton used to signal "Anonymous Sender"
    5346
    5447    The Anonymous object is used to signal that the sender
     
    6558        in either function then all messages are routed
    6659        as though there was a single sender (Anonymous)
    6760        being used everywhere.
    68     """
    69 Anonymous = _Anonymous()
     61    """)
    7062
    7163WEAKREF_TYPES = (weakref.ReferenceType, saferef.BoundMethodWeakref)
    7264
Back to Top