This commit is contained in:
2017-12-30 18:31:56 +01:00
parent c086f6dc0f
commit 16a160340c
9 changed files with 745 additions and 23 deletions

View File

@ -297,11 +297,10 @@ class TiramisuOptionProperty(CommonTiramisuOption):
@count
def pop(self, prop):
props = self.get()
props.remove(prop)
self.settings.setproperties(path=self.path,
properties=frozenset(props),
config_bag=self.config_bag)
self.get_option()
self.settings.popproperty(self.path,
prop,
self.config_bag)
@count
def reset(self):

View File

@ -408,13 +408,13 @@ class SubConfig(object):
'').format(subpath))
length = self.cfgimpl_get_length()
if index is not None and index >= length:
raise IndexError(_('index ({}) is higher than the master length ({}) '
'for "{}"').format(index,
raise IndexError(_('index "{}" is higher than the master length "{}" '
'for option "{}"').format(index,
length,
option.impl_get_display_name()))
slave_len = self.cfgimpl_get_values()._p_.get_max_length(subpath)
if slave_len > length:
raise SlaveError(_('slave option "{}" has higher length ({}) than the master length ({})'
raise SlaveError(_('slave option "{}" has higher length "{}" than the master length "{}"'
'').format(option.impl_get_display_name(),
slave_len,
length,

View File

@ -353,7 +353,7 @@ class Base(object):
return not isinstance(getattr(self, '_informations', dict()), dict)
def impl_getproperties(self):
return getattr(self, '_properties', STATIC_TUPLE)
return getattr(self, '_properties', frozenset())
def _set_readonly(self):
if not self.impl_is_readonly():

View File

@ -71,7 +71,7 @@ class MasterSlaves(OptionDescription):
if idx != 0:
properties = list(child._properties)
properties.remove('empty')
child._properties = tuple(properties)
child._properties = frozenset(properties)
slaves.append(child)
child._add_dependency(self)
child._master_slaves = weakref.ref(self)

View File

@ -247,8 +247,7 @@ class Option(OnlyOption):
def do_validation(_value,
_index):
if isinstance(_value, list): # pragma: no cover
raise ValueError(_('invalid value "{}" for "{}" '
'which must not be a list').format(_value,
raise ValueError(_('which must not be a list').format(_value,
self.impl_get_display_name()))
#FIXME a revoir ...
if _value is not None:
@ -278,6 +277,8 @@ class Option(OnlyOption):
do_validation(val, None)
elif force_index is not None:
if self.impl_is_submulti():
if not isinstance(value, list):
raise ValueError(_('which must be a list'))
_is_not_unique(value)
for idx, val in enumerate(value):
do_validation(val,
@ -290,23 +291,17 @@ class Option(OnlyOption):
else:
lst = multi
if value in lst:
raise ValueError(_('invalid value "{}", this value is already'
' in "{}"').format(value,
self.impl_get_display_name()))
raise ValueError(_('this value is not uniq'))
do_validation(val,
force_index)
elif not isinstance(value, list):
raise ValueError(_('invalid value "{0}" for "{1}" which '
'must be a list').format(value,
self.impl_getname()))
raise ValueError(_('which must be a list'))
elif self.impl_is_submulti():
for idx, lval in enumerate(value):
_is_not_unique(lval)
if not isinstance(lval, list):
raise ValueError(_('invalid value "{0}" for "{1}" '
'which must be a list of list'
'').format(lval,
self.impl_getname()))
raise ValueError(_('which "{}" must be a list of list'
'').format(lval))
for val in lval:
do_validation(val,
idx)

View File

@ -612,6 +612,16 @@ class Settings(object):
config_bag,
force=True)
def popproperty(self,
path,
property_,
config_bag):
props = config_bag.option.impl_getproperties()
self.setproperties(path,
props - {property_},
config_bag,
force=True)
def set_context_permissive(self, permissive):
self.setpermissive(None, None, permissive)

View File

@ -248,7 +248,7 @@ class Values(object):
elif isinstance(value, list):
# value is a list, but no index specified
_reset_cache()
if opt.impl_is_submulti() and (value == [] or not isinstance(value[0], list)):
if opt.impl_is_submulti() and (value != [] and not isinstance(value[0], list)):
# if submulti, return a list of value
return [value]
# otherwise just return the value