mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
[py3] Added Python 3 compatibility for xrange.
This commit is contained in:
@@ -2,6 +2,7 @@ import weakref
|
||||
import threading
|
||||
|
||||
from django.dispatch import saferef
|
||||
from django.utils.six.moves import xrange
|
||||
|
||||
WEAKREF_TYPES = (weakref.ReferenceType, saferef.BoundMethodWeakref)
|
||||
|
||||
@@ -13,17 +14,17 @@ def _make_id(target):
|
||||
class Signal(object):
|
||||
"""
|
||||
Base class for all signals
|
||||
|
||||
|
||||
Internal attributes:
|
||||
|
||||
|
||||
receivers
|
||||
{ receriverkey (id) : weakref(receiver) }
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, providing_args=None):
|
||||
"""
|
||||
Create a new signal.
|
||||
|
||||
|
||||
providing_args
|
||||
A list of the arguments this signal can pass along in a send() call.
|
||||
"""
|
||||
@@ -36,9 +37,9 @@ class Signal(object):
|
||||
def connect(self, receiver, sender=None, weak=True, dispatch_uid=None):
|
||||
"""
|
||||
Connect receiver to sender for signal.
|
||||
|
||||
|
||||
Arguments:
|
||||
|
||||
|
||||
receiver
|
||||
A function or an instance method which is to receive signals.
|
||||
Receivers must be hashable objects.
|
||||
@@ -46,7 +47,7 @@ class Signal(object):
|
||||
If weak is True, then receiver must be weak-referencable (more
|
||||
precisely saferef.safeRef() must be able to create a reference
|
||||
to the receiver).
|
||||
|
||||
|
||||
Receivers must be able to accept keyword arguments.
|
||||
|
||||
If receivers have a dispatch_uid attribute, the receiver will
|
||||
@@ -62,19 +63,19 @@ class Signal(object):
|
||||
module will attempt to use weak references to the receiver
|
||||
objects. If this parameter is false, then strong references will
|
||||
be used.
|
||||
|
||||
|
||||
dispatch_uid
|
||||
An identifier used to uniquely identify a particular instance of
|
||||
a receiver. This will usually be a string, though it may be
|
||||
anything hashable.
|
||||
"""
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
# If DEBUG is on, check that we got a good receiver
|
||||
if settings.DEBUG:
|
||||
import inspect
|
||||
assert callable(receiver), "Signal receivers must be callable."
|
||||
|
||||
|
||||
# Check for **kwargs
|
||||
# Not all callables are inspectable with getargspec, so we'll
|
||||
# try a couple different ways but in the end fall back on assuming
|
||||
@@ -90,7 +91,7 @@ class Signal(object):
|
||||
if argspec:
|
||||
assert argspec[2] is not None, \
|
||||
"Signal receivers must accept keyword arguments (**kwargs)."
|
||||
|
||||
|
||||
if dispatch_uid:
|
||||
lookup_key = (dispatch_uid, _make_id(sender))
|
||||
else:
|
||||
@@ -112,19 +113,19 @@ class Signal(object):
|
||||
|
||||
If weak references are used, disconnect need not be called. The receiver
|
||||
will be remove from dispatch automatically.
|
||||
|
||||
|
||||
Arguments:
|
||||
|
||||
|
||||
receiver
|
||||
The registered receiver to disconnect. May be none if
|
||||
dispatch_uid is specified.
|
||||
|
||||
|
||||
sender
|
||||
The registered sender to disconnect
|
||||
|
||||
|
||||
weak
|
||||
The weakref state to disconnect
|
||||
|
||||
|
||||
dispatch_uid
|
||||
the unique identifier of the receiver to disconnect
|
||||
"""
|
||||
@@ -149,10 +150,10 @@ class Signal(object):
|
||||
receivers called if a raises an error.
|
||||
|
||||
Arguments:
|
||||
|
||||
|
||||
sender
|
||||
The sender of the signal Either a specific object or None.
|
||||
|
||||
|
||||
named
|
||||
Named arguments which will be passed to receivers.
|
||||
|
||||
@@ -172,7 +173,7 @@ class Signal(object):
|
||||
Send signal from sender to all connected receivers catching errors.
|
||||
|
||||
Arguments:
|
||||
|
||||
|
||||
sender
|
||||
The sender of the signal. Can be any python object (normally one
|
||||
registered with a connect if you actually want something to
|
||||
|
||||
Reference in New Issue
Block a user