def _to_pb()

in src/google/appengine/datastore/datastore_query.py [0:0]


  def _to_pb(self, conn, query_options):
    """Returns the internal only pb representation."""
    pb = self._key_filter._to_pb()


    if self._filter_predicate:
      for f in self._filter_predicate._to_pbs():
        pb.filter.add().CopyFrom(f)


    if self._order:
      for order in self._order._to_pbs():
        pb.order.add().CopyFrom(order)


    if QueryOptions.keys_only(query_options, conn.config):
      pb.keys_only = True

    projection = QueryOptions.projection(query_options, conn.config)
    self._validate_projection_and_group_by(projection, self._group_by)

    if projection:
      pb.property_name.extend(projection)


    if self._group_by:
      pb.group_by_property_name.extend(self._group_by)

    if QueryOptions.produce_cursors(query_options, conn.config):
      pb.compile = True

    limit = QueryOptions.limit(query_options, conn.config)
    if limit is not None:
      pb.limit = limit

    count = QueryOptions.prefetch_size(query_options, conn.config)
    if count is None:
      count = QueryOptions.batch_size(query_options, conn.config)
    if count is not None:
      pb.count = count


    if query_options.offset:
      pb.offset = query_options.offset


    if query_options.start_cursor is not None:
      try:
        pb.compiled_cursor.ParseFromString(
            query_options.start_cursor.to_bytes())
      except message.DecodeError:
        raise datastore_errors.BadValueError('invalid cursor')


    if query_options.end_cursor is not None:
      try:
        pb.end_compiled_cursor.ParseFromString(
            query_options.end_cursor.to_bytes())
      except message.DecodeError:
        raise datastore_errors.BadValueError('invalid cursor')


    if ((query_options.hint == QueryOptions.ORDER_FIRST and len(pb.order)) or
        (query_options.hint == QueryOptions.ANCESTOR_FIRST and
         pb.HasField('ancestor')) or
        (query_options.hint == QueryOptions.FILTER_FIRST and pb.filter)):
      pb.hint = query_options.hint

    if self.read_time_us is not None:
      pb.read_time_us = self.read_time_us


    conn._set_request_read_policy(pb, query_options)
    conn._set_request_transaction(pb)

    return pb