MultiTypeError => ValueError
This commit is contained in:
parent
80438b1495
commit
eea96cc3d1
@ -23,6 +23,8 @@
|
||||
#ValueError if function's parameter not correct
|
||||
# or if not logical
|
||||
# or if validation falied
|
||||
# or multi must be a list
|
||||
# or error with multi length
|
||||
#TypeError if parameter has no good type
|
||||
#AttributeError if no option or optiondescription in optiondescription (also when specified a path)
|
||||
|
||||
@ -53,9 +55,3 @@ class PropertiesOptionError(AttributeError):
|
||||
class RequirementRecursionError(StandardError):
|
||||
"recursive error"
|
||||
pass
|
||||
|
||||
|
||||
class MultiTypeError(Exception):
|
||||
"""multi must be a list
|
||||
or error with multi length"""
|
||||
pass
|
||||
|
@ -17,7 +17,7 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# ____________________________________________________________
|
||||
from tiramisu.error import MultiTypeError, ConfigError
|
||||
from tiramisu.error import ConfigError
|
||||
from tiramisu.setting import owners, multitypes
|
||||
from tiramisu.autolib import carry_out_calculation
|
||||
from tiramisu.i18n import _
|
||||
@ -49,9 +49,9 @@ class Values(object):
|
||||
mastervalue = getattr(self.context, masterpath)
|
||||
masterlen = len(mastervalue)
|
||||
if len(value) > masterlen:
|
||||
raise MultiTypeError(_("invalid len for the slave: {0}"
|
||||
" which has {1} as master").format(
|
||||
opt._name, masterpath))
|
||||
raise ValueError(_("invalid len for the slave: {0}"
|
||||
" which has {1} as master").format(
|
||||
opt._name, masterpath))
|
||||
if len(value) < masterlen:
|
||||
for num in range(0, masterlen - len(value)):
|
||||
value.append(opt.getdefault_multi(), force=True)
|
||||
@ -163,26 +163,26 @@ class Values(object):
|
||||
for slave in opt.master_slaves:
|
||||
value_slave = self._get_value(slave)
|
||||
if len(value_slave) > masterlen:
|
||||
raise MultiTypeError(_("invalid len for the slave: {0}"
|
||||
" which has {1} as master").format(
|
||||
slave._name, opt._name))
|
||||
raise ValueError(_("invalid len for the slave: {0}"
|
||||
" which has {1} as master").format(
|
||||
slave._name, opt._name))
|
||||
elif len(value_slave) < masterlen:
|
||||
for num in range(0, masterlen - len(value_slave)):
|
||||
value_slave.append(slave.getdefault_multi(), force=True)
|
||||
|
||||
elif opt.get_multitype() == multitypes.slave:
|
||||
if len(self._get_value(opt.master_slaves)) != len(value):
|
||||
raise MultiTypeError(_("invalid len for the slave: {0}"
|
||||
" which has {1} as master").format(
|
||||
opt._name, opt.master_slaves._name))
|
||||
raise ValueError(_("invalid len for the slave: {0}"
|
||||
" which has {1} as master").format(
|
||||
opt._name, opt.master_slaves._name))
|
||||
if not isinstance(value, Multi):
|
||||
value = Multi(value, self.context, opt)
|
||||
self.setitem(opt, value)
|
||||
|
||||
def setitem(self, opt, value):
|
||||
if type(value) == list:
|
||||
raise MultiTypeError(_("the type of the value {0} which is multi shall "
|
||||
"be Multi and not list").format(str(value)))
|
||||
raise ValueError(_("the type of the value {0} which is multi shall "
|
||||
"be Multi and not list").format(str(value)))
|
||||
self.values[opt] = (self.context.cfgimpl_get_settings().getowner(), value)
|
||||
|
||||
def __contains__(self, opt):
|
||||
@ -236,8 +236,8 @@ class Multi(list):
|
||||
"""
|
||||
if not force:
|
||||
if self.opt.get_multitype() == multitypes.slave:
|
||||
raise MultiTypeError(_("cannot append a value on a multi option {0}"
|
||||
" which is a slave").format(self.opt._name))
|
||||
raise ValueError(_("cannot append a value on a multi option {0}"
|
||||
" which is a slave").format(self.opt._name))
|
||||
elif self.opt.get_multitype() == multitypes.master:
|
||||
for slave in self.opt.get_master_slaves():
|
||||
self.context.cfgimpl_get_values()[slave].append(
|
||||
@ -264,8 +264,8 @@ class Multi(list):
|
||||
"""
|
||||
if not force:
|
||||
if self.opt.multitype == multitypes.slave:
|
||||
raise MultiTypeError(_("cannot append a value on a multi option {0}"
|
||||
" which is a slave").format(self.opt._name))
|
||||
raise ValueError(_("cannot append a value on a multi option {0}"
|
||||
" which is a slave").format(self.opt._name))
|
||||
elif self.opt.multitype == multitypes.master:
|
||||
for slave in self.opt.get_master_slaves():
|
||||
self.context.cfgimpl_get_values()[slave].pop(key, force=True)
|
||||
|
Loading…
Reference in New Issue
Block a user