Added ability to get raw configuration parameter values

This commit is contained in:
Maxim Kulkin 2013-10-14 12:45:53 +04:00
parent 4ceec12865
commit cc79d5896c
2 changed files with 12 additions and 1 deletions

View File

@ -77,7 +77,7 @@ class Configuration(object):
return '%s.%s' % (section, param)
def get(self, name, default=None, _state=[]):
def get(self, name, default=None, raw=False, _state=[]):
section, name = self._normalize_name(name)
if section in self._normal and name in self._normal[section]:
@ -90,6 +90,9 @@ class Configuration(object):
if not isinstance(value, str):
return value
if raw:
return value
tmpl = string.Template(value)
return tmpl.safe_substitute(ConfigurationWrapper(self, _state + [name]))

View File

@ -195,3 +195,11 @@ class ConfigurationTests(unittest.TestCase):
self.assertEqual('cba', c.get('c'))
def test_getting_raw_values(self):
c = Configuration()
c.set('a', '$b')
c.set('b', 'x')
self.assertEqual('$b', c.get('a', raw=True))