Use RawConfigParser so we can load python style template syntax from configs

This commit is contained in:
Stefan Hacker
2013-02-24 08:30:49 +01:00
parent 4a42e01f36
commit 74674509cd
2 changed files with 5 additions and 2 deletions

View File

@@ -43,7 +43,7 @@ class Config(object):
sections = set(default.iterkeys())
if filename:
cfg = ConfigParser.ConfigParser()
cfg = ConfigParser.RawConfigParser()
cfg.optionxform = str
cfg.read(filename)
sections.update(cfg.sections())

View File

@@ -54,6 +54,7 @@ domination = True
somestr = Blabla
somenum = 10
testfallbacknum = asdas
blubber = Things %(doesnotexistsasdefault)s
[Server_10]
value = False
[Server_9]
@@ -64,7 +65,8 @@ value = True
cfg_default = {'world':(('domination', x2bool, False),
('somestr', str, "fail"),
('somenum', int, 0),
('somenumtest', int, 1)),
('somenumtest', int, 1),
('blubber', str, "empty")),
(lambda x: re.match("Server_\d+",x)):(('value', x2bool, True),),
'somethingelse':(('bla', str, "test"),)}
@@ -118,6 +120,7 @@ value = True
assert(cfg.world.somestr == "Blabla")
assert(cfg.world.somenum == 10)
self.assertRaises(AttributeError, getattr, cfg.world, "testfallbacknum")
self.assertEqual(cfg.world.blubber, "Things %(doesnotexistsasdefault)s")
assert(cfg.somethingelse.bla == "test")
assert(cfg.Server_10.value == False)
assert(cfg.Server_2.value == True)