diff --git a/trac/config.py b/trac/config.py
|
a
|
b
|
|
| 141 | 141 | def sections(self): |
| 142 | 142 | """Return a list of section names.""" |
| 143 | 143 | sections = set(self.parser.sections()) |
| 144 | | parent = self.parent |
| 145 | | while parent: |
| 146 | | sections |= set(parent.parser.sections()) |
| 147 | | parent = parent.parent |
| | 144 | if self.parent: |
| | 145 | sections.update(self.parent.sections()) |
| | 146 | else: |
| | 147 | sections.update(self.defaults().keys()) |
| 148 | 148 | return sorted(sections) |
| 149 | 149 | |
| 150 | 150 | def has_option(self, section, option): |
| … |
… |
|
| 153 | 153 | |
| 154 | 154 | (since Trac 0.11) |
| 155 | 155 | """ |
| 156 | | # Check project trac.ini |
| 157 | | for file_option, val in self.options(section): |
| 158 | | if file_option == option: |
| | 156 | if self.parser.has_section(section): |
| | 157 | if option in self.parser.options(section): |
| 159 | 158 | return True |
| 160 | | # Check parent trac.ini |
| 161 | 159 | if self.parent: |
| 162 | | for parent_option, val in self.parent.options(section): |
| 163 | | if parent_option == option: |
| 164 | | return True |
| 165 | | # Check the registry |
| 166 | | if (section, option) in Option.registry: |
| 167 | | return True |
| 168 | | # Not found |
| 169 | | return False |
| | 160 | return self.parent.has_option(section, option) |
| | 161 | else: |
| | 162 | return (section, option) in Option.registry |
| 170 | 163 | |
| 171 | 164 | def save(self): |
| 172 | 165 | """Write the configuration options to the primary file.""" |
| … |
… |
|
| 254 | 247 | return True |
| 255 | 248 | if self.config.parent: |
| 256 | 249 | return name in self.config.parent[self.name] |
| 257 | | return False |
| | 250 | return Option.registry.has_key((self.name, name)) |
| 258 | 251 | |
| 259 | 252 | def __iter__(self): |
| 260 | 253 | options = set() |
| … |
… |
|
| 266 | 259 | for option in self.config.parent[self.name]: |
| 267 | 260 | if option.lower() not in options: |
| 268 | 261 | yield option |
| | 262 | else: |
| | 263 | for section, option in Option.registry.keys(): |
| | 264 | if section == self.name and option.lower() not in options: |
| | 265 | yield option |
| 269 | 266 | |
| 270 | 267 | def __repr__(self): |
| 271 | 268 | return '<Section [%s]>' % (self.name) |
diff --git a/trac/tests/config.py b/trac/tests/config.py
|
a
|
b
|
|
| 192 | 192 | self._write(['[a]', 'option = x', '[b]', 'option = y']) |
| 193 | 193 | config = self._read() |
| 194 | 194 | self.assertEquals(['a', 'b'], config.sections()) |
| | 195 | |
| | 196 | class Foo(object): |
| | 197 | option_c = Option('c', 'option', 'value') |
| | 198 | |
| | 199 | self.assertEquals(['a', 'b', 'c'], config.sections()) |
| 195 | 200 | |
| 196 | 201 | def test_options(self): |
| 197 | 202 | self._write(['[a]', 'option = x', '[b]', 'option = y']) |
| … |
… |
|
| 199 | 204 | self.assertEquals(('option', 'x'), iter(config.options('a')).next()) |
| 200 | 205 | self.assertEquals(('option', 'y'), iter(config.options('b')).next()) |
| 201 | 206 | self.assertRaises(StopIteration, iter(config.options('c')).next) |
| | 207 | |
| | 208 | class Foo(object): |
| | 209 | option_a = Option('a', 'b', 'c') |
| | 210 | |
| | 211 | self.assertEquals([('option', 'x'), ('b', 'c')], |
| | 212 | list(config.options('a'))) |
| 202 | 213 | |
| 203 | 214 | def test_has_option(self): |
| 204 | 215 | config = self._read() |
| … |
… |
|
| 207 | 218 | config = self._read() |
| 208 | 219 | self.assertEquals(True, config.has_option('a', 'option')) |
| 209 | 220 | |
| | 221 | class Foo(object): |
| | 222 | option_a = Option('a', 'option2', 'x2') |
| | 223 | |
| | 224 | self.assertEquals(True, config.has_option('a', 'option2')) |
| | 225 | |
| 210 | 226 | def test_reparse(self): |
| 211 | 227 | self._write(['[a]', 'option = x']) |
| 212 | 228 | config = self._read() |