def HostNameValid(host):
 valid = False
 for attr in ['AF_INET', 'AF_INET6']:
  try:
   socket.inet_pton(socket.__getattribute__(attr), host)
   valid = True
   break
  except socket.error:
   pass
 if (not valid):
  if ((not host) or ((not DnsNameValid(host)) and (not ALPHA_RE.match(host)))):
   return False
  else:
   return True
 else:
  return True

def HostNameValid ( host ) : valid = False for attr in [ 'AF_INET' , 'AF_INET6' ] : try : socket . inet_pton ( socket . __getattribute__ ( attr ) , host ) valid = True break except socket . error : pass if ( not valid ) : if ( ( not host ) or ( ( not DnsNameValid ( host ) ) and ( not ALPHA_RE . match ( host ) ) ) ) : return False else : return True else : return True
tests whether a string is a valid host-name .