Consolidated some code.

This commit is contained in:
Anthony Sottile 2014-03-16 18:40:16 -07:00
parent 33f5bad484
commit 7b1b72e225
2 changed files with 22 additions and 23 deletions

View file

@ -22,15 +22,16 @@ class cached_property(object):
def memoize_by_cwd(func):
"""Memoize a function call based on os.getcwd()."""
cache = {}
@functools.wraps(func)
def wrapper(*args):
cwd = os.getcwd()
key = (cwd,) + args
try:
return cache[key]
return wrapper._cache[key]
except KeyError:
ret = cache[key] = func(*args)
ret = wrapper._cache[key] = func(*args)
return ret
wrapper._cache = {}
return wrapper