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