Use `classmethod` as a decorator.
This commit is contained in:
parent
73b3c257e3
commit
4cfe6ba6a3
|
@ -117,6 +117,7 @@ class SimpleUploadedFile(InMemoryUploadedFile):
|
||||||
super(SimpleUploadedFile, self).__init__(BytesIO(content), None, name,
|
super(SimpleUploadedFile, self).__init__(BytesIO(content), None, name,
|
||||||
content_type, len(content), None, None)
|
content_type, len(content), None, None)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def from_dict(cls, file_dict):
|
def from_dict(cls, file_dict):
|
||||||
"""
|
"""
|
||||||
Creates a SimpleUploadedFile object from
|
Creates a SimpleUploadedFile object from
|
||||||
|
@ -128,4 +129,3 @@ class SimpleUploadedFile(InMemoryUploadedFile):
|
||||||
return cls(file_dict['filename'],
|
return cls(file_dict['filename'],
|
||||||
file_dict['content'],
|
file_dict['content'],
|
||||||
file_dict.get('content-type', 'text/plain'))
|
file_dict.get('content-type', 'text/plain'))
|
||||||
from_dict = classmethod(from_dict)
|
|
||||||
|
|
|
@ -135,6 +135,7 @@ class BoundMethodWeakref(object):
|
||||||
self.selfName = str(target.__self__)
|
self.selfName = str(target.__self__)
|
||||||
self.funcName = str(target.__func__.__name__)
|
self.funcName = str(target.__func__.__name__)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def calculateKey(cls, target):
|
def calculateKey(cls, target):
|
||||||
"""Calculate the reference key for this reference
|
"""Calculate the reference key for this reference
|
||||||
|
|
||||||
|
@ -142,7 +143,6 @@ class BoundMethodWeakref(object):
|
||||||
target object and the target function respectively.
|
target object and the target function respectively.
|
||||||
"""
|
"""
|
||||||
return (id(target.__self__), id(target.__func__))
|
return (id(target.__self__), id(target.__func__))
|
||||||
calculateKey = classmethod(calculateKey)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Give a friendly representation of the object"""
|
"""Give a friendly representation of the object"""
|
||||||
|
|
|
@ -93,6 +93,7 @@ def lazy(func, *resultclasses):
|
||||||
(func, self.__args, self.__kw) + resultclasses
|
(func, self.__args, self.__kw) + resultclasses
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def __prepare_class__(cls):
|
def __prepare_class__(cls):
|
||||||
cls.__dispatch = {}
|
cls.__dispatch = {}
|
||||||
for resultclass in resultclasses:
|
for resultclass in resultclasses:
|
||||||
|
@ -119,8 +120,8 @@ def lazy(func, *resultclasses):
|
||||||
cls.__bytes__ = cls.__bytes_cast
|
cls.__bytes__ = cls.__bytes_cast
|
||||||
else:
|
else:
|
||||||
cls.__str__ = cls.__bytes_cast
|
cls.__str__ = cls.__bytes_cast
|
||||||
__prepare_class__ = classmethod(__prepare_class__)
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def __promise__(cls, klass, funcname, method):
|
def __promise__(cls, klass, funcname, method):
|
||||||
# Builds a wrapper around some magic method and registers that
|
# Builds a wrapper around some magic method and registers that
|
||||||
# magic method for the given type and method name.
|
# magic method for the given type and method name.
|
||||||
|
@ -137,7 +138,6 @@ def lazy(func, *resultclasses):
|
||||||
cls.__dispatch[klass] = {}
|
cls.__dispatch[klass] = {}
|
||||||
cls.__dispatch[klass][funcname] = method
|
cls.__dispatch[klass][funcname] = method
|
||||||
return __wrapper__
|
return __wrapper__
|
||||||
__promise__ = classmethod(__promise__)
|
|
||||||
|
|
||||||
def __text_cast(self):
|
def __text_cast(self):
|
||||||
return func(*self.__args, **self.__kw)
|
return func(*self.__args, **self.__kw)
|
||||||
|
|
|
@ -27,6 +27,7 @@ class Node(object):
|
||||||
|
|
||||||
# We need this because of django.db.models.query_utils.Q. Q. __init__() is
|
# We need this because of django.db.models.query_utils.Q. Q. __init__() is
|
||||||
# problematic, but it is a natural Node subclass in all other respects.
|
# problematic, but it is a natural Node subclass in all other respects.
|
||||||
|
@classmethod
|
||||||
def _new_instance(cls, children=None, connector=None, negated=False):
|
def _new_instance(cls, children=None, connector=None, negated=False):
|
||||||
"""
|
"""
|
||||||
This is called to create a new instance of this class when we need new
|
This is called to create a new instance of this class when we need new
|
||||||
|
@ -39,7 +40,6 @@ class Node(object):
|
||||||
obj = Node(children, connector, negated)
|
obj = Node(children, connector, negated)
|
||||||
obj.__class__ = cls
|
obj.__class__ = cls
|
||||||
return obj
|
return obj
|
||||||
_new_instance = classmethod(_new_instance)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.negated:
|
if self.negated:
|
||||||
|
|
Loading…
Reference in New Issue