def cached_query(model, filter_fn=filter_identity):
 def cached_query_decorator(fn):
  def cached_query_wrapper(*args):
   assert fn.__name__.startswith('get_')
   row_key_components = [fn.__name__[len('get_'):]]
   if (len(args) > 0):
    if isinstance(args[0], Thing):
     args = list(args)
     args[0] = args[0]._id
    if isinstance(args[0], (int, long)):
     serialized = to36(args[0])
    else:
     serialized = str(args[0])
    row_key_components.append(serialized)
   row_key_components.extend((str(x) for x in args[1:]))
   row_key = '.'.join(row_key_components)
   query = fn(*args)
   query_sort = query._sort
   try:
    is_precomputed = query.precomputed
   except AttributeError:
    is_precomputed = _is_query_precomputed(query)
   return CachedQuery(model, row_key, query_sort, filter_fn, is_precomputed)
  return cached_query_wrapper
 return cached_query_decorator

def cached_query ( model , filter_fn = filter_identity ) : def cached_query_decorator ( fn ) : def cached_query_wrapper ( * args ) : assert fn . __name__ . startswith ( 'get_' ) row_key_components = [ fn . __name__ [ len ( 'get_' ) : ] ] if ( len ( args ) > 0 ) : if isinstance ( args [ 0 ] , Thing ) : args = list ( args ) args [ 0 ] = args [ 0 ] . _id if isinstance ( args [ 0 ] , ( int , long ) ) : serialized = to36 ( args [ 0 ] ) else : serialized = str ( args [ 0 ] ) row_key_components . append ( serialized ) row_key_components . extend ( ( str ( x ) for x in args [ 1 : ] ) ) row_key = '.' . join ( row_key_components ) query = fn ( * args ) query_sort = query . _sort try : is_precomputed = query . precomputed except AttributeError : is_precomputed = _is_query_precomputed ( query ) return CachedQuery ( model , row_key , query_sort , filter_fn , is_precomputed ) return cached_query_wrapper return cached_query_decorator
decorate a function describing a cached query .