def v1_key_to_string(v1_key):
  """Generates a string representing a key's path.

  The output makes no effort to qualify special characters in strings.

  The key need not be valid, but if any of the key path elements have
  both a name and an ID the name is ignored.

  Args:
    v1_key: an googledatastore.Key

  Returns:
    a string representing the key's path
  """
  path_element_strings = []
  for path_element in v1_key.path:
    field = path_element.WhichOneof('id_type')
    if field == 'id':
      id_or_name = str(path_element.id)
    elif field == 'name':
      id_or_name = path_element.name
    else:
      id_or_name = ''
    path_element_strings.append('%s: %s' % (path_element.kind, id_or_name))
  return '[%s]' % ', '.join(path_element_strings)
dataset/ETHPy150Open GoogleCloudPlatform/python-compat-runtime/appengine-compat/exported_appengine_sdk/google/appengine/datastore/datastore_pbs.py/v1_key_to_string/original