mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed reverse URL lookup using functions when the original URL pattern was a
string. This is now just as fragile as it was prior to [5609], but works in a few cases that people were relying on, apparently. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5632 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -3,18 +3,20 @@ def curry(_curried_func, *args, **kwargs):
|
||||
return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
|
||||
return _curried
|
||||
|
||||
def memoize(func, cache):
|
||||
def memoize(func, cache, num_args):
|
||||
"""
|
||||
Wrap a function so that results for any argument tuple are stored in
|
||||
'cache'. Note that the args to the function must be usable as dictionary
|
||||
keys.
|
||||
|
||||
Only the first num_args are considered when creating the key.
|
||||
"""
|
||||
def wrapper(*args):
|
||||
if args in cache:
|
||||
return cache[args]
|
||||
|
||||
mem_args = args[:num_args]
|
||||
if mem_args in cache:
|
||||
return cache[mem_args]
|
||||
result = func(*args)
|
||||
cache[args] = result
|
||||
cache[mem_args] = result
|
||||
return result
|
||||
return wrapper
|
||||
|
||||
|
||||
Reference in New Issue
Block a user