From 74674509cdeca1293fe75f9303612243114c342a Mon Sep 17 00:00:00 2001 From: Stefan Hacker Date: Sun, 24 Feb 2013 08:30:49 +0100 Subject: [PATCH] Use RawConfigParser so we can load python style template syntax from configs --- config.py | 2 +- config_test.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 126316d..4913a57 100644 --- a/config.py +++ b/config.py @@ -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()) diff --git a/config_test.py b/config_test.py index 1a3d7b3..2c74613 100644 --- a/config_test.py +++ b/config_test.py @@ -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)