def choose_hostname(hostnames=None, fallback=''):
 hostname = fallback
 if (hostnames is None):
  return hostname
 ip_regex = '\\A\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\Z'
 ips = [i for i in hostnames if ((i is not None) and isinstance(i, string_types) and re.match(ip_regex, i))]
 hosts = [i for i in hostnames if ((i is not None) and (i != '') and (i not in ips))]
 for host_list in (hosts, ips):
  for host in host_list:
   if hostname_valid(host):
    return host
 return hostname

def choose_hostname ( hostnames = None , fallback = '' ) : hostname = fallback if ( hostnames is None ) : return hostname ip_regex = '\\A\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\Z' ips = [ i for i in hostnames if ( ( i is not None ) and isinstance ( i , string_types ) and re . match ( ip_regex , i ) ) ] hosts = [ i for i in hostnames if ( ( i is not None ) and ( i != '' ) and ( i not in ips ) ) ] for host_list in ( hosts , ips ) : for host in host_list : if hostname_valid ( host ) : return host return hostname
choose a hostname from the provided hostnames given a list of hostnames and a fallback value .