1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixed #21266 -- Fixed E201,E202 pep8 warnings.

This commit is contained in:
Larry O'Neill
2013-10-14 20:13:14 +01:00
committed by Tim Graham
parent 42a67ec1cd
commit 83b9bfea44
35 changed files with 152 additions and 145 deletions

View File

@@ -32,7 +32,7 @@ def safeRef(target, onDelete = None):
if callable(onDelete):
return weakref.ref(target, onDelete)
else:
return weakref.ref( target )
return weakref.ref(target)
class BoundMethodWeakref(object):
"""'Safe' and reusable weak references to instance methods
@@ -70,7 +70,7 @@ class BoundMethodWeakref(object):
_allInstances = weakref.WeakValueDictionary()
def __new__( cls, target, onDelete=None, *arguments,**named ):
def __new__(cls, target, onDelete=None, *arguments,**named):
"""Create new instance or return current instance
Basically this method of construction allows us to
@@ -85,12 +85,12 @@ class BoundMethodWeakref(object):
key = cls.calculateKey(target)
current =cls._allInstances.get(key)
if current is not None:
current.deletionMethods.append( onDelete)
current.deletionMethods.append(onDelete)
return current
else:
base = super( BoundMethodWeakref, cls).__new__( cls )
base = super(BoundMethodWeakref, cls).__new__(cls)
cls._allInstances[key] = base
base.__init__( target, onDelete, *arguments,**named)
base.__init__(target, onDelete, *arguments,**named)
return base
def __init__(self, target, onDelete=None):
@@ -112,13 +112,13 @@ class BoundMethodWeakref(object):
methods = self.deletionMethods[:]
del self.deletionMethods[:]
try:
del self.__class__._allInstances[ self.key ]
del self.__class__._allInstances[self.key]
except KeyError:
pass
for function in methods:
try:
if callable( function ):
function( self )
if callable(function):
function(self)
except Exception as e:
try:
traceback.print_exc()
@@ -127,20 +127,20 @@ class BoundMethodWeakref(object):
self, function, e)
)
self.deletionMethods = [onDelete]
self.key = self.calculateKey( target )
self.key = self.calculateKey(target)
self.weakSelf = weakref.ref(target.__self__, remove)
self.weakFunc = weakref.ref(target.__func__, remove)
self.selfName = str(target.__self__)
self.funcName = str(target.__func__.__name__)
def calculateKey( cls, target ):
def calculateKey(cls, target):
"""Calculate the reference key for this reference
Currently this is a two-tuple of the id()'s of the
target object and the target function respectively.
"""
return (id(target.__self__),id(target.__func__))
calculateKey = classmethod( calculateKey )
calculateKey = classmethod(calculateKey)
def __str__(self):
"""Give a friendly representation of the object"""
@@ -155,7 +155,7 @@ class BoundMethodWeakref(object):
def __hash__(self):
return hash(self.key)
def __bool__( self ):
def __bool__(self):
"""Whether we are still a valid reference"""
return self() is not None