setattr instead of _setattr

This commit is contained in:
Emmanuel Garette 2016-01-25 15:57:34 +01:00
parent f4307b9122
commit 8a21d49948
1 changed files with 11 additions and 5 deletions

View File

@ -199,16 +199,22 @@ class SubConfig(object):
# attribute methods # attribute methods
def __setattr__(self, name, value): def __setattr__(self, name, value):
"attribute notation mechanism for the setting of the value of an option" "attribute notation mechanism for the setting of the value of an option"
self._setattr(name, value) self.setattr(name, value)
def _setattr(self, name, value, force_permissive=False, not_raises=False): def _setattr(self, name, value, force_permissive=False, not_raises=False):
"""use setattr instead of _setattr
"""
self.setattr(name, value, force_permissive=force_permissive,
not_raises=not_raises)
def setattr(self, name, value, force_permissive=False, not_raises=False):
if name.startswith('_impl_'): if name.startswith('_impl_'):
object.__setattr__(self, name, value) object.__setattr__(self, name, value)
return return
if '.' in name: # pragma: optional cover if '.' in name: # pragma: optional cover
homeconfig, name = self.cfgimpl_get_home_by_path(name) homeconfig, name = self.cfgimpl_get_home_by_path(name)
return homeconfig._setattr(name, value, force_permissive, return homeconfig.setattr(name, value, force_permissive,
not_raises) not_raises)
context = self._cfgimpl_get_context() context = self._cfgimpl_get_context()
child = self.cfgimpl_get_description().__getattr__(name, child = self.cfgimpl_get_description().__getattr__(name,
context=context) context=context)
@ -218,7 +224,7 @@ class SubConfig(object):
not isinstance(child, DynSymLinkOption): # pragma: no dynoptiondescription cover not isinstance(child, DynSymLinkOption): # pragma: no dynoptiondescription cover
path = context.cfgimpl_get_description().impl_get_path_by_opt( path = context.cfgimpl_get_description().impl_get_path_by_opt(
child._impl_getopt()) child._impl_getopt())
context._setattr(path, value, force_permissive, not_raises) context.setattr(path, value, force_permissive, not_raises)
else: else:
subpath = self._get_subpath(name) subpath = self._get_subpath(name)
self.cfgimpl_get_values().setitem(child, value, subpath, self.cfgimpl_get_values().setitem(child, value, subpath,
@ -756,7 +762,7 @@ class GroupConfig(_CommonConfig):
elif isinstance(child, GroupConfig): elif isinstance(child, GroupConfig):
child.set_value(path, value) child.set_value(path, value)
else: else:
child._setattr(path, value, not_raises=True) child.setattr(path, value, not_raises=True)
def find_firsts(self, byname=None, bypath=undefined, byoption=undefined, def find_firsts(self, byname=None, bypath=undefined, byoption=undefined,
byvalue=undefined, raise_if_not_found=True, _sub=False, byvalue=undefined, raise_if_not_found=True, _sub=False,