def collect_hosts(hosts, randomize=True):
 (host_ports, chroot) = hosts.partition('/')[::2]
 chroot = (('/' + chroot) if chroot else None)
 result = []
 for host_port in host_ports.split(','):
  res = urlsplit(('xxx://' + host_port))
  host = res.hostname
  port = (int(res.port) if res.port else 2181)
  result.append((host.strip(), port))
 if randomize:
  random.shuffle(result)
 return (result, chroot)

def collect_hosts ( hosts , randomize = True ) : ( host_ports , chroot ) = hosts . partition ( '/' ) [ : : 2 ] chroot = ( ( '/' + chroot ) if chroot else None ) result = [ ] for host_port in host_ports . split ( ',' ) : res = urlsplit ( ( 'xxx://' + host_port ) ) host = res . hostname port = ( int ( res . port ) if res . port else 2181 ) result . append ( ( host . strip ( ) , port ) ) if randomize : random . shuffle ( result ) return ( result , chroot )
collect a set of hosts and an optional chroot from a string .