def TransformName(r, undefined=''):
  """Returns a resorce name from an URI.

  Args:
    r: JSON-serializable object.
    undefined: Returns this value if the resource cannot be formatted.

  Returns:
    A project name for selfLink from r.
  """
  if r:
    try:
      return r.split('/')[-1]
    except AttributeError:
      pass
  return undefined