'Add query filter to restrict to this key range.
Args:
query: A datastore.Query instance.
Returns:
The input query restricted to this key range.'

def filter_datastore_query(self, query):

    assert isinstance(query, datastore.Query)
    if self._app:
        query.__app = self._app
    if self.include_start:
        start_comparator = '>='
    else:
        start_comparator = '>'
    if self.include_end:
        end_comparator = '<='
    else:
        end_comparator = '<'
    if self.key_start:
        query.update({('__key__    %s' % start_comparator): self.key_start})
    if self.key_end:
        query.update({('__key__    %s' % end_comparator): self.key_end})
    return query
