import re


def parse(filename):
  """Searches the file for lines that start with `# TEAM:` or `# COMPONENT:`.

  Args:
    filename (str): path to the file to parse.
  Returns:
    (team (str), component(str)): The team and component found in the file, the
        last one of each if multiple, None if missing.
  """
  team = None
  component = None
  team_regex = re.compile('\s*#\s*TEAM\s*:\s*(\S+)')
  component_regex = re.compile('\s*#\s*COMPONENT\s*:\s*(\S+)')
  with open(filename) as f:
    for line in f:
      team_matches = team_regex.match(line)
      if team_matches:
        team = team_matches.group(1)
      component_matches = component_regex.match(line)
      if component_matches:
        component = component_matches.group(1)
  return team, component