summaryrefslogtreecommitdiff
path: root/django/dispatch
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-11-03 21:43:11 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-11-03 22:08:05 +0100
commitd7688a010a34033a5cc8eecf7b1460169c0e056e (patch)
treeec6e0ffea3410d0c7b743d77d123f5eba1db8a0e /django/dispatch
parentbe6522561f01aa2a0b503fb35f35c9fd34c5110f (diff)
[1.5.x] Fixed #18963 -- Used a subclass-friendly pattern
for Python 2 object model compatibility methods. Backport of fc10418 from master.
Diffstat (limited to 'django/dispatch')
-rw-r--r--django/dispatch/saferef.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/django/dispatch/saferef.py b/django/dispatch/saferef.py
index 84d1b2183c..7423669c96 100644
--- a/django/dispatch/saferef.py
+++ b/django/dispatch/saferef.py
@@ -67,9 +67,9 @@ class BoundMethodWeakref(object):
same BoundMethodWeakref instance.
"""
-
+
_allInstances = weakref.WeakValueDictionary()
-
+
def __new__( cls, target, onDelete=None, *arguments,**named ):
"""Create new instance or return current instance
@@ -92,7 +92,7 @@ class BoundMethodWeakref(object):
cls._allInstances[key] = base
base.__init__( target, onDelete, *arguments,**named)
return base
-
+
def __init__(self, target, onDelete=None):
"""Return a weak-reference-like instance for a bound method
@@ -132,7 +132,7 @@ class BoundMethodWeakref(object):
self.weakFunc = weakref.ref(target.__func__, remove)
self.selfName = str(target.__self__)
self.funcName = str(target.__func__.__name__)
-
+
def calculateKey( cls, target ):
"""Calculate the reference key for this reference
@@ -141,7 +141,7 @@ class BoundMethodWeakref(object):
"""
return (id(target.__self__),id(target.__func__))
calculateKey = classmethod( calculateKey )
-
+
def __str__(self):
"""Give a friendly representation of the object"""
return """%s( %s.%s )"""%(
@@ -157,14 +157,16 @@ class BoundMethodWeakref(object):
def __bool__( self ):
"""Whether we are still a valid reference"""
return self() is not None
- __nonzero__ = __bool__ # Python 2
+
+ def __nonzero__(self): # Python 2 compatibility
+ return type(self).__bool__(self)
def __eq__(self, other):
"""Compare with another reference"""
if not isinstance(other, self.__class__):
return self.__class__ == type(other)
return self.key == other.key
-
+
def __call__(self):
"""Return a strong reference to the bound method