at_index to check owners

This commit is contained in:
gwen 2012-11-08 09:57:29 +01:00
parent 407c74008c
commit 1de236d2a8

View file

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