Parse a list of lines and create an internal property dictionary
(self, lines)
| 53 | return s |
| 54 | |
| 55 | def __parse(self, lines): |
| 56 | """ Parse a list of lines and create |
| 57 | an internal property dictionary """ |
| 58 | |
| 59 | # Every line in the file must consist of either a comment |
| 60 | # or a key-value pair. A key-value pair is a line consisting |
| 61 | # of a key which is a combination of non-white space characters |
| 62 | # The separator character between key-value pairs is a '=', |
| 63 | # ':' or a whitespace character not including the newline. |
| 64 | # If the '=' or ':' characters are found, in the line, even |
| 65 | # keys containing whitespace chars are allowed. |
| 66 | |
| 67 | # A line with only a key according to the rules above is also |
| 68 | # fine. In such case, the value is considered as the empty string. |
| 69 | # In order to include characters '=' or ':' in a key or value, |
| 70 | # they have to be properly escaped using the backslash character. |
| 71 | |
| 72 | # Some examples of valid key-value pairs: |
| 73 | # |
| 74 | # key value |
| 75 | # key=value |
| 76 | # key:value |
| 77 | # key value1,value2,value3 |
| 78 | # key value1,value2,value3 \ |
| 79 | # value4, value5 |
| 80 | # key |
| 81 | # This key= this value |
| 82 | # key = value1 value2 value3 |
| 83 | |
| 84 | # Any line that starts with a '#' is considerered a comment |
| 85 | # and skipped. Also any trailing or preceding whitespaces |
| 86 | # are removed from the key/value. |
| 87 | |
| 88 | # This is a line parser. It parses the |
| 89 | # contents like by line. |
| 90 | |
| 91 | lineno=0 |
| 92 | i = iter(lines) |
| 93 | |
| 94 | for line in i: |
| 95 | lineno += 1 |
| 96 | line = line.strip() |
| 97 | # Skip null lines |
| 98 | if not line: continue |
| 99 | # Skip lines which are comments |
| 100 | if line[0] == '#': continue |
| 101 | # Some flags |
| 102 | escaped=False |
| 103 | # Position of first separation char |
| 104 | sepidx = -1 |
| 105 | # A flag for performing wspace re check |
| 106 | flag = 0 |
| 107 | # Check for valid space separation |
| 108 | # First obtain the max index to which we |
| 109 | # can search. |
| 110 | m = self.othercharre.search(line) |
| 111 | if m: |
| 112 | first, last = m.span() |