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

View File

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