remove unnecessary HostIterator classes
Unreferenced outside of their own file and not providing any real value
This commit is contained in:
@@ -6,35 +6,6 @@ except ImportError:
|
||||
# try python3 then
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
|
||||
class HostIterator(object):
|
||||
"""An iterator that returns selected hosts in order.
|
||||
|
||||
A host is guaranteed to not be selected twice unless there is only
|
||||
one host in the collection.
|
||||
"""
|
||||
|
||||
def __init__(self, hosts):
|
||||
self.hosts = hosts
|
||||
|
||||
def __iter__(self):
|
||||
for host in self.hosts[:]:
|
||||
yield host
|
||||
|
||||
def __len__(self):
|
||||
return len(self.hosts)
|
||||
|
||||
|
||||
class RandomHostIterator(HostIterator):
|
||||
"""An iterator that returns a randomly selected host."""
|
||||
|
||||
def __iter__(self):
|
||||
hostslist = self.hosts[:]
|
||||
random.shuffle(hostslist)
|
||||
for host in hostslist:
|
||||
yield host
|
||||
|
||||
|
||||
def collect_hosts(hosts, randomize=True):
|
||||
"""Collect a set of hosts and an optional chroot from a string."""
|
||||
host_ports, chroot = hosts.partition("/")[::2]
|
||||
@@ -48,6 +19,8 @@ def collect_hosts(hosts, randomize=True):
|
||||
host = res.hostname
|
||||
port = int(res.port) if res.port else 2181
|
||||
result.append((host.strip(), port))
|
||||
|
||||
if randomize:
|
||||
return (RandomHostIterator(result), chroot)
|
||||
return (HostIterator(result), chroot)
|
||||
random.shuffle(result)
|
||||
|
||||
return result, chroot
|
||||
|
||||
Reference in New Issue
Block a user