def cursor(self):
    """Get a serialized cursor for an already executed query.

    The returned cursor effectively lets a future invocation of a similar
    query to begin fetching results immediately after the last returned
    result from this query invocation.

    Returns:
      A base64-encoded serialized cursor.
    """
    if not self._compile:
      raise AssertionError('No cursor available, this action does not support '
                           'cursors (try "fetch" instead)')
    try:
      if not self._compiled_query:
        return self._compiled_query
      if isinstance(self._compiled_query, Exception):
        raise self._compiled_query

      pb = datastore_pb.CompiledQuery()
      pb.set_keys_only(self._compiled_query.keys_only())
      if (self._compiled_query.has_primaryscan() and
          self._compiled_query.primaryscan().has_start_key()):
        start_key = self._compiled_query.primaryscan().start_key()
        start_inclusive = self._compiled_query.primaryscan().start_inclusive()
        primary_scan = pb.mutable_primaryscan()
        primary_scan.set_start_key(start_key)
        primary_scan.set_start_inclusive(start_inclusive)

      if self._compiled_query.has_offset():
        pb.set_offset(self._compiled_query.offset())

      return base64.urlsafe_b64encode(pb.Encode())
    except AttributeError:
      raise AssertionError('No cursor available, this query has not been '
                           'executed')
dataset/ETHPy150Open CollabQ/CollabQ/.google_appengine/google/appengine/ext/db/__init__.py/_BaseQuery.cursor/original