finally a getvalue without a getattr

This commit is contained in:
gwen 2013-02-27 11:09:13 +01:00
parent c40d33fec3
commit df3753c36b
2 changed files with 26 additions and 0 deletions

View File

@ -58,6 +58,13 @@ def test_iter_subconfig():
zip(conf.gc, [("name", "ref"), ("dummy", False)]):
assert name == gname
assert value == gvalue
def test_cfgimpl_get_value():
"same as getattr."
descr = make_description()
conf = Config(descr)
assert conf.cfgimpl_get_value(('gc', 'dummy')) == False
#____________________________________________________________
def test_getpaths():
descr = make_description()

View File

@ -79,6 +79,25 @@ class Config(object):
raise ConfigError("setting not allowed")
self._cfgimpl_context._cfgimpl_settings = settings
def cfgimpl_get_description(self):
return self._cfgimpl_descr
def cfgimpl_get_value(self, path):
"""same as multiple getattrs
:param path: list or tuple of path
example : ``path = (sub_conf, opt)`` makes a getattr of sub_conf, then
a getattr of opt, and then returns the opt's value.
:returns: subconf or option's value
"""
subpaths = list(path)
subconf_or_opt = self
for subpath in subpaths:
subconf_or_opt = getattr(subconf_or_opt, subpath)
return subconf_or_opt
def _validate_duplicates(self, children):
"""duplicates Option names in the schema
:type children: list of `Option` or `OptionDescription`