This commit is contained in:
2019-02-24 20:23:16 +01:00
parent 375b3c91de
commit af55e20afe
12 changed files with 76 additions and 80 deletions

View File

@ -148,11 +148,7 @@ class _TiramisuOptionOptionDescription(CommonTiramisuOption):
return self._option_bag.option
def type(self):
type_ = self._option_bag.option.__class__.__name__
if type_.endswith('Option'):
type_ = type_[:-6]
type_ = type_.lower()
return type_
return self._option_bag.option.get_display_type()
def isleadership(self):
"""Test if option is a leader or a follower"""
@ -659,29 +655,6 @@ class _TiramisuOptionDescription(_TiramisuOption):
return t_option
ret.append(t_option)
return ret
#
# def get(self, name):
# self._get_option()
# current_option = self._option_bag.option.get_child(name,
# self._config_bag,
# self._subconfig.cfgimpl_get_path)
# path = self._option_bag.path + '.' + name
# option_bag= OptionBag()
# option_bag.set_option(current_option,
# path,
# None,
# self._config_bag)
# if current_option.impl_is_optiondescription():
# subconfig = self._subconfig.getattr(name,
# option_bag)
# else:
# subconfig = self._subconfig
# return TiramisuOption(name,
# path,
# None,
# subconfig,
# self._config_bag,
# option_bag)
def group_type(self):
"""Get type for an optiondescription (only for optiondescription)"""

View File

@ -77,5 +77,5 @@ class ParamIndex(Param):
__slots__ = tuple()
def tiramisu_copy(val):
def tiramisu_copy(val): # pragma: no cover
return val

View File

@ -18,7 +18,6 @@
# the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/
# the whole pypy projet is under MIT licence
# ____________________________________________________________
import re
from types import FunctionType
from typing import FrozenSet, Callable, Tuple, Set, Optional, Union, Any, List
import weakref
@ -36,14 +35,12 @@ STATIC_TUPLE = frozenset()
submulti = 2
NAME_REGEXP = re.compile(r'^[a-zA-Z][a-zA-Z\d_-]*$')
def valid_name(name):
if not isinstance(name, str):
return False
return True
# return re.match(NAME_REGEXP, name) is not None
#____________________________________________________________

View File

@ -18,7 +18,7 @@
# the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/
# the whole pypy projet is under MIT licence
# ____________________________________________________________
from ipaddress import ip_address, IPv4Address, ip_network
from ipaddress import ip_address, ip_network
from ..error import ConfigError
from ..setting import undefined, Undefined, OptionBag
@ -42,8 +42,7 @@ class BroadcastOption(Option):
if val.startswith("0") and len(val) > 1:
raise ValueError()
try:
if not isinstance(ip_address(value), IPv4Address):
raise ValueError()
ip_address(value)
except ValueError:
raise ValueError()

View File

@ -111,22 +111,14 @@ class DomainnameOption(StrOption):
if not isinstance(value, str):
raise ValueError(_('invalid string'))
if self.impl_get_extra('_allow_ip') is True:
try:
if not isinstance(ip_address(value), IPv4Address):
raise ValueError()
except ValueError:
pass
else:
return
try:
ip_address(value)
except ValueError:
pass
else:
try:
if not isinstance(ip_address(value), IPv4Address):
raise ValueError()
except ValueError:
pass
else:
raise ValueError(_('must not be an IP'))
if self.impl_get_extra('_allow_ip') is True:
return
raise ValueError(_('must not be an IP'))
part_name_length = self._get_len(self.impl_get_extra('_dom_type'))
if self.impl_get_extra('_dom_type') == 'domainname':
if not self.impl_get_extra('_allow_without_dot') and not "." in value:

View File

@ -18,7 +18,7 @@
# the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/
# the whole pypy projet is under MIT licence
# ____________________________________________________________
from ipaddress import ip_address, ip_interface, ip_network, IPv4Address, IPv4Interface
from ipaddress import ip_address, ip_interface, ip_network
from ..error import ConfigError
from ..setting import undefined, Undefined, OptionBag
@ -90,11 +90,9 @@ class IPOption(StrOption):
# 'standard' validation
try:
if not cidr:
if not isinstance(ip_address(value), IPv4Address):
raise ValueError()
ip_address(value)
else:
if not isinstance(ip_interface(value), IPv4Address):
raise ValueError()
ip_interface(value)
except ValueError:
raise ValueError()

View File

@ -18,7 +18,7 @@
# the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/
# the whole pypy projet is under MIT licence
# ____________________________________________________________
from ipaddress import ip_address, ip_network, IPv4Network
from ipaddress import ip_address, ip_network
from ..setting import undefined
from ..i18n import _
@ -78,8 +78,7 @@ class NetworkOption(Option):
if val.startswith("0") and len(val) > 1:
raise ValueError()
try:
if not isinstance(ip_network(value), IPv4Network):
raise ValueError()
ip_network(value)
except ValueError:
raise ValueError()

View File

@ -206,13 +206,7 @@ class Option(BaseOption):
def impl_get_extra(self,
key: str) -> Any:
extra = getattr(self, '_extra', {})
if isinstance(extra, tuple):
if key in extra[0]:
return extra[1][extra[0].index(key)]
return None
else:
return extra.get(key)
return getattr(self, '_extra', {}).get(key)
#__________________________________________________________________________
# validator