def from_protobuf(cls, pb): entity = cls(key=Key.from_protobuf(pb.key)) for property_pb in pb.property: value = helpers.get_value_from_protobuf(property_pb) entity[property_pb.name] = value return entity
def from_protobuf(cls, pb, dataset=None): """Factory method for creating an entity based on a protobuf. The protobuf should be one returned from the Cloud Datastore Protobuf API. :type key: :class:`gclouddatastore.datastore_v1_pb2.Entity` :param key: The Protobuf representing the entity. :returns: The :class:`Entity` derived from the :class:`gclouddatastore.datastore_v1_pb2.Entity`. """ # This is here to avoid circular imports. from gclouddatastore import helpers key = Key.from_protobuf(pb.key, dataset=dataset) entity = cls.from_key(key) for property_pb in pb.property: value = helpers.get_value_from_protobuf(property_pb) entity[property_pb.name] = value return entity