def ReferenceToKeyValue(key, id_resolver=None):
 if (datastore_pbs._CLOUD_DATASTORE_ENABLED and isinstance(key, googledatastore.Key)):
  v1_key = key
  key = entity_pb.Reference()
  datastore_pbs.get_entity_converter(id_resolver).v1_to_v3_reference(v1_key, key)
 elif isinstance(key, entity_v4_pb.Key):
  v4_key = key
  key = entity_pb.Reference()
  datastore_pbs.get_entity_converter().v4_to_v3_reference(v4_key, key)
 if isinstance(key, entity_pb.Reference):
  element_list = key.path().element_list()
 elif isinstance(key, entity_pb.PropertyValue_ReferenceValue):
  element_list = key.pathelement_list()
 else:
  raise datastore_errors.BadArgumentError(('key arg expected to be entity_pb.Reference or googledatastore.Key (%r)' % (key,)))
 result = [entity_pb.PropertyValue.kReferenceValueGroup, key.app(), key.name_space()]
 for element in element_list:
  result.append(element.type())
  if element.has_name():
   result.append(element.name())
  else:
   result.append(element.id())
 return tuple(result)

def ReferenceToKeyValue ( key , id_resolver = None ) : if ( datastore_pbs . _CLOUD_DATASTORE_ENABLED and isinstance ( key , googledatastore . Key ) ) : v1_key = key key = entity_pb . Reference ( ) datastore_pbs . get_entity_converter ( id_resolver ) . v1_to_v3_reference ( v1_key , key ) elif isinstance ( key , entity_v4_pb . Key ) : v4_key = key key = entity_pb . Reference ( ) datastore_pbs . get_entity_converter ( ) . v4_to_v3_reference ( v4_key , key ) if isinstance ( key , entity_pb . Reference ) : element_list = key . path ( ) . element_list ( ) elif isinstance ( key , entity_pb . PropertyValue_ReferenceValue ) : element_list = key . pathelement_list ( ) else : raise datastore_errors . BadArgumentError ( ( 'key arg expected to be entity_pb.Reference or googledatastore.Key (%r)' % ( key , ) ) ) result = [ entity_pb . PropertyValue . kReferenceValueGroup , key . app ( ) , key . name_space ( ) ] for element in element_list : result . append ( element . type ( ) ) if element . has_name ( ) : result . append ( element . name ( ) ) else : result . append ( element . id ( ) ) return tuple ( result )
converts a key into a comparable hashable "key" value .