def host_is_trusted(hostname, trusted_list):
 if (not hostname):
  return False
 if isinstance(trusted_list, string_types):
  trusted_list = [trusted_list]
 def _normalize(hostname):
  if (':' in hostname):
   hostname = hostname.rsplit(':', 1)[0]
  return _encode_idna(hostname)
 try:
  hostname = _normalize(hostname)
 except UnicodeError:
  return False
 for ref in trusted_list:
  if ref.startswith('.'):
   ref = ref[1:]
   suffix_match = True
  else:
   suffix_match = False
  try:
   ref = _normalize(ref)
  except UnicodeError:
   return False
  if (ref == hostname):
   return True
  if (suffix_match and hostname.endswith(('.' + ref))):
   return True
 return False

def host_is_trusted ( hostname , trusted_list ) : if ( not hostname ) : return False if isinstance ( trusted_list , string_types ) : trusted_list = [ trusted_list ] def _normalize ( hostname ) : if ( ':' in hostname ) : hostname = hostname . rsplit ( ':' , 1 ) [ 0 ] return _encode_idna ( hostname ) try : hostname = _normalize ( hostname ) except UnicodeError : return False for ref in trusted_list : if ref . startswith ( '.' ) : ref = ref [ 1 : ] suffix_match = True else : suffix_match = False try : ref = _normalize ( ref ) except UnicodeError : return False if ( ref == hostname ) : return True if ( suffix_match and hostname . endswith ( ( '.' + ref ) ) ) : return True return False
checks if a host is trusted against a list .