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