def collect_hosts(hosts, randomize=True):
    """
    Collects a comma-separated set of hosts (host:port) and optionally
    randomize the returned list.
    """

    if isinstance(hosts, six.string_types):
        hosts = hosts.strip().split(',')

    result = []
    for host_port in hosts:
        # ignore leading SECURITY_PROTOCOL:// to mimic java client
        host_port = re.sub('^.*://', '', host_port)
        host, port, afi = get_ip_port_afi(host_port)
        result.append((host, port, afi))

    if randomize:
        random.shuffle(result)
    return result

    Collects a comma-separated set of hosts (host:port) and optionally
    randomize the returned list.
    
kafka/cluster.py