def _GetEnumValue(helper, name_or_value):
  """Maps an enum name to its value. Checks that a value is valid."""
  if isinstance(name_or_value, int):
    helper.Name(name_or_value)  # Raises EnumError if not a valid value.
    return name_or_value
  else:
    return helper.Value(name_or_value)