Ticket #8290: bug8290.patch
| File bug8290.patch, 2.9 KB (added by Joachim Hoessler <hoessler@…>, 3 years ago) |
|---|
-
trac/tests/config.py
244 244 finally: 245 245 os.remove(sitename) 246 246 247 def test_read_option_from_descriptor(self): 248 config = self._read() 249 Option('a', 'option', 'x') 250 self.assertEqual('x', config.get('a', 'option')) 247 251 252 def test_iterate_option_from_descriptor(self): 253 config = self._read() 254 Option('a', 'option', 'x') 255 self.assertTrue('option' in config['a']) 256 options = config['a'].options() 257 self.assertEqual(('option', 'x'), options.next()) 258 248 259 def suite(): 249 260 return unittest.makeSuite(ConfigurationTestCase, 'test') 250 261 -
trac/config.py
253 253 if self.config.parser.has_option(self.name, name): 254 254 return True 255 255 if self.config.parent: 256 return name in self.config.parent[self.name] 257 return False 256 if name in self.config.parent[self.name]: 257 return True 258 return name in [op for sec, op in Option.registry 259 if sec == self.name] 258 260 259 261 def __iter__(self): 260 262 options = set() … … 265 267 if self.config.parent: 266 268 for option in self.config.parent[self.name]: 267 269 if option.lower() not in options: 270 options.add(option.lower()) 268 271 yield option 272 for option in [op for sec, op in Option.registry if sec == self.name]: 273 if option.lower() not in options: 274 options.add(option.lower()) 275 yield option 269 276 270 277 def __repr__(self): 271 278 return '<Section [%s]>' % (self.name) 272 279 280 def _get(self, name): 281 """Iterates through .ini inheritance hierarchy and 282 returns value of specified option if found. Otherwise 283 returns None. 284 """ 285 if self.config.parser.has_option(self.name, name): 286 return self.config.parser.get(self.name, name) 287 elif self.config.parent: 288 return self.config.parent[self.name]._get(name) 289 return None 290 273 291 def get(self, name, default=''): 274 292 """Return the value of the specified option. 275 293 276 294 Valid default input is a string. Returns a string. 277 295 """ 278 if self.config.parser.has_option(self.name, name): 279 value = self.config.parser.get(self.name, name) 280 elif self.config.parent: 281 value = self.config.parent[self.name].get(name, default) 282 else: 296 value = self._get(name) 297 298 if not value: 283 299 option = Option.registry.get((self.name, name)) 284 300 if option: 285 301 value = option.default or default
