from typing import Iterator
from typing import Dict
import csv


def _parse_as_to_type_map(f: Iterator[str]) -> Dict[int, str]:
  """Returns a mapping of ASNs to org type info from a file.

  Args:
    f: as2type file object

  Returns:
    Dict {asn -> network_type}
    ex {398243 : "Enterprise", 13335: "Content", 4: "Transit/Access"}
  """
  # filter comments
  data_lines = [line for line in f if line[0] != "#"]
  type_data = list(csv.reader(data_lines, delimiter="|"))

  as_to_type_map: Dict[int, str] = {}
  for line in type_data:
    asn, source, org_type = line
    as_to_type_map[int(asn)] = org_type

  return as_to_type_map