'The function for parsing whois fields from a data input.
Args:
response: The response from the whois/rwhois server.
fields_dict: The dictionary of fields -> regex search values.
net_start: The starting point of the network (if parsing multiple
networks).
net_end: The ending point of the network (if parsing multiple
networks).
dt_format: The format of datetime fields if known.
field_list: If provided, a list of fields to parse:
[\'name\', \'handle\', \'description\', \'country\', \'state\', \'city\',
\'address\', \'postal_code\', \'emails\', \'created\', \'updated\']
Returns:
Dictionary: A dictionary of fields provided in fields_dict.'

def _parse_fields(self, response, fields_dict, net_start=None, net_end=None, dt_format=None, field_list=None):

    ret = {}
    if (not field_list):
        field_list = ['name', 'handle', 'description', 'country', 'state', 'city', 'address', 'postal_code', 'emails', 'created', 'updated']
    generate = ((field, pattern) for (field, pattern) in fields_dict.items() if (field in field_list))
    for (field, pattern) in generate:
        pattern = re.compile(str(pattern), re.DOTALL)
        if (net_start is not None):
            match = pattern.finditer(response, net_end, net_start)
        elif (net_end is not None):
            match = pattern.finditer(response, net_end)
        else:
            match = pattern.finditer(response)
        values = []
        sub_section_end = None
        for m in match:
            if sub_section_end:
                if ((field not in 'emails') and (sub_section_end != (m.start() - 1))):
                    break
            try:
                values.append(m.group('val').strip())
            except IndexError:
                pass
            sub_section_end = m.end()
        if (len(values) > 0):
            value = None
            try:
                if (field == 'country'):
                    value = values[0].upper()
                elif ((field in ['created', 'updated']) and dt_format):
                    value = datetime.strptime(values[0], str(dt_format)).isoformat('T')
                else:
                    values = unique_everseen(values)
                    value = '\n'.join(values)
            except ValueError as e:
                log.debug('Whois    field    parsing    failed    for    {0}:    {1}'.format(field, e))
                pass
            ret[field] = value
    return ret
