better message error
This commit is contained in:
parent
a33c7ed41e
commit
35ef218c9c
|
@ -70,9 +70,15 @@ class DomainnameOption(IPOption):
|
||||||
else:
|
else:
|
||||||
min_time = 1
|
min_time = 1
|
||||||
regexp = r'((?!-)[a-z0-9-]{{{1},{0}}}\.){{{1},}}[a-z0-9-]{{1,{0}}}'.format(self._get_len(type_), min_time)
|
regexp = r'((?!-)[a-z0-9-]{{{1},{0}}}\.){{{1},}}[a-z0-9-]{{1,{0}}}'.format(self._get_len(type_), min_time)
|
||||||
|
msg = _('only lowercase, number, "-" and "." are characters are allowed')
|
||||||
|
msg_warning = _('only lowercase, number, "-" and "." are characters are recommanded')
|
||||||
else:
|
else:
|
||||||
regexp = r'((?!-)[a-z0-9-]{{1,{0}}})'.format(self._get_len(type_))
|
regexp = r'((?!-)[a-z0-9-]{{1,{0}}})'.format(self._get_len(type_))
|
||||||
|
msg = _('only lowercase, number and - are characters are allowed')
|
||||||
|
msg_warning = _('only lowercase, number and "-" are characters are recommanded')
|
||||||
if allow_ip:
|
if allow_ip:
|
||||||
|
msg = _('could be a IP, otherwise {}').format(msg)
|
||||||
|
msg_warning = _('could be a IP, otherwise {}').format(msg_warning)
|
||||||
if not cidr:
|
if not cidr:
|
||||||
regexp = r'^(?:{0}|(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){{3}}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))$'.format(regexp)
|
regexp = r'^(?:{0}|(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){{3}}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))$'.format(regexp)
|
||||||
else:
|
else:
|
||||||
|
@ -80,6 +86,8 @@ class DomainnameOption(IPOption):
|
||||||
else:
|
else:
|
||||||
regexp = r'^{0}$'.format(regexp)
|
regexp = r'^{0}$'.format(regexp)
|
||||||
extra['_domain_re'] = re.compile(regexp)
|
extra['_domain_re'] = re.compile(regexp)
|
||||||
|
extra['_domain_re_message'] = msg
|
||||||
|
extra['_domain_re_message_warning'] = msg_warning
|
||||||
extra['_has_upper'] = re.compile('[A-Z]')
|
extra['_has_upper'] = re.compile('[A-Z]')
|
||||||
|
|
||||||
super().__init__(name,
|
super().__init__(name,
|
||||||
|
@ -141,6 +149,6 @@ class DomainnameOption(IPOption):
|
||||||
raise ValueError(_('some characters are uppercase'))
|
raise ValueError(_('some characters are uppercase'))
|
||||||
if not self.impl_get_extra('_domain_re').search(value):
|
if not self.impl_get_extra('_domain_re').search(value):
|
||||||
if warnings_only:
|
if warnings_only:
|
||||||
raise ValueError(_('some characters may cause problems'))
|
raise ValueError(self.impl_get_extra('_domain_re_message_warning'))
|
||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError(self.impl_get_extra('_domain_re_message'))
|
||||||
|
|
|
@ -144,9 +144,8 @@ class IPOption(StrOption):
|
||||||
ip, network = vals
|
ip, network = vals
|
||||||
network_obj = ip_network(network)
|
network_obj = ip_network(network)
|
||||||
if ip_interface(ip) not in network_obj:
|
if ip_interface(ip) not in network_obj:
|
||||||
msg = _('"{0}" is not in network "{1}" ("{2}")')
|
msg = _('IP not in network "{0}" ("{1}")')
|
||||||
raise ValueError(msg.format(ip,
|
raise ValueError(msg.format(network,
|
||||||
network,
|
|
||||||
opts[1].impl_get_display_name()))
|
opts[1].impl_get_display_name()))
|
||||||
# test if ip is not network/broadcast IP
|
# test if ip is not network/broadcast IP
|
||||||
netmask = NetmaskOption(self.impl_getname(),
|
netmask = NetmaskOption(self.impl_getname(),
|
||||||
|
@ -166,12 +165,18 @@ class IPOption(StrOption):
|
||||||
ip, network, netmask = vals
|
ip, network, netmask = vals
|
||||||
if ip_interface(ip) not in ip_network('{0}/{1}'.format(network,
|
if ip_interface(ip) not in ip_network('{0}/{1}'.format(network,
|
||||||
netmask)):
|
netmask)):
|
||||||
msg = _('"{4}" is not in network "{0}"/"{1}" ("{2}"/"{3}")')
|
if current_opt == opts[0]:
|
||||||
raise ValueError(msg.format(network,
|
msg = _('IP not in network "{2}"/"{4}" ("{3}"/"{5}")')
|
||||||
netmask,
|
elif current_opt == opts[1]:
|
||||||
|
msg = _('the network doest not match with IP "{0}" ("{1}") and network "{4}" ("{5}")')
|
||||||
|
else:
|
||||||
|
msg = _('the netmask does not match with IP "{0}" ("{1}") and broadcast "{2}" ("{3}")')
|
||||||
|
raise ValueError(msg.format(ip,
|
||||||
|
opts[0].impl_get_display_name(),
|
||||||
|
network,
|
||||||
opts[1].impl_get_display_name(),
|
opts[1].impl_get_display_name(),
|
||||||
opts[2].impl_get_display_name(),
|
netmask,
|
||||||
ip))
|
opts[2].impl_get_display_name()))
|
||||||
# test if ip is not network/broadcast IP
|
# test if ip is not network/broadcast IP
|
||||||
opts[2]._cons_ip_netmask(current_opt,
|
opts[2]._cons_ip_netmask(current_opt,
|
||||||
(opts[2], opts[0]),
|
(opts[2], opts[0]),
|
||||||
|
|
|
@ -66,11 +66,11 @@ class NetmaskOption(StrOption):
|
||||||
ip_network('{0}/{1}'.format(val_network, val_netmask))
|
ip_network('{0}/{1}'.format(val_network, val_netmask))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if current_opt == opt_network:
|
if current_opt == opt_network:
|
||||||
raise ValueError(_('with netmask "{0}" ("{1}")').format(val_netmask,
|
raise ValueError(_('the netmask "{0}" ("{1}") does not match').format(val_netmask,
|
||||||
opt_netmask.impl_get_display_name()))
|
opt_netmask.impl_get_display_name()))
|
||||||
else:
|
else:
|
||||||
raise ValueError(_('with network "{0}" ("{1}")').format(val_network,
|
raise ValueError(_('the network "{0}" ("{1}") does not match').format(val_network,
|
||||||
opt_network.impl_get_display_name()))
|
opt_network.impl_get_display_name()))
|
||||||
|
|
||||||
def _cons_ip_netmask(self,
|
def _cons_ip_netmask(self,
|
||||||
current_opt: Option,
|
current_opt: Option,
|
||||||
|
|
Loading…
Reference in New Issue