def sanitize_hostname(hostname):
 if isinstance(hostname, unicode):
  hostname = hostname.encode('latin-1', 'ignore')
 hostname = re.sub('[ _]', '-', hostname)
 hostname = re.sub('[^\\w.-]+', '', hostname)
 hostname = hostname.lower()
 hostname = hostname.strip('.-')
 return hostname

def sanitize_hostname ( hostname ) : if isinstance ( hostname , unicode ) : hostname = hostname . encode ( 'latin-1' , 'ignore' ) hostname = re . sub ( '[ _]' , '-' , hostname ) hostname = re . sub ( '[^\\w.-]+' , '' , hostname ) hostname = hostname . lower ( ) hostname = hostname . strip ( '.-' ) return hostname
return a hostname which conforms to rfc-952 and rfc-1123 specs .