mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Reworded docstrings and settings documentation from [1068]
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1098 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -4,24 +4,17 @@ def curry(*args, **kwargs):
|
||||
return _curried
|
||||
|
||||
def lazy(func, *resultclasses):
|
||||
|
||||
"""
|
||||
lazy turns any callable passed in into a lazy evaluated callable.
|
||||
you need to give result classes or types - at least one is needed
|
||||
so that the automatic forcing of the lazy evaluation code is
|
||||
triggered. Results are not memoized - the function is evaluated
|
||||
on every access.
|
||||
Turns any callable into a lazy evaluated callable. You need to give result
|
||||
classes or types -- at least one is needed so that the automatic forcing of
|
||||
the lazy evaluation code is triggered. Results are not memoized; the
|
||||
function is evaluated on every access.
|
||||
"""
|
||||
|
||||
class __proxy__:
|
||||
|
||||
"""
|
||||
This inner class encapsulates the code that should be evaluated
|
||||
lazyly. On calling of one of the magic methods it will force
|
||||
the evaluation and store the result - afterwards the result
|
||||
is delivered directly. So the result is memoized.
|
||||
"""
|
||||
|
||||
# This inner class encapsulates the code that should be evaluated
|
||||
# lazily. On calling of one of the magic methods it will force
|
||||
# the evaluation and store the result. Afterwards, the result
|
||||
# is delivered directly. So the result is memoized.
|
||||
def __init__(self, args, kw):
|
||||
self.__func = func
|
||||
self.__args = args
|
||||
@@ -31,35 +24,23 @@ def lazy(func, *resultclasses):
|
||||
self.__dispatch[resultclass] = {}
|
||||
for (k, v) in resultclass.__dict__.items():
|
||||
setattr(self, k, self.__promise__(resultclass, k, v))
|
||||
|
||||
|
||||
def __promise__(self, klass, funcname, func):
|
||||
|
||||
"""
|
||||
This function builds a wrapper around some magic method and
|
||||
registers that magic method for the given type and methodname.
|
||||
"""
|
||||
|
||||
# Builds a wrapper around some magic method and registers that magic
|
||||
# method for the given type and method name.
|
||||
def __wrapper__(*args, **kw):
|
||||
"""
|
||||
This wrapper function automatically triggers the evaluation of
|
||||
a lazy value. It then applies the given magic method of the
|
||||
result type.
|
||||
"""
|
||||
# Automatically triggers the evaluation of a lazy value and
|
||||
# applies the given magic method of the result type.
|
||||
res = self.__func(*self.__args, **self.__kw)
|
||||
return self.__dispatch[type(res)][funcname](res, *args, **kw)
|
||||
|
||||
|
||||
if not self.__dispatch.has_key(klass):
|
||||
self.__dispatch[klass] = {}
|
||||
self.__dispatch[klass][funcname] = func
|
||||
return __wrapper__
|
||||
|
||||
|
||||
def __wrapper__(*args, **kw):
|
||||
"""
|
||||
This wrapper function just creates the proxy object that is returned
|
||||
instead of the actual value.
|
||||
"""
|
||||
# Creates the proxy object, instead of the actual value.
|
||||
return __proxy__(args, kw)
|
||||
|
||||
return __wrapper__
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user