Merge pull request #52678 from phlogistonjohn/jjm-fix-test_valid_addr

python-common: fix valid_addr on python 3.11

Reviewed-by: Adam King <adking@redhat.com>
This commit is contained in:
Adam King 2023-08-15 15:36:11 -04:00 committed by GitHub
commit d0b31b236a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,6 +70,9 @@ def valid_addr(addr: str) -> Tuple[bool, str]:
colons = addr.count(':')
addr_as_url = f'http://{addr}'
if addr.startswith('[') and dots:
return False, "IPv4 address wrapped in brackets is invalid"
try:
res = urlparse(addr_as_url)
except ValueError as e:
@ -89,9 +92,6 @@ def valid_addr(addr: str) -> Tuple[bool, str]:
elif ']:' in addr:
return False, 'Port must be numeric'
if addr.startswith('[') and dots:
return False, "IPv4 address wrapped in brackets is invalid"
# catch partial address like 10.8 which would be valid IPaddress schemes
# but are classed as invalid here since they're not usable
if dots and addr[0].isdigit() and dots != 3: