72 |
72 |
73 def parse(self, src, data, sections=None, remap=None, include=None): |
73 def parse(self, src, data, sections=None, remap=None, include=None): |
74 sectionre = re.compile(r'\[([^\[]+)\]') |
74 sectionre = re.compile(r'\[([^\[]+)\]') |
75 itemre = re.compile(r'([^=\s][^=]*?)\s*=\s*(.*\S|)') |
75 itemre = re.compile(r'([^=\s][^=]*?)\s*=\s*(.*\S|)') |
76 contre = re.compile(r'\s+(\S|\S.*\S)\s*$') |
76 contre = re.compile(r'\s+(\S|\S.*\S)\s*$') |
77 emptyre = re.compile(r'(;|#|\s*$)') |
77 emptyre = re.compile(r'\s*(;|#|\s*$)') |
|
78 commentre = re.compile(r'(;|#)') |
78 unsetre = re.compile(r'%unset\s+(\S+)') |
79 unsetre = re.compile(r'%unset\s+(\S+)') |
79 includere = re.compile(r'%include\s+(\S|\S.*\S)\s*$') |
80 includere = re.compile(r'%include\s+(\S|\S.*\S)\s*$') |
80 section = "" |
81 section = "" |
81 item = None |
82 item = None |
82 line = 0 |
83 line = 0 |
83 cont = False |
84 cont = False |
84 |
85 |
85 for l in data.splitlines(True): |
86 for l in data.splitlines(True): |
86 line += 1 |
87 line += 1 |
87 if cont: |
88 if cont: |
|
89 if commentre.match(l): |
|
90 continue |
88 m = contre.match(l) |
91 m = contre.match(l) |
89 if m: |
92 if m: |
90 if sections and section not in sections: |
93 if sections and section not in sections: |
91 continue |
94 continue |
92 v = self.get(section, item) + "\n" + m.group(1) |
95 v = self.get(section, item) + "\n" + m.group(1) |