def smart_urlquote(url):
 (scheme, netloc, path, query, fragment) = urlparse.urlsplit(url)
 try:
  netloc = netloc.encode('idna')
 except UnicodeError:
  pass
 else:
  url = urlparse.urlunsplit((scheme, netloc, path, query, fragment))
 if (('%' not in url) or unquoted_percents_re.search(url)):
  url = urllib.quote(smart_str(url), safe="!*'();:@&=+$,/?#[]~")
 return force_unicode(url)

def smart_urlquote ( url ) : ( scheme , netloc , path , query , fragment ) = urlparse . urlsplit ( url ) try : netloc = netloc . encode ( 'idna' ) except UnicodeError : pass else : url = urlparse . urlunsplit ( ( scheme , netloc , path , query , fragment ) ) if ( ( '%' not in url ) or unquoted_percents_re . search ( url ) ) : url = urllib . quote ( smart_str ( url ) , safe = "!*'();:@&=+$,/?#[]~" ) return force_unicode ( url )
quotes a url if it isnt already quoted .