Merge branch 'master' into orm

Conflicts:
	tiramisu/config.py
	tiramisu/option.py
This commit is contained in:
2014-02-04 21:48:20 +01:00
8 changed files with 92 additions and 32 deletions

View File

@ -434,12 +434,9 @@ class SubConfig(object):
def _make_sub_dict(self, opt, path, pathsvalues, _currpath, flatten):
if isinstance(opt, OptionDescription):
try:
pathsvalues += getattr(self, path).make_dict(flatten,
_currpath +
path.split('.'))
except PropertiesOptionError:
pass # this just a hidden or disabled option
pathsvalues += getattr(self, path).make_dict(flatten,
_currpath +
path.split('.'))
else:
try:
value = self._getattr(opt.impl_getname())

View File

@ -715,7 +715,7 @@ class ChoiceOption(Option):
return self._choice_open_values
def _validate(self, value):
if not self._choice_open_values and not value in self._choice_values:
if not self.impl_is_openvalues() and not value in self.impl_get_values():
raise ValueError(_('value {0} is not permitted, '
'only {1} is allowed'
'').format(value, self._choice_values))
@ -832,9 +832,13 @@ class IPOption(Option):
def _validate(self, value):
# sometimes an ip term starts with a zero
# but this does not fit in some case, for example bind does not like it
for val in value.split('.'):
if val.startswith("0") and len(val) > 1:
raise ValueError(_('invalid IP'))
try:
for val in value.split('.'):
if val.startswith("0") and len(val) > 1:
raise ValueError(_('invalid IP'))
except AttributeError:
#if integer for example
raise ValueError(_('invalid IP'))
# 'standard' validation
try:
IP('{0}/32'.format(value))
@ -905,18 +909,23 @@ class PortOption(Option):
if self._extra['_allow_range'] and ":" in str(value):
value = str(value).split(':')
if len(value) != 2:
raise ValueError('invalid part, range must have two values '
'only')
raise ValueError(_('invalid part, range must have two values '
'only'))
if not value[0] < value[1]:
raise ValueError('invalid port, first port in range must be'
' smaller than the second one')
raise ValueError(_('invalid port, first port in range must be'
' smaller than the second one'))
else:
value = [value]
for val in value:
if not self._extra['_min_value'] <= int(val) <= self._extra['_max_value']:
raise ValueError('invalid port, must be an between {0} and {1}'
''.format(self._extra['_min_value'], self._extra['_max_value']))
try:
if not self._extra['_min_value'] <= int(val) <= self._extra['_max_value']:
raise ValueError('invalid port, must be an between {0} '
'and {1}'.format(
self._extra['_min_value'],
self._extra['_max_value']))
except ValueError:
raise ValueError(_('invalid port'))
class NetworkOption(Option):

View File

@ -372,7 +372,7 @@ class Settings(object):
def _getproperties(self, opt=None, path=None, is_apply_req=True):
if opt is None:
props = self._p_.getproperties(path, default_properties)
props = copy(self._p_.getproperties(path, default_properties))
else:
if path is None:
raise ValueError(_('if opt is not None, path should not be'
@ -383,8 +383,8 @@ class Settings(object):
ntime = int(time())
is_cached, props = self._p_.getcache(path, ntime)
if is_cached:
return props
props = self._p_.getproperties(path, opt._properties)
return copy(props)
props = copy(self._p_.getproperties(path, opt._properties))
if is_apply_req:
props |= self.apply_requires(opt, path)
if 'cache' in self:
@ -447,8 +447,8 @@ class Settings(object):
(typically with the `frozen` property)
"""
# opt properties
properties = copy(self._getproperties(opt_or_descr, path))
self_properties = copy(self._getproperties())
properties = self._getproperties(opt_or_descr, path)
self_properties = self._getproperties()
# remove opt permissive
# permissive affect option's permission with or without permissive
# global property

View File

@ -66,6 +66,8 @@ class Values(object):
meta = self._getcontext().cfgimpl_get_meta()
if meta is not None:
value = meta.cfgimpl_get_values()[opt]
if isinstance(value, Multi):
value = list(value)
else:
value = opt.impl_getdefault()
if opt.impl_is_multi():