def _memoize(func, *args, **opts):
 if opts:
  key = (args, frozenset(opts.items()))
 else:
  key = args
 cache = func.cache
 try:
  result = cache[key]
 except KeyError:
  result = cache[key] = func(*args, **opts)
 return result

def _memoize ( func , * args , ** opts ) : if opts : key = ( args , frozenset ( opts . items ( ) ) ) else : key = args cache = func . cache try : result = cache [ key ] except KeyError : result = cache [ key ] = func ( * args , ** opts ) return result
implements memoized cache lookups .