def clean_url(url):
 url = url.encode('utf8')
 url = ''.join([(urllib.parse.quote(c) if (ord(c) >= 127) else c) for c in url.decode('utf-8')])
 return url

def clean_url ( url ) : url = url . encode ( 'utf8' ) url = '' . join ( [ ( urllib . parse . quote ( c ) if ( ord ( c ) >= 127 ) else c ) for c in url . decode ( 'utf-8' ) ] ) return url
clean a url instance to string following these rules: * if there is a query string .