private method _get_multitype()

This commit is contained in:
gwen 2013-02-25 14:27:12 +01:00
parent 7b4f3b5d36
commit 77633c84ce
1 changed files with 17 additions and 12 deletions

View File

@ -38,10 +38,7 @@ class Values(object):
self.slaves = {}
self.context = context
def _get_value(self, opt):
"special case for the multis: they never return None"
if opt not in self.values:
if opt.is_multi():
def _get_multitype(self):
if opt in self.slaves:
# slave
multitype = multitypes.slave
@ -51,6 +48,13 @@ class Values(object):
# FIXME : default value for a multi, we shall work on groups
else:
multitype = multitypes.default
return multitype
def _get_value(self, opt):
"special case for the multis: they never return None"
if opt not in self.values:
if opt.is_multi():
multitype = self._get_multitype()
return Multi(opt.getdefault(), self.context, opt, multitype)
else:
return opt.getdefault()
@ -99,7 +103,8 @@ class Values(object):
_result = [result]
else:
_result = result
return Multi(_result, self.context, opt)
multitype = self._get_multitype()
return Multi(_result, self.context, opt, multitype)
def __getitem__(self, opt):
# options with callbacks
@ -107,7 +112,7 @@ class Values(object):
if opt.has_callback():
if (not opt.is_frozen() or \
not opt.is_forced_on_freeze()) and \
not opt.is_default_owner(self):
not opt.is_default_owner(self.context):
return self._get_value(opt)
try:
result = opt.getcallback_value(
@ -116,7 +121,7 @@ class Values(object):
pass
else:
if opt.is_multi():
value = fill_multi(opt, result)
value = self.fill_multi(opt, result)
else:
# this result **shall not** be a list
if isinstance(result, list):