def entity_from_protobuf(pb):
 key = None
 if pb.HasField('key'):
  key = key_from_protobuf(pb.key)
 entity_props = {}
 entity_meanings = {}
 exclude_from_indexes = []
 for (prop_name, value_pb) in _property_tuples(pb):
  value = _get_value_from_value_pb(value_pb)
  entity_props[prop_name] = value
  is_list = isinstance(value, list)
  meaning = _get_meaning(value_pb, is_list=is_list)
  if (meaning is not None):
   entity_meanings[prop_name] = (meaning, value)
  if is_list:
   exclude_values = set((value_pb.exclude_from_indexes for value_pb in value_pb.array_value.values))
   if (len(exclude_values) != 1):
    raise ValueError('For an array_value, subvalues must either all be indexed or all excluded from indexes.')
   if exclude_values.pop():
    exclude_from_indexes.append(prop_name)
  elif value_pb.exclude_from_indexes:
   exclude_from_indexes.append(prop_name)
 entity = Entity(key=key, exclude_from_indexes=exclude_from_indexes)
 entity.update(entity_props)
 entity._meanings.update(entity_meanings)
 return entity

def entity_from_protobuf ( pb ) : key = None if pb . HasField ( 'key' ) : key = key_from_protobuf ( pb . key ) entity_props = { } entity_meanings = { } exclude_from_indexes = [ ] for ( prop_name , value_pb ) in _property_tuples ( pb ) : value = _get_value_from_value_pb ( value_pb ) entity_props [ prop_name ] = value is_list = isinstance ( value , list ) meaning = _get_meaning ( value_pb , is_list = is_list ) if ( meaning is not None ) : entity_meanings [ prop_name ] = ( meaning , value ) if is_list : exclude_values = set ( ( value_pb . exclude_from_indexes for value_pb in value_pb . array_value . values ) ) if ( len ( exclude_values ) != 1 ) : raise ValueError ( 'For an array_value, subvalues must either all be indexed or all excluded from indexes.' ) if exclude_values . pop ( ) : exclude_from_indexes . append ( prop_name ) elif value_pb . exclude_from_indexes : exclude_from_indexes . append ( prop_name ) entity = Entity ( key = key , exclude_from_indexes = exclude_from_indexes ) entity . update ( entity_props ) entity . _meanings . update ( entity_meanings ) return entity
factory method for creating an entity based on a protobuf .