def _convert_to_idn(url):
 parts = list(urlparse.urlsplit(url))
 try:
  parts[1].encode(u'ascii')
 except UnicodeEncodeError:
  host = parts[1].rsplit(u':', 1)
  newhost = []
  port = u''
  if (len(host) == 2):
   port = host.pop()
  for h in host[0].split(u'.'):
   newhost.append(h.encode(u'idna').decode(u'utf-8'))
  parts[1] = u'.'.join(newhost)
  if port:
   parts[1] += (u':' + port)
  return urlparse.urlunsplit(parts)
 else:
  return url

def _convert_to_idn ( url ) : parts = list ( urlparse . urlsplit ( url ) ) try : parts [ 1 ] . encode ( u'ascii' ) except UnicodeEncodeError : host = parts [ 1 ] . rsplit ( u':' , 1 ) newhost = [ ] port = u'' if ( len ( host ) == 2 ) : port = host . pop ( ) for h in host [ 0 ] . split ( u'.' ) : newhost . append ( h . encode ( u'idna' ) . decode ( u'utf-8' ) ) parts [ 1 ] = u'.' . join ( newhost ) if port : parts [ 1 ] += ( u':' + port ) return urlparse . urlunsplit ( parts ) else : return url
convert a url to idn notation .