def requote_uri(uri):
 safe_with_percent = "!#$%&'()*+,/:;=?@[]~"
 safe_without_percent = "!#$&'()*+,/:;=?@[]~"
 try:
  return quote(unquote_unreserved(uri), safe=safe_with_percent)
 except InvalidURL:
  return quote(uri, safe=safe_without_percent)

def requote_uri ( uri ) : safe_with_percent = "!#$%&'()*+,/:;=?@[]~" safe_without_percent = "!#$&'()*+,/:;=?@[]~" try : return quote ( unquote_unreserved ( uri ) , safe = safe_with_percent ) except InvalidURL : return quote ( uri , safe = safe_without_percent )
re-quote the given uri .