Example #1
0
 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
Example #2
0
 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
Example #3
0
 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
Example #4
0
 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
Example #5
0
 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
Example #7
0
 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