This commit is contained in:
2019-02-25 08:46:58 +01:00
parent 8be042434b
commit 46e5179d5e
7 changed files with 104 additions and 77 deletions

View File

@ -477,6 +477,7 @@ class _TiramisuOptionValueOption:
idx,
self._option_bag.config_bag)
value.append(values.getdefaultvalue(soption_bag))
return value
else:
return values.getdefaultvalue(self._option_bag)
@ -945,7 +946,7 @@ class TiramisuContextProperty(TiramisuContext):
def importation(self, properties):
"""Import config properties"""
if 'force_store_value' in properties:
if 'force_store_value' in properties.get(None, []):
force_store_value = 'force_store_value' not in self._config_bag.properties
else:
force_store_value = False
@ -1172,17 +1173,6 @@ class _TiramisuContextConfigReset():
# Remove cache
self._config_bag.context.cfgimpl_reset_cache(None, None)
def __call__(self,
path: Optional[str]):
"""select a child Tiramisu config"""
if path is None:
return Config(self._config_bag)
spaths = path.split('.')
config = self._config_bag.context
for spath in spaths:
config = config.getconfig(spath)
return Config(config)
class _TiramisuContextConfig(TiramisuContext, _TiramisuContextConfigReset):
"""Actions to Config"""
@ -1275,10 +1265,13 @@ class TiramisuContextCache(TiramisuContext):
def reset(self):
self._config_bag.context.cfgimpl_reset_cache(None, None)
def expiration_time(self,
time: int):
def set_expiration_time(self,
time: int) -> None:
self._config_bag.expiration_time = time
def get_expiration_time(self) -> int:
return self._config_bag.expiration_time
class TiramisuDispatcher:
pass

View File

@ -282,7 +282,7 @@ class Base:
return self._name
def _set_readonly(self) -> None:
if not self.impl_is_readonly():
if isinstance(self._informations, dict):
_setattr = object.__setattr__
dico = self._informations
keys = tuple(dico.keys())

View File

@ -59,22 +59,16 @@ class NetmaskOption(StrOption):
raise ConfigError(_('network_netmask needs a network and a netmask'))
if None in vals or len(vals) != 2:
return
msg = None
val_netmask, val_network = vals
try:
ip_network('{0}/{1}'.format(val_network, val_netmask))
except ValueError:
if current_opt == opts[1]:
raise ValueError(_('with netmask "{0}" ("{1}")').format(val_netmask, opts[0].impl_get_display_name()))
raise ValueError(_('with netmask "{0}" ("{1}")').format(val_netmask,
opts[0].impl_get_display_name()))
else:
raise ValueError(_('with network "{0}" ("{1}")').format(val_network, opts[1].impl_get_display_name()))
if msg is not None:
self.raise_err(msg,
val_netmask,
val_network,
current_opt,
opts,
'network')
raise ValueError(_('with network "{0}" ("{1}")').format(val_network,
opts[1].impl_get_display_name()))
def _cons_ip_netmask(self,
current_opt,
@ -90,46 +84,22 @@ class NetmaskOption(StrOption):
return
msg = None
val_netmask, val_ip = vals
try:
ip = ip_interface('{0}/{1}'.format(val_ip, val_netmask))
network = ip.network
# if not ip same has network
if ip.ip == network.network_address:
if not _cidr and current_opt == opts[1]:
msg = _('this is a network with netmask "{0}" ("{1}")')
else:
msg = _('{2} "{0}" ("{1}") is the network')
elif ip.ip == network.broadcast_address:
if not _cidr and current_opt == opts[1]:
msg = _('this is a broadcast with netmask "{0}" ("{1}")')
else:
msg = _('{2} "{0}" ("{1}") is the broadcast')
except ValueError:
import traceback
traceback.print_exc()
pass
ip = ip_interface('{0}/{1}'.format(val_ip, val_netmask))
network = ip.network
if ip.ip == network.network_address:
if not _cidr and current_opt == opts[1]:
msg = _('this is a network with netmask "{0}" ("{1}")')
else:
msg = _('IP "{0}" ("{1}") is the network')
elif ip.ip == network.broadcast_address:
if not _cidr and current_opt == opts[1]:
msg = _('this is a broadcast with netmask "{0}" ("{1}")')
else:
msg = _('IP "{0}" ("{1}") is the broadcast')
if msg is not None:
self.raise_err(msg,
val_netmask,
val_ip,
current_opt,
opts,
'IP',
_cidr)
def raise_err(self,
msg,
val_netmask,
val_ipnetwork,
current_opt,
opts,
typ,
_cidr=False):
if not _cidr and current_opt == opts[1]:
raise ValueError(msg.format(val_netmask,
opts[1].impl_get_display_name()))
else:
raise ValueError(msg.format(val_ipnetwork,
opts[0].impl_get_display_name(),
typ))
if not _cidr and current_opt == opts[1]:
raise ValueError(msg.format(val_netmask,
opts[0].impl_get_display_name()))
else:
raise ValueError(msg.format(val_ip,
opts[1].impl_get_display_name()))

View File

@ -206,7 +206,13 @@ class Option(BaseOption):
def impl_get_extra(self,
key: str) -> Any:
return getattr(self, '_extra', {}).get(key)
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)
#__________________________________________________________________________
# validator