Example #1
0
 def punycode_url(self):
     """
     Convert url to punycode if necessary.
     """
     hostname = original = self.netloc_parts[2]
     hostname = hostname.strip('.')
     while '..' in hostname:
         hostname = hostname.replace('..', '.')
     punycode = hostname.encode('idna').decode('ascii')
     if punycode == original:
         return
     self.netloc_parts[2] = punycode
     self.url_parts[1] = unsplit_netloc(self.netloc_parts)
     self.cleaned_data['url'] = urlparse.urlunsplit(self.url_parts)