'Finds the best vhost for a target_name.
This does not upgrade a vhost to HTTPS... it only finds the most
appropriate vhost for the given target_name.
:returns: VHost or None'

def _find_best_vhost(self, target_name):

    best_candidate = None
    best_points = 0
    for vhost in self.vhosts:
        if (vhost.modmacro is True):
            continue
        names = vhost.get_names()
        if (target_name in names):
            points = 3
        elif self.included_in_wildcard(names, target_name):
            points = 2
        elif any(((addr.get_addr() == target_name) for addr in vhost.addrs)):
            points = 1
        else:
            continue
        if vhost.ssl:
            points += 3
        if (points > best_points):
            best_points = points
            best_candidate = vhost
    if (best_candidate is None):
        vhosts = self._non_default_vhosts()
        reasonable_vhosts = [vh for vh in vhosts if (vh.modmacro is False)]
        if (len(reasonable_vhosts) == 1):
            best_candidate = reasonable_vhosts[0]
    return best_candidate
