def requote_uri(uri):
    """Requote uri if it contains non-ascii chars, spaces etc.
    """
    # To reduce tabulator import time
    import requests.utils
    if six.PY2:
        def url_encode_non_ascii(bytes):
            pattern = '[\x80-\xFF]'
            replace = lambda c: ('%%%02x' % ord(c.group(0))).upper()
            return re.sub(pattern, replace, bytes)
        parts = urlparse(uri)
        uri = urlunparse(
            part.encode('idna') if index == 1
            else url_encode_non_ascii(part.encode('utf-8'))
            for index, part in enumerate(parts))
    return requests.utils.requote_uri(uri)
def requote_uri ( uri ) : import requests . utils if six . PY2 : def url_encode_non_ascii ( bytes ) : pattern = '[\x80-\xFF]' replace = lambda c : ( '%%%02x' % ord ( c . group ( 0 ) ) ) . upper ( ) return re . sub ( pattern , replace , bytes ) parts = urlparse ( uri ) uri = urlunparse ( part . encode ( 'idna' ) if index == 1 else url_encode_non_ascii ( part . encode ( 'utf-8' ) ) for index , part in enumerate ( parts ) ) return requests . utils . requote_uri ( uri )
Requote uri if it contains non-ascii chars, spaces etc.