diff --git a/src/util/__init__.py b/src/util/__init__.py index e64c0fc5e..5cee29f55 100644 --- a/src/util/__init__.py +++ b/src/util/__init__.py @@ -1,4 +1,5 @@ +# Decorator the specifies bjam-side prototype for a Python function def bjam_signature(s): def wrap(f): @@ -6,3 +7,23 @@ def bjam_signature(s): return f return wrap + +class cached(object): + + def __init__(self, function): + self.function = function + self.cache = {} + + def __call__(self, *args): + try: + return self.cache[args] + except KeyError: + v = self.function(*args) + self.cache[args] = v + return v + +def unquote(s): + if s and s[0] == '"' and s[-1] == '"': + return s[1:-1] + else: + return s