master len without getattr

This commit is contained in:
gwen 2012-12-04 16:22:39 +01:00
parent 6538231817
commit 0db34bbeba
2 changed files with 34 additions and 25 deletions

View File

@ -161,13 +161,13 @@ class Config(object):
def _get_master_len(self, slave_name): def _get_master_len(self, slave_name):
try: try:
parent_cfg = self._cfgimpl_parent parent_cfg = self
if parent_cfg is None: if parent_cfg is None:
return None return None
master_name = parent_cfg._cfgimpl_descr.get_master_name() master_name = parent_cfg._cfgimpl_descr.get_master_name()
master_value = getattr(parent_cfg, master_name) master_value = parent_cfg._cfgimpl_values[master_name]
return len(master_value) return len(master_value)
except TypeError: except TypeError, err:
# in this case we just don't care about the len # in this case we just don't care about the len
return None return None
@ -176,8 +176,8 @@ class Config(object):
if master_len == None: if master_len == None:
return True return True
if master_len != len(slave_value): if master_len != len(slave_value):
raise ValueError("invalid len for the group {0}" raise ValueError("invalid len for the group of"
"in the option {1} ".format(master_name, slave_name)) " the option {0}".format(slave_name))
def fill_multi(self, name, result, default_multi=None): def fill_multi(self, name, result, default_multi=None):
"""fills a multi option with default and calculated values """fills a multi option with default and calculated values

View File

@ -63,14 +63,18 @@ class Multi(list):
if master != self.opt._name: if master != self.opt._name:
raise IndexError("in a group with a master, you mustn't add " raise IndexError("in a group with a master, you mustn't add "
"a value in a slave's Multi value") "a value in a slave's Multi value")
except TypeError:
return self._setvalue(value, who=settings.owner)
multis = []
for name, multi in self.config: for name, multi in self.config:
multis.append(multi)
for multi in multis:
if master == multi.opt._name: if master == multi.opt._name:
multi._setvalue(value, who=settings.owner) ret = multi._setvalue(value, who=settings.owner)
else: else:
default_value = multi.opt.getdefault_multi() default_value = multi.opt.getdefault_multi()
multi._setvalue(default_value) multi._setvalue(default_value)
except TypeError: return ret
self._setvalue(value, who=settings.owner)
def _setvalue(self, value, key=None, who=None): def _setvalue(self, value, key=None, who=None):
if value != None: if value != None:
@ -96,9 +100,15 @@ class Multi(list):
if master != self.opt._name: if master != self.opt._name:
raise IndexError("in a group with a master, you mustn't remove " raise IndexError("in a group with a master, you mustn't remove "
"a value in a slave's Multi value") "a value in a slave's Multi value")
except TypeError:
return self._pop(key)
multis = []
for name, multi in self.config: for name, multi in self.config:
multis.append(multi)
for multi in multis:
if master == multi.opt._name: if master == multi.opt._name:
multi._pop(key) ret = multi._pop(key)
else: else:
change_who = False change_who = False
# the value owner has to be updated because # the value owner has to be updated because
@ -107,8 +117,7 @@ class Multi(list):
if len(multi.opt.getdefault()) >= len(multi): if len(multi.opt.getdefault()) >= len(multi):
change_who = True change_who = True
multi._pop(key, change_who=change_who) multi._pop(key, change_who=change_who)
except TypeError: return ret
self._pop(key)
def _pop(self, key, change_who=True): def _pop(self, key, change_who=True):
oldvalue = list(self) oldvalue = list(self)