示例#1
0
 def _Load(self, expression):
   self._Flush()
   parser = config_file.KeyValueParser(kv_sep=":", sep=",",
                                       term=(r"\s+", r"\n"))
   parsed = {}
   for entry in parser.ParseEntries(expression):
     parsed.update(entry)
   self.cfg = rdfvalue.Config(parsed)
   return parsed
示例#2
0
 def _ProcessEntries(self, filename, fd):
     """Extract entries from the xinted config files."""
     parser = config_file.KeyValueParser(kv_sep="{", term="}", sep=None)
     data = fd.read(100000)
     entries = parser.ParseEntries(data)
     for entry in entries:
         for section, cfg in entry.items():
             # The parser returns a list of configs. There will only be one.
             if cfg:
                 cfg = cfg[0].strip()
             else:
                 cfg = ""
             self._ParseSection(section, cfg)
示例#3
0
 def _ParseSection(self, section, cfg):
     parser = config_file.KeyValueParser()
     # Skip includedir, we get this from the artifact.
     if section.startswith("includedir"):
         return
     elif section.startswith("default"):
         for val in parser.ParseEntries(cfg):
             self.default.update(val)
     elif section.startswith("service"):
         svc = section.replace("service", "").strip()
         if not svc:
             return
         self.entries[svc] = {}
         for val in parser.ParseEntries(cfg):
             self.entries[svc].update(val)
示例#4
0
  def testParser(self):
    test_data = r"""
    key1 = a list of \
      fields # but not \n this, or \ this.

    # Nothing here.
    key 2:another entry
    = # Bad line
    'a key'with" no" value field ;; and not this comment.
    """
    expected = [{"key1": ["a", "list", "of", "fields"]},
                {"key 2": ["another", "entry"]},
                {"a keywith no value field": []}]
    cfg = config_file.KeyValueParser(kv_sep=["=", ":"], comments=["#", ";;"])
    results = cfg.ParseEntries(test_data)
    for i, expect in enumerate(expected):
      self.assertDictEqual(expect, results[i])
示例#5
0
 def __init__(self, *args, **kwargs):
     super(SysctlCmdParser, self).__init__(*args, **kwargs)
     self.lexer = config_file.KeyValueParser()