Changeset 5632
- Timestamp:
- 07/07/07 19:39:32 (1 year ago)
- Files:
-
- django/trunk/django/core/urlresolvers.py (modified) (2 diffs)
- django/trunk/django/utils/functional.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/urlresolvers.py
r5630 r5632 39 39 during the import fail and the string is returned. 40 40 """ 41 try: 42 # Bail out early if lookup_view is not ASCII. This can't be a function. 43 lookup_view = lookup_view.encode('ascii') 44 45 if not callable(lookup_view): 41 if not callable(lookup_view): 42 try: 43 # Bail early for non-ASCII strings (they can't be functions). 44 lookup_view = lookup_view.encode('ascii') 46 45 mod_name, func_name = get_mod_func(lookup_view) 47 try: 48 if func_name != '': 49 lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) 50 except (ImportError, AttributeError): 51 if not can_fail: 52 raise 53 except UnicodeEncodeError: 54 pass 46 if func_name != '': 47 lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) 48 except (ImportError, AttributeError): 49 if not can_fail: 50 raise 51 except UnicodeEncodeError: 52 pass 55 53 return lookup_view 56 get_callable = memoize(get_callable, _callable_cache )54 get_callable = memoize(get_callable, _callable_cache, 1) 57 55 58 56 def get_resolver(urlconf): … … 61 59 urlconf = settings.ROOT_URLCONF 62 60 return RegexURLResolver(r'^/', urlconf) 63 get_resolver = memoize(get_resolver, _resolver_cache )61 get_resolver = memoize(get_resolver, _resolver_cache, 1) 64 62 65 63 def get_mod_func(callback): django/trunk/django/utils/functional.py
r5609 r5632 4 4 return _curried 5 5 6 def memoize(func, cache ):6 def memoize(func, cache, num_args): 7 7 """ 8 8 Wrap a function so that results for any argument tuple are stored in 9 9 'cache'. Note that the args to the function must be usable as dictionary 10 10 keys. 11 12 Only the first num_args are considered when creating the key. 11 13 """ 12 14 def wrapper(*args): 13 if args in cache:14 return cache[args]15 15 mem_args = args[:num_args] 16 if mem_args in cache: 17 return cache[mem_args] 16 18 result = func(*args) 17 cache[ args] = result19 cache[mem_args] = result 18 20 return result 19 21 return wrapper
