def Paginate(self, query, default_limit):
    """Returns a list of entities limited to limit, with a next_page cursor."""
    try:
      limit = int(self.request.get('limit', default_limit))
    except __HOLE__:
      limit = default_limit
    if limit not in QUERY_LIMITS:
      limit = default_limit

    cursor = self.request.get('page', '')
    if cursor:
      query.with_cursor(cursor)

    entities = list(query.fetch(limit))

    if len(entities) == limit:
      next_page = query.cursor()
    else:
      next_page = None

    self._page = {
        'limit': limit,
        'next_page': next_page,
        'results_count': len(entities),
    }

    return entities
dataset/ETHPy150Open google/simian/src/simian/mac/admin/__init__.py/AdminHandler.Paginate