'Add query filter to restrict to this key range.
Args:
query: An 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_ndb_query(self, query, filters=None):

    assert _IsNdbQuery(query)
    if filters:
        for f in filters:
            query = query.filter(ndb.FilterNode(*f))
    if self.include_start:
        start_comparator = '>='
    else:
        start_comparator = '>'
    if self.include_end:
        end_comparator = '<='
    else:
        end_comparator = '<'
    if self.key_start:
        query = query.filter(ndb.FilterNode('__key__', start_comparator, self.key_start))
    if self.key_end:
        query = query.filter(ndb.FilterNode('__key__', end_comparator, self.key_end))
    return query
