|
|
|
@ -68,7 +68,8 @@ class ChoiceOption(Option):
|
|
|
|
|
properties=properties,
|
|
|
|
|
warnings_only=warnings_only)
|
|
|
|
|
|
|
|
|
|
def impl_get_values(self, context, current_opt=undefined):
|
|
|
|
|
def impl_get_values(self, context, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
if current_opt is undefined:
|
|
|
|
|
current_opt = self
|
|
|
|
|
#FIXME cache? but in context...
|
|
|
|
@ -82,14 +83,21 @@ class ChoiceOption(Option):
|
|
|
|
|
values_params = {}
|
|
|
|
|
values = carry_out_calculation(current_opt, context=context,
|
|
|
|
|
callback=values,
|
|
|
|
|
callback_params=values_params)
|
|
|
|
|
callback_params=values_params,
|
|
|
|
|
returns_raise=returns_raise)
|
|
|
|
|
if isinstance(values, Exception):
|
|
|
|
|
return values
|
|
|
|
|
if values is not undefined and not isinstance(values, list): # pragma: optional cover
|
|
|
|
|
raise ConfigError(_('calculated values for {0} is not a list'
|
|
|
|
|
'').format(self.impl_getname()))
|
|
|
|
|
return values
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
values = self.impl_get_values(context, current_opt=current_opt)
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
values = self.impl_get_values(context, current_opt=current_opt,
|
|
|
|
|
returns_raise=returns_raise)
|
|
|
|
|
if isinstance(values, Exception):
|
|
|
|
|
return values
|
|
|
|
|
if values is not undefined and not value in values: # pragma: optional cover
|
|
|
|
|
return ValueError(_('value {0} is not permitted, '
|
|
|
|
|
'only {1} is allowed'
|
|
|
|
@ -101,7 +109,8 @@ class BoolOption(Option):
|
|
|
|
|
"represents a choice between ``True`` and ``False``"
|
|
|
|
|
__slots__ = tuple()
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
if not isinstance(value, bool):
|
|
|
|
|
return ValueError(_('invalid boolean')) # pragma: optional cover
|
|
|
|
|
|
|
|
|
@ -110,7 +119,8 @@ class IntOption(Option):
|
|
|
|
|
"represents a choice of an integer"
|
|
|
|
|
__slots__ = tuple()
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
if not isinstance(value, int):
|
|
|
|
|
return ValueError(_('invalid integer')) # pragma: optional cover
|
|
|
|
|
|
|
|
|
@ -119,7 +129,8 @@ class FloatOption(Option):
|
|
|
|
|
"represents a choice of a floating point number"
|
|
|
|
|
__slots__ = tuple()
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
if not isinstance(value, float):
|
|
|
|
|
return ValueError(_('invalid float')) # pragma: optional cover
|
|
|
|
|
|
|
|
|
@ -128,7 +139,8 @@ class StrOption(Option):
|
|
|
|
|
"represents the choice of a string"
|
|
|
|
|
__slots__ = tuple()
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
if not isinstance(value, str):
|
|
|
|
|
return ValueError(_('invalid string')) # pragma: optional cover
|
|
|
|
|
|
|
|
|
@ -144,7 +156,8 @@ else:
|
|
|
|
|
__slots__ = tuple()
|
|
|
|
|
_empty = u''
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
if not isinstance(value, unicode):
|
|
|
|
|
return ValueError(_('invalid unicode')) # pragma: optional cover
|
|
|
|
|
|
|
|
|
@ -172,7 +185,8 @@ class IPOption(Option):
|
|
|
|
|
warnings_only=warnings_only,
|
|
|
|
|
extra=extra)
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
# sometimes an ip term starts with a zero
|
|
|
|
|
# but this does not fit in some case, for example bind does not like it
|
|
|
|
|
err = self._impl_valid_unicode(value)
|
|
|
|
@ -276,7 +290,8 @@ class PortOption(Option):
|
|
|
|
|
warnings_only=warnings_only,
|
|
|
|
|
extra=extra)
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
if isinstance(value, int):
|
|
|
|
|
if sys.version_info[0] >= 3: # pragma: optional cover
|
|
|
|
|
value = str(value)
|
|
|
|
@ -310,7 +325,8 @@ class NetworkOption(Option):
|
|
|
|
|
"represents the choice of a network"
|
|
|
|
|
__slots__ = tuple()
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
err = self._impl_valid_unicode(value)
|
|
|
|
|
if err:
|
|
|
|
|
return err
|
|
|
|
@ -333,7 +349,8 @@ class NetmaskOption(Option):
|
|
|
|
|
"represents the choice of a netmask"
|
|
|
|
|
__slots__ = tuple()
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
err = self._impl_valid_unicode(value)
|
|
|
|
|
if err:
|
|
|
|
|
return err
|
|
|
|
@ -383,7 +400,8 @@ class NetmaskOption(Option):
|
|
|
|
|
class BroadcastOption(Option):
|
|
|
|
|
__slots__ = tuple()
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
err = self._impl_valid_unicode(value)
|
|
|
|
|
if err:
|
|
|
|
|
return err
|
|
|
|
@ -443,7 +461,8 @@ class DomainnameOption(Option):
|
|
|
|
|
warnings_only=warnings_only,
|
|
|
|
|
extra=extra)
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
err = self._impl_valid_unicode(value)
|
|
|
|
|
if err:
|
|
|
|
|
return err
|
|
|
|
@ -504,7 +523,8 @@ class EmailOption(DomainnameOption):
|
|
|
|
|
__slots__ = tuple()
|
|
|
|
|
username_re = re.compile(r"^[\w!#$%&'*+\-/=?^`{|}~.]+$")
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
err = self._impl_valid_unicode(value)
|
|
|
|
|
if err:
|
|
|
|
|
return err
|
|
|
|
@ -528,7 +548,8 @@ class URLOption(DomainnameOption):
|
|
|
|
|
proto_re = re.compile(r'(http|https)://')
|
|
|
|
|
path_re = re.compile(r"^[A-Za-z0-9\-\._~:/\?#\[\]@!%\$&\'\(\)\*\+,;=]+$")
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
err = self._impl_valid_unicode(value)
|
|
|
|
|
if err:
|
|
|
|
|
return err
|
|
|
|
@ -574,7 +595,8 @@ class UsernameOption(Option):
|
|
|
|
|
#regexp build with 'man 8 adduser' informations
|
|
|
|
|
username_re = re.compile(r"^[a-z_][a-z0-9_-]{0,30}[$a-z0-9_-]{0,1}$")
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
err = self._impl_valid_unicode(value)
|
|
|
|
|
if err:
|
|
|
|
|
return err
|
|
|
|
@ -587,7 +609,8 @@ class FilenameOption(Option):
|
|
|
|
|
__slots__ = tuple()
|
|
|
|
|
path_re = re.compile(r"^[a-zA-Z0-9\-\._~/+]+$")
|
|
|
|
|
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined):
|
|
|
|
|
def _validate(self, value, context=undefined, current_opt=undefined,
|
|
|
|
|
returns_raise=False):
|
|
|
|
|
err = self._impl_valid_unicode(value)
|
|
|
|
|
if err:
|
|
|
|
|
return err
|
|
|
|
|