code: def parse_zone_details(zone_contents):
      
      records = []
      bad_lines = []
      zone_lines = [line.strip() for line in zone_contents.split('\n')]
  
      zone_search = re.search(r'^\$ORIGIN (?P<zone>.*)\.', zone_lines[0])
      zone = zone_search.group('zone')
  
      for line in zone_lines[1:]:
          record_search = re.search(RECORD_REGEX, line)
          if record_search is None:
              bad_lines.append(line)
              continue
  
          name = record_search.group('domain')
          # The API requires we send a host, although bind allows a blank
          # entry. @ is the same thing as blank
          if name is None:
              name = "@"
  
          ttl = record_search.group('ttl')
          # we don't do anything with the class
          # domain_class = domainSearch.group('class')
          record_type = record_search.group('type').upper()
          data = record_search.group('data')
  
          # the dns class doesn't support weighted MX records yet, so we chomp
          # that part out.
          if record_type == "MX":
              record_search = re.search(r'(?P<weight>\d+)\s+(?P<data>.*)', data)
              data = record_search.group('data')
  
          # This will skip the SOA record bit. And any domain that gets
          # parsed oddly.
          if record_type == 'IN':
              bad_lines.append(line)
              continue
  
          records.append({
              'record': name,
              'type': record_type,
              'data': data,
              'ttl': ttl,
          })
  
      return zone, records, bad_lines
docs: Parses a zone file into python data-structures.