Show More
@@ -69,7 +69,7 b' class config(object):' | |||
|
69 | 69 | self._data[section][item] = value |
|
70 | 70 | self._source[(section, item)] = source |
|
71 | 71 | |
|
72 | def read(self, path, fp=None, sections=None): | |
|
72 | def parse(self, src, data, sections=None, remap=None, include=None): | |
|
73 | 73 | sectionre = re.compile(r'\[([^\[]+)\]') |
|
74 | 74 | itemre = re.compile(r'([^=\s][^=]*?)\s*=\s*(.*\S|)') |
|
75 | 75 | contre = re.compile(r'\s+(\S.*\S)') |
@@ -81,10 +81,7 b' class config(object):' | |||
|
81 | 81 | line = 0 |
|
82 | 82 | cont = 0 |
|
83 | 83 | |
|
84 | if not fp: | |
|
85 | fp = open(path) | |
|
86 | ||
|
87 | for l in fp: | |
|
84 | for l in data.splitlines(1): | |
|
88 | 85 | line += 1 |
|
89 | 86 | if cont: |
|
90 | 87 | m = contre.match(l) |
@@ -92,16 +89,16 b' class config(object):' | |||
|
92 | 89 | if sections and section not in sections: |
|
93 | 90 | continue |
|
94 | 91 | v = self.get(section, item) + "\n" + m.group(1) |
|
95 |
self.set(section, item, v, "%s:%d" % ( |
|
|
92 | self.set(section, item, v, "%s:%d" % (src, line)) | |
|
96 | 93 | continue |
|
97 | 94 | item = None |
|
98 | 95 | m = includere.match(l) |
|
99 | 96 | if m: |
|
100 | 97 | inc = m.group(1) |
|
101 |
base = os.path.dirname( |
|
|
98 | base = os.path.dirname(src) | |
|
102 | 99 | inc = os.path.normpath(os.path.join(base, inc)) |
|
103 |
i |
|
|
104 | self.read(inc, incfp) | |
|
100 | if include: | |
|
101 | include(inc, remap=remap, sections=sections) | |
|
105 | 102 | continue |
|
106 | 103 | if emptyre.match(l): |
|
107 | 104 | continue |
@@ -117,7 +114,7 b' class config(object):' | |||
|
117 | 114 | cont = 1 |
|
118 | 115 | if sections and section not in sections: |
|
119 | 116 | continue |
|
120 |
self.set(section, item, m.group(2), "%s:%d" % ( |
|
|
117 | self.set(section, item, m.group(2), "%s:%d" % (src, line)) | |
|
121 | 118 | continue |
|
122 | 119 | m = unsetre.match(l) |
|
123 | 120 | if m: |
@@ -129,4 +126,9 b' class config(object):' | |||
|
129 | 126 | continue |
|
130 | 127 | |
|
131 | 128 | raise error.ConfigError(_('config error at %s:%d: \'%s\'') |
|
132 |
% ( |
|
|
129 | % (src, line, l.rstrip())) | |
|
130 | ||
|
131 | def read(self, path, fp=None, sections=None, remap=None): | |
|
132 | if not fp: | |
|
133 | fp = open(path) | |
|
134 | self.parse(path, fp.read(), sections, remap, self.read) |
General Comments 0
You need to be logged in to leave comments.
Login now