'Process f as a file in the /etc/resolv.conf format.  If f is
a string, it is used as the name of the file to open; otherwise it
is treated as the file itself.'

def read_resolv_conf(self, f):

    if (isinstance(f, str) or isinstance(f, unicode)):
        try:
            f = open(f, 'r')
        except IOError:
            self.nameservers = ['127.0.0.1']
            return
        want_close = True
    else:
        want_close = False
    try:
        for l in f:
            if ((len(l) == 0) or (l[0] == '#') or (l[0] == ';')):
                continue
            tokens = l.split()
            if (len(tokens) == 0):
                continue
            if (tokens[0] == 'nameserver'):
                self.nameservers.append(tokens[1])
            elif (tokens[0] == 'domain'):
                self.domain = dns.name.from_text(tokens[1])
            elif (tokens[0] == 'search'):
                for suffix in tokens[1:]:
                    self.search.append(dns.name.from_text(suffix))
    finally:
        if want_close:
            f.close()
    if (len(self.nameservers) == 0):
        self.nameservers.append('127.0.0.1')
