at_index to check owners

This commit is contained in:
gwen 2012-11-08 09:57:29 +01:00
parent 407c74008c
commit 1de236d2a8
1 changed files with 8 additions and 4 deletions

View File

@ -220,17 +220,21 @@ class Option(HiddenBaseType, DisabledBaseType):
"config *must* be only the **parent** config (not the toplevel config)"
return config._cfgimpl_value_owners[self._name]
def is_default_owner(self, config, all_default=True):
def is_default_owner(self, config, all_default=True, at_index=None):
"""
:param config: *must* be only the **parent** config
(not the toplevel config)
:param all_default: only for multi options, if True and the owner list
has something else than "default" returns False, if False and the owner
list has at least one "default" owner, returns True
:param at_index: only for multi options, checks owner at specified
index
:return: boolean
"""
if self.is_multi():
owners = self.getowner(config)
if at_index:
return owners[at_index] == 'default'
for owner in owners:
if all_default and owner != 'default':
return False
@ -241,9 +245,9 @@ class Option(HiddenBaseType, DisabledBaseType):
else:
return False
else:
if self.getowner(config) == 'default':
return True
return False
if at_index:
raise ValueError('index specified for a not multi option')
return self.getowner(config) == 'default'
def setoption(self, config, value, who):
"""changes the option's value with the value_owner's who