def FixKeys(entity_proto, app_id):
 def FixKey(mutable_key):
  mutable_key.set_app(app_id)
 def FixPropertyList(property_list):
  for prop in property_list:
   prop_value = prop.mutable_value()
   if prop_value.has_referencevalue():
    FixKey(prop_value.mutable_referencevalue())
   elif (prop.meaning() == entity_pb.Property.ENTITY_PROTO):
    embedded_entity_proto = entity_pb.EntityProto()
    try:
     embedded_entity_proto.ParsePartialFromString(prop_value.stringvalue())
    except Exception:
     logging.exception('Failed to fix-keys for property %s of %s', prop.name(), entity_proto.key())
    else:
     FixKeys(embedded_entity_proto, app_id)
     prop_value.set_stringvalue(embedded_entity_proto.SerializePartialToString())
 if (entity_proto.has_key() and entity_proto.key().path().element_size()):
  FixKey(entity_proto.mutable_key())
 FixPropertyList(entity_proto.property_list())
 FixPropertyList(entity_proto.raw_property_list())

def FixKeys ( entity_proto , app_id ) : def FixKey ( mutable_key ) : mutable_key . set_app ( app_id ) def FixPropertyList ( property_list ) : for prop in property_list : prop_value = prop . mutable_value ( ) if prop_value . has_referencevalue ( ) : FixKey ( prop_value . mutable_referencevalue ( ) ) elif ( prop . meaning ( ) == entity_pb . Property . ENTITY_PROTO ) : embedded_entity_proto = entity_pb . EntityProto ( ) try : embedded_entity_proto . ParsePartialFromString ( prop_value . stringvalue ( ) ) except Exception : logging . exception ( 'Failed to fix-keys for property %s of %s' , prop . name ( ) , entity_proto . key ( ) ) else : FixKeys ( embedded_entity_proto , app_id ) prop_value . set_stringvalue ( embedded_entity_proto . SerializePartialToString ( ) ) if ( entity_proto . has_key ( ) and entity_proto . key ( ) . path ( ) . element_size ( ) ) : FixKey ( entity_proto . mutable_key ( ) ) FixPropertyList ( entity_proto . property_list ( ) ) FixPropertyList ( entity_proto . raw_property_list ( ) )
go over keys in the given entity and update the application id .