Use RawConfigParser so we can load python style template syntax from configs
This commit is contained in:
@@ -43,7 +43,7 @@ class Config(object):
|
|||||||
|
|
||||||
sections = set(default.iterkeys())
|
sections = set(default.iterkeys())
|
||||||
if filename:
|
if filename:
|
||||||
cfg = ConfigParser.ConfigParser()
|
cfg = ConfigParser.RawConfigParser()
|
||||||
cfg.optionxform = str
|
cfg.optionxform = str
|
||||||
cfg.read(filename)
|
cfg.read(filename)
|
||||||
sections.update(cfg.sections())
|
sections.update(cfg.sections())
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ domination = True
|
|||||||
somestr = Blabla
|
somestr = Blabla
|
||||||
somenum = 10
|
somenum = 10
|
||||||
testfallbacknum = asdas
|
testfallbacknum = asdas
|
||||||
|
blubber = Things %(doesnotexistsasdefault)s
|
||||||
[Server_10]
|
[Server_10]
|
||||||
value = False
|
value = False
|
||||||
[Server_9]
|
[Server_9]
|
||||||
@@ -64,7 +65,8 @@ value = True
|
|||||||
cfg_default = {'world':(('domination', x2bool, False),
|
cfg_default = {'world':(('domination', x2bool, False),
|
||||||
('somestr', str, "fail"),
|
('somestr', str, "fail"),
|
||||||
('somenum', int, 0),
|
('somenum', int, 0),
|
||||||
('somenumtest', int, 1)),
|
('somenumtest', int, 1),
|
||||||
|
('blubber', str, "empty")),
|
||||||
(lambda x: re.match("Server_\d+",x)):(('value', x2bool, True),),
|
(lambda x: re.match("Server_\d+",x)):(('value', x2bool, True),),
|
||||||
'somethingelse':(('bla', str, "test"),)}
|
'somethingelse':(('bla', str, "test"),)}
|
||||||
|
|
||||||
@@ -118,6 +120,7 @@ value = True
|
|||||||
assert(cfg.world.somestr == "Blabla")
|
assert(cfg.world.somestr == "Blabla")
|
||||||
assert(cfg.world.somenum == 10)
|
assert(cfg.world.somenum == 10)
|
||||||
self.assertRaises(AttributeError, getattr, cfg.world, "testfallbacknum")
|
self.assertRaises(AttributeError, getattr, cfg.world, "testfallbacknum")
|
||||||
|
self.assertEqual(cfg.world.blubber, "Things %(doesnotexistsasdefault)s")
|
||||||
assert(cfg.somethingelse.bla == "test")
|
assert(cfg.somethingelse.bla == "test")
|
||||||
assert(cfg.Server_10.value == False)
|
assert(cfg.Server_10.value == False)
|
||||||
assert(cfg.Server_2.value == True)
|
assert(cfg.Server_2.value == True)
|
||||||
|
|||||||
Reference in New Issue
Block a user