Esempio n. 1
0
 def testWhitespaceDoesntNukeNewline(self):
     test_data = "trailing spaces     \nno trailing spaces\n"
     expected = [["trailing", "spaces"], ["no", "trailing", "spaces"]]
     results = config_file.FieldParser().ParseEntries(test_data)
     for i, expect in enumerate(expected):
         self.assertItemsEqual(expect, results[i])
     expected = [["trailing", "spaces", "no", "trailing", "spaces"]]
     results = config_file.FieldParser(sep=r"\s+").ParseEntries(test_data)
     for i, expect in enumerate(expected):
         self.assertItemsEqual(expect, results[i])
Esempio n. 2
0
  def _ParseInsserv(self, data):
    """/etc/insserv.conf* entries define system facilities.

    Full format details are in man 8 insserv, but the basic structure is:
      $variable          facility1 facility2
      $second_variable   facility3 $variable

    Any init script that specifies Required-Start: $second_variable needs to be
    expanded to facility1 facility2 facility3.

    Args:
      data: A string of insserv definitions.
    """
    p = config_file.FieldParser()
    entries = p.ParseEntries(data)
    raw = {e[0]: e[1:] for e in entries}
    # Now expand out the facilities to services.
    facilities = {}
    for k, v in iteritems(raw):
      # Remove interactive tags.
      k = k.replace("<", "").replace(">", "")
      facilities[k] = v
    for k, vals in iteritems(facilities):
      self.insserv[k] = []
      for v in vals:
        self.insserv[k].extend(self._InsservExpander(facilities, v))
Esempio n. 3
0
 def testNoFinalTerminator(self):
     test_data = "you forgot a newline"
     expected = [["you", "forgot", "a", "newline"]]
     cfg = config_file.FieldParser()
     results = cfg.ParseEntries(test_data)
     for i, expect in enumerate(expected):
         self.assertItemsEqual(expect, results[i])
Esempio n. 4
0
 def testParser(self):
   test_data = r"""
   each of these words:should;be \
       fields # but not these ones \n, or \ these.
   this  should be     another entry "with this quoted text as one field"
   'an entry'with" only two" fields ;; and not this comment.
   """
   expected = [["each", "of", "these", "words", "should", "be", "fields"], [
       "this", "should", "be", "another", "entry",
       "with this quoted text as one field"
   ], ["an entrywith only two", "fields"]]
   cfg = config_file.FieldParser(
       sep=["[ \t\f\v]+", ":", ";"], comments=["#", ";;"])
   results = cfg.ParseEntries(test_data)
   for i, expect in enumerate(expected):
     self.assertItemsEqual(expect, results[i])
Esempio n. 5
0
 def __init__(self):
     super(PathParser, self).__init__()
     # Terminate entries on ";" to capture multiple values on one line.
     self.parser = config_file.FieldParser(term=r"[\r\n;]")
Esempio n. 6
0
 def __init__(self, *args, **kwargs):
   super().__init__(*args, **kwargs)
   # Terminate entries on ";" to capture multiple values on one line.
   self.parser = config_file.FieldParser(term=r"[\r\n;]")