safer option.type() (ref #4)
This commit is contained in:
parent
cc44cabf56
commit
2a6df8c8d8
19 changed files with 22 additions and 1 deletions
|
@ -148,7 +148,7 @@ class _TiramisuOptionOptionDescription(CommonTiramisuOption):
|
|||
return self._option_bag.option
|
||||
|
||||
def type(self):
|
||||
return self._option_bag.option.get_display_type()
|
||||
return self._option_bag.option.get_type()
|
||||
|
||||
def isleadership(self):
|
||||
"""Test if option is a leader or a follower"""
|
||||
|
|
|
@ -27,6 +27,7 @@ from .option import Option
|
|||
class BoolOption(Option):
|
||||
"represents a choice between ``True`` and ``False``"
|
||||
__slots__ = tuple()
|
||||
_type = 'boolean'
|
||||
_display_name = _('boolean')
|
||||
|
||||
def _validate(self,
|
||||
|
|
|
@ -28,6 +28,7 @@ from .option import Option
|
|||
|
||||
class BroadcastOption(Option):
|
||||
__slots__ = tuple()
|
||||
_type = 'broadcast_address'
|
||||
_display_name = _('broadcast address')
|
||||
|
||||
def _validate(self,
|
||||
|
|
|
@ -33,6 +33,7 @@ class ChoiceOption(Option):
|
|||
The option can also have the value ``None``
|
||||
"""
|
||||
__slots__ = tuple()
|
||||
_type = 'choice'
|
||||
_display_name = _('choice')
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -27,6 +27,7 @@ from .option import Option
|
|||
|
||||
class DateOption(Option):
|
||||
__slots__ = tuple()
|
||||
_type = 'date'
|
||||
_display_name = _('date')
|
||||
|
||||
def _validate(self,
|
||||
|
|
|
@ -35,6 +35,7 @@ class DomainnameOption(StrOption):
|
|||
fqdn: with tld, not supported yet
|
||||
"""
|
||||
__slots__ = tuple()
|
||||
_type = 'domainname'
|
||||
_display_name = _('domain name')
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -28,4 +28,5 @@ class EmailOption(RegexpOption):
|
|||
__slots__ = tuple()
|
||||
#https://www.w3.org/TR/html-markup/input.email.html#input.email.attrs.value.single.
|
||||
_regexp = re.compile(r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$")
|
||||
_type = 'email'
|
||||
_display_name = _('email address')
|
||||
|
|
|
@ -27,4 +27,5 @@ from .stroption import RegexpOption
|
|||
class FilenameOption(RegexpOption):
|
||||
__slots__ = tuple()
|
||||
_regexp = re.compile(r"^[a-zA-Z0-9\-\._~/+]+$")
|
||||
_type = 'filename'
|
||||
_display_name = _('file name')
|
||||
|
|
|
@ -27,6 +27,7 @@ from .option import Option
|
|||
class FloatOption(Option):
|
||||
"represents a choice of a floating point number"
|
||||
__slots__ = tuple()
|
||||
_type = 'float'
|
||||
_display_name = _('float')
|
||||
|
||||
def _validate(self,
|
||||
|
|
|
@ -27,6 +27,7 @@ from .option import Option
|
|||
class IntOption(Option):
|
||||
"represents a choice of an integer"
|
||||
__slots__ = tuple()
|
||||
_type = 'integer'
|
||||
_display_name = _('integer')
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -32,6 +32,7 @@ from .networkoption import NetworkOption
|
|||
class IPOption(StrOption):
|
||||
"represents the choice of an ip"
|
||||
__slots__ = tuple()
|
||||
_type = 'ip'
|
||||
_display_name = _('IP')
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -31,6 +31,7 @@ from .stroption import StrOption
|
|||
class NetmaskOption(StrOption):
|
||||
"represents the choice of a netmask"
|
||||
__slots__ = tuple()
|
||||
_type = 'netmask'
|
||||
_display_name = _('netmask address')
|
||||
|
||||
def _validate(self,
|
||||
|
|
|
@ -28,6 +28,7 @@ from .option import Option
|
|||
class NetworkOption(Option):
|
||||
"represents the choice of a network"
|
||||
__slots__ = tuple()
|
||||
_type = 'network'
|
||||
_display_name = _('network address')
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -179,6 +179,10 @@ class Option(BaseOption):
|
|||
def impl_is_dynsymlinkoption(self) -> bool:
|
||||
return False
|
||||
|
||||
def get_type(self) -> str:
|
||||
# _display_name for compatibility with older version than 3.0rc3
|
||||
return getattr(self, '_type', self._display_name)
|
||||
|
||||
def get_display_type(self) -> str:
|
||||
return self._display_name
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ from .stroption import StrOption
|
|||
class PasswordOption(StrOption):
|
||||
"represents the choice of a password"
|
||||
__slots__ = tuple()
|
||||
_type = 'password'
|
||||
_display_name = _('password')
|
||||
|
||||
def _validate(self,
|
||||
|
|
|
@ -40,6 +40,7 @@ class PortOption(StrOption):
|
|||
"""
|
||||
__slots__ = tuple()
|
||||
port_re = re.compile(r"^[0-9]*$")
|
||||
_type = 'port'
|
||||
_display_name = _('port')
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -29,6 +29,7 @@ from .option import Option
|
|||
class StrOption(Option):
|
||||
"represents the choice of a string"
|
||||
__slots__ = tuple()
|
||||
_type = 'string'
|
||||
_display_name = _('string')
|
||||
|
||||
def _validate(self,
|
||||
|
|
|
@ -30,6 +30,7 @@ class URLOption(DomainnameOption):
|
|||
__slots__ = tuple()
|
||||
proto_re = re.compile(r'(http|https)://')
|
||||
path_re = re.compile(r"^[A-Za-z0-9\-\._~:/\?#\[\]@!%\$&\'\(\)\*\+,;=]+$")
|
||||
_type = 'url'
|
||||
_display_name = _('URL')
|
||||
|
||||
def _validate(self,
|
||||
|
|
|
@ -28,4 +28,5 @@ class UsernameOption(RegexpOption):
|
|||
__slots__ = tuple()
|
||||
#regexp build with 'man 8 adduser' informations
|
||||
_regexp = re.compile(r"^[a-z_][a-z0-9_-]{0,30}[$a-z0-9_-]{0,1}$")
|
||||
_type = 'username'
|
||||
_display_name = _('username')
|
||||
|
|
Loading…
Reference in a new issue