option with str value has to depends on StrOption
This commit is contained in:
parent
a30eaacb1f
commit
5bb0c49949
10 changed files with 30 additions and 12 deletions
|
@ -5,12 +5,12 @@ from .masterslaves import MasterSlaves
|
|||
from .baseoption import submulti
|
||||
from .symlinkoption import SymLinkOption
|
||||
from .syndynoption import SynDynOption
|
||||
from .option import Option, RegexpOption
|
||||
from .option import Option
|
||||
from .choiceoption import ChoiceOption
|
||||
from .booloption import BoolOption
|
||||
from .intoption import IntOption
|
||||
from .floatoption import FloatOption
|
||||
from .stroption import StrOption, UnicodeOption
|
||||
from .stroption import StrOption, UnicodeOption, RegexpOption
|
||||
from .ipoption import IPOption
|
||||
from .portoption import PortOption
|
||||
from .networkoption import NetworkOption
|
||||
|
|
|
@ -24,9 +24,10 @@ from IPy import IP
|
|||
from ..setting import undefined, Undefined, OptionBag
|
||||
from ..i18n import _
|
||||
from .option import Option
|
||||
from .stroption import StrOption
|
||||
|
||||
|
||||
class DomainnameOption(Option):
|
||||
class DomainnameOption(StrOption):
|
||||
"""represents the choice of a domain name
|
||||
netbios: for MS domain
|
||||
hostname: to identify the device
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
import re
|
||||
|
||||
from ..i18n import _
|
||||
from .option import RegexpOption
|
||||
from .stroption import RegexpOption
|
||||
|
||||
|
||||
class EmailOption(RegexpOption):
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
import re
|
||||
|
||||
from ..i18n import _
|
||||
from .option import RegexpOption
|
||||
from .stroption import RegexpOption
|
||||
|
||||
|
||||
class FilenameOption(RegexpOption):
|
||||
|
|
|
@ -24,9 +24,10 @@ from ..error import ConfigError
|
|||
from ..setting import undefined, Undefined, OptionBag
|
||||
from ..i18n import _
|
||||
from .option import Option
|
||||
from .stroption import StrOption
|
||||
|
||||
|
||||
class IPOption(Option):
|
||||
class IPOption(StrOption):
|
||||
"represents the choice of an ip"
|
||||
__slots__ = tuple()
|
||||
_display_name = _('IP')
|
||||
|
|
|
@ -24,9 +24,10 @@ from ..error import ConfigError
|
|||
from ..setting import undefined, OptionBag, Undefined
|
||||
from ..i18n import _
|
||||
from .option import Option
|
||||
from .stroption import StrOption
|
||||
|
||||
|
||||
class NetmaskOption(Option):
|
||||
class NetmaskOption(StrOption):
|
||||
"represents the choice of a netmask"
|
||||
__slots__ = tuple()
|
||||
_display_name = _('netmask address')
|
||||
|
|
|
@ -22,9 +22,10 @@
|
|||
from ..setting import undefined, Undefined, OptionBag
|
||||
from ..i18n import _
|
||||
from .option import Option
|
||||
from .stroption import StrOption
|
||||
|
||||
|
||||
class PasswordOption(Option):
|
||||
class PasswordOption(StrOption):
|
||||
"represents the choice of a password"
|
||||
__slots__ = tuple()
|
||||
_display_name = _('password')
|
||||
|
|
|
@ -25,9 +25,10 @@ from typing import Union
|
|||
from ..setting import undefined, Undefined, OptionBag
|
||||
from ..i18n import _
|
||||
from .option import Option
|
||||
from .stroption import StrOption
|
||||
|
||||
|
||||
class PortOption(Option):
|
||||
class PortOption(StrOption):
|
||||
"""represents the choice of a port
|
||||
The port numbers are divided into three ranges:
|
||||
the well-known ports,
|
||||
|
@ -101,8 +102,6 @@ class PortOption(Option):
|
|||
value: Union[int,str],
|
||||
option_bag: OptionBag,
|
||||
current_opt: Option=Undefined) -> None:
|
||||
if isinstance(value, int):
|
||||
value = str(value)
|
||||
if not isinstance(value, str):
|
||||
raise ValueError(_('invalid string'))
|
||||
if self.impl_get_extra('_allow_range') and ":" in str(value):
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
# the whole pypy projet is under MIT licence
|
||||
# ____________________________________________________________
|
||||
import sys
|
||||
from typing import Any
|
||||
|
||||
from ..setting import undefined, Undefined, OptionBag
|
||||
from ..i18n import _
|
||||
|
@ -42,3 +43,17 @@ class StrOption(Option):
|
|||
class UnicodeOption(StrOption):
|
||||
__slots__ = tuple()
|
||||
_display_name = _('unicode')
|
||||
|
||||
|
||||
class RegexpOption(StrOption):
|
||||
__slots__ = tuple()
|
||||
|
||||
def _validate(self,
|
||||
value: Any,
|
||||
option_bag: OptionBag,
|
||||
current_opt: Option=Undefined) -> None:
|
||||
if not isinstance(value, str):
|
||||
raise ValueError(_('invalid string'))
|
||||
match = self._regexp.search(value)
|
||||
if not match:
|
||||
raise ValueError()
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
import re
|
||||
|
||||
from ..i18n import _
|
||||
from .option import RegexpOption
|
||||
from .stroption import RegexpOption
|
||||
|
||||
|
||||
class UsernameOption(RegexpOption):
|
||||
|
|
Loading…
Reference in a new issue