import socket
def _check_bootstrap_server(broker_list):
pattern = re.compile(r'.*?\[?([0-9a-zA-Z\-%._:]*)\]?:([0-9]+)')
for host_and_port in broker_list:
match = pattern.match(host_and_port)
if match:
try:
host = match.group(1)
port = int(match.group(2))
ok = False
for af in (socket.AF_INET, socket.AF_INET6):
try:
socket.inet_pton(af, host)
ok = True
break
except (ValueError, AttributeError, socket.error):
continue
assert ok, "Illegal hostname"
assert 0 <= port <= 65535, "Port out of range: " + str(port)
except socket.error:
return False
else:
return False
return True
copy from kafka2.audit.py