Common: Style improvements in ip_ranges.py

This commit is contained in:
vakarisz 2022-08-01 10:56:45 +03:00
parent 16ac6b2e15
commit 3a6fcd670c
1 changed files with 3 additions and 4 deletions

View File

@ -47,7 +47,6 @@ def validate_hostname(hostname: str):
def validate_ip_network(ip_network: str): def validate_ip_network(ip_network: str):
try: try:
IPv4Network(ip_network, strict=False) IPv4Network(ip_network, strict=False)
return
except (NetmaskValueError, AddressValueError): except (NetmaskValueError, AddressValueError):
raise ValidationError(f"Invalid IPv4 network {ip_network}") raise ValidationError(f"Invalid IPv4 network {ip_network}")
@ -56,11 +55,11 @@ def validate_ip_range(ip_range: str):
try: try:
ip_range = ip_range.replace(" ", "") ip_range = ip_range.replace(" ", "")
ips = ip_range.split("-") ips = ip_range.split("-")
validate_ip(ips[0])
validate_ip(ips[1])
if len(ips) != 2: if len(ips) != 2:
raise ValidationError(f"Invalid IP range {ip_range}") raise ValidationError(f"Invalid IP range {ip_range}")
except (AddressValueError, IndexError): validate_ip(ips[0])
validate_ip(ips[1])
except IndexError:
raise ValidationError(f"Invalid IP range {ip_range}") raise ValidationError(f"Invalid IP range {ip_range}")