def get_key_value(parts, key_field_num, ignore_missing_keys, seen_keys,
                  output_type):
  """
  get the key value from the line and check it's not a dup. or missing. fields
  with only whitespace are considered empty (missing).

  :param ignore_missing_keys: if True, return None for missing keys. If false,
                              missing keys cause an exception
                              (MissingKeyError).
  :param seen_keys: a set of keys already seen.

  :return: the key value, or None if the field was empty.
  """
  key_val = parts[key_field_num]
  if key_val.strip() == "":
    if not ignore_missing_keys:
      raise MissingKeyError("missing key value")
    else:
      return None

  if key_val in seen_keys and \
     output_type is OutputType.error_on_dups:
    raise DuplicateKeyError(key_val + " appears multiple times as key")

  return key_val
get the key value from the line and check it's not a dup. or missing. fields
  with only whitespace are considered empty (missing).

  :param ignore_missing_keys: if True, return None for missing keys. If false,
                              missing keys cause an exception
                              (MissingKeyError).
  :param seen_keys: a set of keys already seen.

  :return: the key value, or None if the field was empty.