'Add query filter to restrict to this key range.
Args:
query: A db.Query or ndb.Query instance.
filters: optional list of filters to apply to the query. Each filter is
a tuple: (<property_name_as_str>, <query_operation_as_str>, <value>).
User filters are applied first.
Returns:
The input query restricted to this key range.'

def filter_query(self, query, filters=None):

    if (ndb is not None):
        if _IsNdbQuery(query):
            return self.filter_ndb_query(query, filters=filters)
    assert (not _IsNdbQuery(query))
    if filters:
        for f in filters:
            query.filter(('%s    %s' % (f[0], f[1])), f[2])
    if self.include_start:
        start_comparator = '>='
    else:
        start_comparator = '>'
    if self.include_end:
        end_comparator = '<='
    else:
        end_comparator = '<'
    if self.key_start:
        query.filter(('__key__    %s' % start_comparator), self.key_start)
    if self.key_end:
        query.filter(('__key__    %s' % end_comparator), self.key_end)
    return query
