'Pick the next server.
This selects the next server from the list of SRV records according
to their priority and weight values, as set out by the default
algorithm specified in RFC 2782.
At the beginning of a round, L{servers} is populated with
L{orderedServers}, and the latter is made empty. L{servers}
is the list of candidates, and L{orderedServers} is the list of servers
that have already been tried.
First, all records are ordered by priority and weight in ascending
order. Then for each priority level, a running sum is calculated
over the sorted list of records for that priority. Then a random value
between 0 and the final sum is compared to each record in order. The
first record that is greater than or equal to that random value is
chosen and removed from the list of candidates for this round.
@return: A tuple of target hostname and port from the chosen DNS SRV
record.
@rtype: L{tuple} of native L{str} and L{int}'

def pickServer(self):

    assert (self.servers is not None)
    assert (self.orderedServers is not None)
    if ((not self.servers) and (not self.orderedServers)):
        return (self.domain, self.service)
    if ((not self.servers) and self.orderedServers):
        self.servers = self.orderedServers
        self.orderedServers = []
    assert self.servers
    self.servers.sort(key=(lambda record: (record.priority, record.weight)))
    minPriority = self.servers[0].priority
    index = 0
    weightSum = 0
    weightIndex = []
    for x in self.servers:
        if (x.priority == minPriority):
            weightSum += x.weight
            weightIndex.append((index, weightSum))
            index += 1
    rand = random.randint(0, weightSum)
    for (index, weight) in weightIndex:
        if (weight >= rand):
            chosen = self.servers[index]
            del self.servers[index]
            self.orderedServers.append(chosen)
            return (str(chosen.target), chosen.port)
    raise RuntimeError(('Impossible    %s    pickServer    result.' % (self.__class__.__name__,)))
