def _DecodeCompiledCursor(self, query, compiled_cursor): """Converts a compiled_cursor into a cursor_entity. Returns: (cursor_entity, inclusive): a datastore.Entity and if it should be included in the result set. """ assert len(compiled_cursor.position_list()) == 1 position = compiled_cursor.position(0) entity_pb = datastore_pb.EntityProto() (query_info_encoded, entity_encoded) = position.start_key().split(_CURSOR_CONCAT_STR, 1) query_info_pb = datastore_pb.Query() query_info_pb.ParseFromString(query_info_encoded) self._ValidateQuery(query, query_info_pb) entity_pb.ParseFromString(entity_encoded) return (datastore.Entity._FromPb(entity_pb, True), position.start_inclusive())
def _MinimalEntityInfo(self, entity_proto, query): """Extract the minimal set of information that preserves entity order. Args: entity_proto: datastore_pb.EntityProto instance from which to extract information query: datastore_pb.Query instance for which ordering must be preserved. Returns: datastore_pb.EntityProto instance suitable for matching against a list of results when finding cursor positions. """ entity_info = datastore_pb.EntityProto(); order_names = [o.property() for o in query.order_list()] entity_info.mutable_key().MergeFrom(entity_proto.key()) entity_info.mutable_entity_group().MergeFrom(entity_proto.entity_group()) for prop in entity_proto.property_list(): if prop.name() in order_names: entity_info.add_property().MergeFrom(prop) return entity_info;