def _parse(self, contents): entries = [] for (i, line) in enumerate(contents.splitlines()): sline = line.strip() if not sline: entries.append(("blank", [line])) continue (head, tail) = chop_comment(line, ";#") if not len(head.strip()): entries.append(("all_comment", [line])) continue if not tail: tail = "" try: (cfg_opt, cfg_values) = head.split(None, 1) except (IndexError, ValueError) as e: raise IOError("Incorrectly formatted resolv.conf line %s" % (i + 1)) from e if cfg_opt not in [ "nameserver", "domain", "search", "sortlist", "options", ]: raise IOError("Unexpected resolv.conf option %s" % (cfg_opt)) entries.append(("option", [cfg_opt, cfg_values, tail])) return entries
def _parse(self, contents): entries = [] for line in contents.splitlines(): if not len(line.strip()): entries.append(('blank', [line])) continue (head, tail) = chop_comment(line.strip(), '#') if not len(head): entries.append(('all_comment', [line])) continue entries.append(('option', [head.split(None), tail])) return entries
def _parse(self, contents): entries = [] hostnames_found = set() for line in contents.splitlines(): if not len(line.strip()): entries.append(('blank', [line])) continue (head, tail) = chop_comment(line.strip(), '#') if not len(head): entries.append(('all_comment', [line])) continue entries.append(('hostname', [head, tail])) hostnames_found.add(head) if len(hostnames_found) > 1: raise IOError("Multiple hostnames (%s) found!" % (hostnames_found)) return entries
def _parse(self, contents): entries = [] for (i, line) in enumerate(contents.splitlines()): sline = line.strip() if not sline: entries.append(('blank', [line])) continue (head, tail) = chop_comment(line, ';#') if not len(head.strip()): entries.append(('all_comment', [line])) continue if not tail: tail = '' try: (cfg_opt, cfg_values) = head.split(None, 1) except (IndexError, ValueError): raise IOError("Incorrectly formatted resolv.conf line %s" % (i + 1)) if cfg_opt not in ['nameserver', 'domain', 'search', 'sortlist', 'options']: raise IOError("Unexpected resolv.conf option %s" % (cfg_opt)) entries.append(("option", [cfg_opt, cfg_values, tail])) return entries