

@classmethod
def _from_pb(cls, pb, set_key=True, ent=None, key=None):
    'Internal helper to create an entity from an EntityProto protobuf.'
    if (not isinstance(pb, entity_pb.EntityProto)):
        raise TypeError(('pb must be a EntityProto; received %r' % pb))
    if (ent is None):
        ent = cls()
    if ((key is None) and pb.key().path().element_size()):
        key = Key(reference=pb.key())
    if ((key is not None) and (set_key or key.id() or key.parent())):
        ent._key = key
    projection = []
    for (indexed, plist) in ((True, pb.property_list()), (False, pb.raw_property_list())):
        for p in plist:
            if (p.meaning() == entity_pb.Property.INDEX_VALUE):
                projection.append(p.name())
            ent._get_property_for(p, indexed)._deserialize(ent, p)
    ent._set_projection(projection)
    return ent

dataset/ETHPy150Open GoogleCloudPlatform/datastore-ndb-python/ndb/model.py Model._from_pb/original