def unicode_to_ascii_authority(authority):
 labels = label_split_regex.split(authority)
 asciiLabels = []
 try:
  import encodings.idna
  for label in labels:
   if label:
    asciiLabels.append(to_native(encodings.idna.ToASCII(label)))
   else:
    asciiLabels.append('')
 except:
  asciiLabels = [str(label) for label in labels]
 return str(reduce((lambda x, y: ((x + unichr(46)) + y)), asciiLabels))

def unicode_to_ascii_authority ( authority ) : labels = label_split_regex . split ( authority ) asciiLabels = [ ] try : import encodings . idna for label in labels : if label : asciiLabels . append ( to_native ( encodings . idna . ToASCII ( label ) ) ) else : asciiLabels . append ( '' ) except : asciiLabels = [ str ( label ) for label in labels ] return str ( reduce ( ( lambda x , y : ( ( x + unichr ( 46 ) ) + y ) ) , asciiLabels ) )
follows the steps in rfc 3490 .