HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/cloudinit/__pycache__/url_helper.cpython-38.pyc
U

��0h���@sddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZddlm
Z
ddlmZddlmZddlmZddlmZddlmZmZmZmZmZmZmZmZmZdd	l m!Z!m"Z"m#Z#m$Z$ddl%Z%dd
l%m&Z&ddl'm(Z(m)Z)m*Z*e�+e,�Z-dZ.eed
ge/fZ0dd�Z1dd�Z2e3d�dd�Z4dMe5e6e7dd�dd�Z8e5dd�dd�Z9edd�dd �Z:Gd!d"�d"�Z;Gd#d�de;�Z<Gd$d�de;�Z=Gd%d&�d&�Z>Gd'd
�d
e?�Z@d(d)�ZAe5e6d*�d+d,�ZBdd-�e@e0ee6d.�d/d0�ZCdddd1ddddd2d2ddd3d2d4d3d5�e0e/e>d6�d7d8�ZDdNed9efe5e3ejEee6ed:�d;d<�ZFdOed9efee5e6e3eee5ee>fd?�d@dA�ZGGdBdC�dCe�ZHe6dD�de-jIdddddd4d2d=dE�e6ee6eeeee6e0eeee6ge6fe5e/e6dF�
dGdH�ZJGdIdJ�dJ�ZKdPdKdL�ZLdS)Q�N)�ThreadPoolExecutor�TimeoutError�as_completed)�	parsedate)�partial)�	NOT_FOUND)�count)�create_default_context)	�Any�Callable�Iterator�List�Mapping�
NamedTuple�Optional�Tuple�Union)�quote�urlparse�urlsplit�
urlunparse)�
exceptions)�performance�util�version�REDACTED�UrlErrorcCs<tt|dd��}|ds4|dr4|d|d<d|d<t|�S)N�http)�scheme���)�listrr)�urlZ
parsed_url�r$�6/usr/lib/python3/dist-packages/cloudinit/url_helper.py�	_cleanurl1s
r&cGs$dd�}|}|D]}|||�}q|S)NcSsNtt|��}|d}|r*|�d�s*|d7}|tt|�dd�7}||d<t|�S)Nr �/z/:)Zsafe)r"r�endswithr�strr)r#�add_onZ
url_parsed�pathr$r$r%�combine_single<sz#combine_url.<locals>.combine_singler$)�baseZadd_onsr,r#r*r$r$r%�combine_url;s
	r.��returnc
CsVtjdtjdtjdtjdtdi}|�t|��}|sRt|t	�rD|j
}nt�d�d}|S)z4helper for read_ftps to map return codes to a number�,���iXi�z9Unexpected exception type while connecting to ftp server.i����)
�ftplibZerror_replyZ
error_temp�
error_permZerror_proto�EOFError�get�type�
isinstance�OSError�errno�LOG�warning)�excZftp_error_codes�coder$r$r%�"ftp_get_return_code_from_exceptionKs(�
�r@�@�FtpResponse)r#�timeout�kwargsr0cKs
t|�}|jstdtd|d��t�����}|jp2d}|jp<d}d|jk�r�z6t	j
t�d�}t�
d||�|j|j||pxd	d
�WnLt	jk
r�}z,t|�}	td|�d|	�d
�|	d|d�|�W5d}~XYnXt�
d|�z*|j||jp�dd�t�
d�|��WnBt	jk
�rF}z t�d�tddd|d�|�W5d}~XYnXz�zFt�
d|j�|jd|j��|jd�t|��|�WW�`W5QR�St	jk
�r�}z,t|�}	td|�d|	�d
�|	d|d�|�W5d}~XYnXW5t�
d�|��X�nz�z�t	��}
t�
d||�|
j|j||�p(d	d
�t�
d|�|
j||j�pJdd�t�
d|j�|
jd|j��|jd�t|��|�WW�`W5QR�St	jk
�r�}z,t|�}	td|�d|	�d
�|	d|d�|�W5d}~XYnXW5t�
d�|
��XW5QRXdS)azconnect to URL using ftp over TLS and read a file

    when using strict mode (ftps://), raise exception in event of failure
    when not using strict mode (ftp://), fall back to using unencrypted ftp

    url: string containing the desination to read a file from. The url is
        parsed with urllib.urlsplit to identify username, password, host,
        path, and port in the following format:
            ftps://[username:password@]host[:port]/[path]
        host is the only required component
    timeout: maximum time for the connection to take
    kwargs: unused, for compatibility with read_url
    returns: UrlResponse
    zInvalid url providedN��causer?�headersr#�Z	anonymous�ftps)�contextz3Attempting to connect to %s via port [%s] over tls.rA)�host�portrCz1Reading file from server over tls failed for url z [�]z"Attempting to login with user [%s]r!)�userZpasswdzCreating a secure connectionz�Attempted to connect to an insecure ftp server but used a scheme of ftps://, which is not allowed. Use ftp:// to allow connecting to insecure ftp servers.r3zClosing connectionzReading file: %szRETR )�callbackz,Reading file from ftp server failed for url z(Attempting to connect to %s via port %s.)rZhostnamerr�io�BytesIOrLZusernamerr4ZFTP_TLSr	r<�debugZconnectZ
all_errorsr@ZloginZpasswordZprot_pr5r=�closer+Z
retrbinary�writerB�getvalueZFTP)r#rCrDZ	url_parts�bufferrLrNZftp_tls�er?�ftpr$r$r%�	read_ftpsbs��

���
��	�
��	�

� ��

��
� ��

rY�FileResponse)r+r0c
Ks�|�d�rt�d|�zt�|�}t||�WStk
r`}zt|td|d�|�W5d}~XYn6t	k
r�}zt||j
d|d�|�W5d}~XYnXdS)zmread a binary file and return a FileResponse

    matches function signature with read_ftps and read_url
    �dataz'Unable to post data to file resource %sNrE)r7r<r=rZload_binary_filerZ�FileNotFoundErrorrr�IOErrorr;)r+rD�contentsrWr$r$r%�
_read_file�s

"r_)rZ�UrlResponserBc
Ks�|��}zt|�}Wn0tk
rD}zt||d�|�W5d}~XYnX|j}|dksd|rrd|dkrrt|jf|�S|dkr�t|f|�S|dkr�t|f|�St	�
d|�t|f|�SdS)	a0Wrapper function around readurl to allow passing a file path as url.

    When url is not a local file path, passthrough any kwargs to readurl.

    In the case of parameter passthrough to readurl, default values for some
    parameters. See: call-signature of readurl in this module for param docs.
    )rFr#N�filer'r)rXrI)r�httpszAttempting unknown protocol %s)�lstripr�
ValueErrorrrr_r+rY�readurlr<r=)r#rDZparsedrWrr$r$r%�read_file_or_url�s
 rfc@s&eZdZd	dd�Zdd�Zdd�ZdS)
�StringResponse��cCs||_i|_||_||_dS�N)r?rGr^r#��selfr^r#r?r$r$r%�__init__szStringResponse.__init__cOs
|jdkS)Nrh�r?�rk�argsrDr$r$r%�okszStringResponse.okcCs|j�d�S)Nzutf-8)r^�decode�rkr$r$r%�__str__szStringResponse.__str__N)rh)�__name__�
__module__�__qualname__rlrprsr$r$r$r%rgs
rgcs&eZdZdeed��fdd�
Z�ZS)rZrh�r^r#cst�j|||d�dS)Nrm��superrlrj��	__class__r$r%rl!szFileResponse.__init__)rh�rtrurv�bytesr)rl�
__classcell__r$r$rzr%rZ scs$eZdZeed��fdd�Z�ZS)rBrwcst��||�dSrirx)rkr^r#rzr$r%rl&szFtpResponse.__init__r|r$r$rzr%rB%sc@s�eZdZejd�dd�Zeed�dd��Zee	d�dd��Z
ded�d
d�Zedd
��Z
eed�dd��Zdd�Zdeeeeed�dd�ZdS)r`)�responsecCs
||_dSri)�	_response)rkrr$r$r%rl+szUrlResponse.__init__r/cCs|jjdkrdS|jjS)N�)r��contentrrr$r$r%r^.szUrlResponse.contentscCs|jjSri)r�r#rrr$r$r%r#4szUrlResponse.urlFcCs2d}|rd}d|jkr"|kr*nndSdSdS)Nr1r2rhTFrm)rkZredirects_ok�upperr$r$r%rp8szUrlResponse.okcCs|jjSri)r�rGrrr$r$r%rGAszUrlResponse.headerscCs|jjSri)r��status_coderrr$r$r%r?EszUrlResponse.codecCs|jjSri)r��textrrr$r$r%rsIszUrlResponse.__str__r)�
chunk_size�decode_unicoder0ccs|j�||�EdHdS)atIterates over the response data.

        When stream=True is set on the request, this avoids reading the content
        at once into memory for large responses.

        :param chunk_size: Number of bytes it should read into memory.
        :param decode_unicode: If True, content will be decoded using the best
        available encoding based on the response.
        N)r��iter_content)rkr�r�r$r$r%r�LszUrlResponse.iter_contentN)F)rF)rtrurv�requestsZResponserl�propertyr}r^r)r#�boolrprG�intr?rsrrr�r$r$r$r%r`*s$	
��r`c@s.eZdZdeeeeeeed�dd�ZdS)rNrEcCs8t�|t|��||_||_|dkr(in||_||_dSri)r]rlr)rFr?rGr#)rkrFr?rGr#r$r$r%rl\s
zUrlError.__init__)NNN)	rtrurvr
rr�rr)rlr$r$r$r%r[s��cCs�i}t|�j}|dkr~|r~d|kr8|dr8|d|d<nd|d<d|krfd|krf|d|dg|d<nd|kr~t|d�|d<|S)NrbZca_certsZverifyTZ	cert_fileZkey_fileZcert)rrr))r#�ssl_detailsZssl_argsrr$r$r%�
_get_ssl_argsjs
�
r�)�retry_afterr0cCs�zt|�}Wn~tk
r�z.t|�}|s2td��tt�|�t���}Wn$tk
rnt�d|�d}YnX|dkr�t�d�d}YnX|S)a<Parse a Retry-After header value into an integer.

    : param retry_after: The value of the Retry-After header.
        https://www.rfc-editor.org/rfc/rfc9110.html#section-10.2.3
        https://www.rfc-editor.org/rfc/rfc2616#section-3.3
    : return: The number of seconds to wait before retrying the request.
    z(Failed to parse Retry-After header valuezGFailed to parse Retry-After header value: %s. Waiting 1 second instead.rrzBRetry-After header value is in the past. Waiting 1 second instead.)�floatrdr�time�mktimer<�info)r�Zto_waitZ
time_tupler$r$r%�_get_retry_after|s(�
�
r���exception_cb)�errorr�r0cCs`|r||�rdS|jrP|jdkrPt�d�|jrBt|j�dd��St�d�dS|sXdS|�dS)a�Handle exceptions raised during request processing.

    If we have no exception callback or the callback handled the error or we
    got a 503, return with an optional timeout so the request can be retried.
    Otherwise, raise the error.

    :param error: The exception raised during the request.
    :param response: The response object.
    :param exception_cb: Callable to handle the exception.

    :return: Optional time to wait before retrying the request.
    Ni�zNEc2 IMDS endpoint returned a 503 error. HTTP endpoint is overloaded. Retrying.zRetry-After�1z7Unable to introspect response header. Waiting 1 second.r)r?r<r=rGr�r7r�)r�r�r$r$r%�
_handle_error�s�
r�rTFr!)r[rC�retries�sec_betweenrG�
headers_cb�headers_redactr��check_status�allow_redirectsr��session�infinite�log_req_resp�request_method�stream)r�r�r0c st|�}||d�}|�t||��|
|d<|s:|r6dnd}||d<|dk	rpt|t�r^||d<ntt|�d�|d<|dkr|g}d	}|r�tt|�d	d	�}d
t�	�}|dk	r�|�
�}ni}|r�||d<|dkr�d}|dkr�t��}t
�D�]}|r�||�}d
|k�r
||d
<||d<i}|��D]p\}�|dk�r4�q|dk�r�|�r��fdd�|D�}|�r�t
���||<|D]}t|||<�qnn�||<�qzh|�r�t�d||
�r�dn|||�|jf|�}|	�r�|��t�d||jt|j�|d	�t|�WStjk
�r,}zt||d�|�W5d}~XYnztjk
�rl}z t||jj|jj|d�}|}W5d}~XYn:tjk
�r�}zt||d�}|}d}W5d}~XYnXt ||d�}|�s�|
�p�|d	|k}|�s�||�|�p�|}|dkr�|�r�t�d|�t!�"|�q�t#d��dS)a`Wrapper around requests.Session to read the url and retry if necessary

    :param url: Mandatory url to request.
    :param data: Optional form data to post the URL. Will set request_method
        to 'POST' if present.
    :param timeout: Timeout in seconds to wait for a response. May be a tuple
        if specifying (connection timeout, read timeout).
    :param retries: Number of times to retry on exception if exception_cb is
        None or exception_cb returns True for the exception caught. Default is
        to fail with 0 retries on exception.
    :param sec_between: Default 1: amount of seconds passed to time.sleep
        between retries. None or -1 means don't sleep.
    :param headers: Optional dict of headers to send during request
    :param headers_cb: Optional callable returning a dict of values to send as
        headers during request
    :param headers_redact: Optional list of header names to redact from the log
    :param ssl_details: Optional dict providing key_file, ca_certs, and
        cert_file keys for use on in ssl connections.
    :param check_status: Optional boolean set True to raise when HTTPError
        occurs. Default: True.
    :param allow_redirects: Optional boolean passed straight to Session.request
        as 'allow_redirects'. Default: True.
    :param exception_cb: Optional callable to handle exception and returns
        True if retries are permitted.
    :param session: Optional exiting requests.Session instance to reuse.
    :param infinite: Bool, set True to retry indefinitely. Default: False.
    :param log_req_resp: Set False to turn off verbose debug messages.
    :param request_method: String passed as 'method' to Session.request.
        Typically GET, or POST. Default: POST if data is provided, GET
        otherwise.
    :param stream: if False, the response content will be immediately
    downloaded.
    )r#r�r�ZPOSTZGET�methodNrCrrz
Cloud-Init/%sr[���z
User-AgentrGcsg|]}��|�r|�qSr$)r7)�.0�k��vr$r%�
<listcomp>'s
zreadurl.<locals>.<listcomp>z'[%s/%s] open '%s' with %s configurationr�z(Read from %s (%s, %sb) after %s attempts�r#�r?rGr#r��1Please wait %s seconds while we wait to try againz"This path should be unreachable...)$r&�updater�r9�tuple�maxr�r�rZversion_string�copyr�ZSessionr�items�deepcopyrr<rRZrequest�raise_for_statusr��lenr�r`rZSSLErrorr�	HTTPErrorrrGZRequestExceptionr�r��sleep�RuntimeError) r#r[rCr�r�rGr�r�r�r�r�r�r�r�r�r�r�Zreq_argsZmanual_triesZ
user_agent�iZfiltered_req_argsr�Zmatched_headers�keyrrWZ	url_errorZraised_exceptionZresponse_sleep_timeZ
will_retry�
sleep_timer$r�r%re�s�5�




��
��
�re.)�func�addrrC�event�delayr0cCs|r|j|d�rdS|||�S)z Execute func with optional delay�rCN��wait�r�r�rCr�r�r$r$r%�_run_func_with_delaypsr��333333�?�
)r��	addresses�
stagger_delayrCr0cs$d}d}d}g}t���tt|�d��z�z������fdd�t|�D�}t|�d�D]N}	||	}|	��}
|
r||
}|�|�qT|	�	�}|rT��
�||fWW�nSqT|r�t�d||�|�nt�
d	|�td
��Wn6tk
�rt�dd�|�d�tt|���YnXW5�jdd�X||fS)
aexecute multiple callbacks in parallel

    Run blocking func against two different addresses staggered with a
    delay. The first call to return successfully is returned from this
    function and remaining unfinished calls are cancelled if they have not
    yet started
    N)Zmax_workersFr�c
s,i|]$\}}�jt�|��|�d�|�qS)r�)Zsubmitr�)r�r�r��Zexecutorr�Zis_doner�rCr$r%�
<dictcomp>�s	��zdual_stack.<locals>.<dictcomp>r�z<Exception(s) %s during request to %s, raising last exceptionzEmpty result for address %szNo result returnedzJTimed out waiting for addresses: %s, exception(s) raised while waiting: %s� )�	threading�Eventrr�Zshutdown�	enumerater�	exception�append�result�setr<r=r�rdr�join�mapr))r�r�r�rCZ
return_resultZreturned_addressZlast_exceptionrZfuturesZfutureZreturn_exceptionr$r�r%�
dual_stack�sJ
	�
��r�c@s2eZdZUeeed<eeed<eeed<dS)�HandledResponser#r�	wait_timeN)rtrurvrr)�__annotations__r`r�r$r$r$r%r��s
r��inf)�max_waitrC�	status_cbr�r�r�r��
sleep_time_cbr��connect_synchronously�async_delay)
r�rCr�r�r�r�r�r�r�r�cs�ttd��
fdd�}dtttd�dd��ttttttttfd�d	d
��ttgtttttfft	tt
tfttttd���fdd
��tttd����	fdd��td��������fdd�}
td�����fdd�}t
��}�
r�|r�td��|
�r|
n|}|�p|}d�d}|||||�}d�|j�rB|j|jjfS|j�rft
�|j��d�d��q||��}��||��r��qވd�t�d|�t
�|�t
��}|�r|||�k�r�||}|dk�r�qސqdS)a
Wait for a response from one of the urls provided.

    :param urls: List of urls to try
    :param max_wait: Roughly the maximum time to wait before giving up
        The max time is *actually* len(urls)*timeout as each url will
        be tried once and given the timeout provided.
        a number <= 0 will always result in only one try
    :param timeout: Timeout provided to urlopen
    :param status_cb: Callable with string message when a url is not available
    :param headers_cb: Callable with single argument of url to get headers
        for request.
    :param headers_redact: List of header names to redact from the log
    :param sleep_time: Amount of time to sleep between retries. If this and
        sleep_time_cb are None, the default sleep time defaults to 1 second
        and increases by 1 seconds every 5 tries. Cannot be specified along
        with `sleep_time_cb`.
    :param exception_cb: Callable to handle exception and returns True if
        retries are permitted.
    :param sleep_time_cb: Callable with 2 arguments (response, loop_n) that
        generates the next sleep time. Cannot be specified
        along with 'sleep_time`.
    :param request_method: Indicates the type of HTTP request:
        GET, PUT, or POST
    :param connect_synchronously: If false, enables executing requests
        in parallel
    :param async_delay: Delay before parallel metadata requests, see RFC 6555

    :return: tuple of (url, response contents), on failure, (False, None)

    :raises: UrlError on unrecoverable error
    )�loop_numberr0cs�dk	r�S|ddS)N�rr$)�_r�)r�r$r%�default_sleep_time
sz(wait_for_url.<locals>.default_sleep_timer�r��
start_timer�cSs0|td�dfkrdS|dkp.t��|||kS)z4Check if time is up based on start time and max waitr�NFr)r�r��	monotonicr�r$r$r%�timeups
�zwait_for_url.<locals>.timeup)rr#r0c
Ss�d}d}|r|s(d}tt|��}||fSz|j��WnNtjjk
r�}z,t||jj|jj	|d�}|t
|�fWY�Sd}~XYnX|js�d|j}tt|�|j|j	|d�}n*|�
�s�d|j}tt|�|j|j	|d�}||fS)z?Map requests response code/contents to internal "UrlError" typer!NzRequest timed outr�zempty response [%s]zbad status code [%s])rrdr�r�r�rr�rr�rGr)r^r?rp)rr#�reason�url_excrWr$r$r%�handle_url_responsesB�"
�
�z)wait_for_url.<locals>.handle_url_response)�
url_reader_cb�urlsr��exc_cb�log_cbr0c

s�d}d}z2||�\}}�||�\}}|s8t||dd�WSWnZtk
rh}	zd|	}|	}W5d}	~	XYn.tk
r�}	zd|	}|	}W5d}	~	XYnXtt��|�}
�r�d�nd}d|p�t|d	d	�|
||f}||�tddt|t�r�t||d
�ndd�S)z:Execute request, handle response, optionally log exceptionr!N)r�zrequest error [%s]zunexpected error [%s]z%ssZ	unlimitedzCalling '%s' failed [%s/%s]: %sr#r��r#rr�)	r�r�	Exceptionr�r�r��getattrr9r�)
r�r�r�r�r�r�r#rr�rWZ
time_takenZmax_wait_strZ
status_msg)r�r�r$r%�read_url_handle_exceptionsAs:
���z0wait_for_url.<locals>.read_url_handle_exceptions)r#rCr0cs$t|�dkrin�|��|d�d�S)NF)rGr�rCr�r�)re)r#rC)r�r�r�r$r%�read_url_cbms�z!wait_for_url.<locals>.read_url_cbr/c
s�td���fdd�}g}�D]�}t��}�dkr|�s|��|�rPtdddd�S�dk	r|�r||�|�kr|t|�|���|||||�}|jr�|S|jr|�|j�q|r�t|�nd}	tdd|	d�S)z|iterate over list of urls, request each one and handle responses
        and thrown exceptions individually per url
        r�cs|�|��fSrir$r�)r�rCr$r%�url_reader_serial~sz@wait_for_url.<locals>.read_url_serial.<locals>.url_reader_serialrNr�)	r)r�r�r�r�rr�r�r�)
r�rCr�r�r�Z
wait_timesr#Znow�outr�)�loop_nr��must_try_againr�r�r�r�r�r%�read_url_serialws>
�
����z%wait_for_url.<locals>.read_url_serialcs tt��|d�}�|�|||�S)z�pass list of urls to dual_stack which sends requests in parallel
        handle response and exceptions of the first endpoint to respond
        )r�rC)rr�)r�rCr�r�Zurl_reader_parallel)r�r�r�r�r$r%�read_url_parallel�s��z'wait_for_url.<locals>.read_url_parallelz3sleep_time and sleep_time_cb are mutually exclusiveNFrTr�)FN)r)r�r�rr`r)rrrr
rr
�ExceptionCallbackr�r�r�rdrr#r^r�r�r<rR)r�r�rCr�r�r�r�r�r�r�r�r�r�r�r�r�Zdo_read_urlZcalculate_sleep_timerZrespZcurrent_sleep_timeZcurrent_timer$)
r�r�r�r�r�r�r�r�r�r�r�r�r�r%�wait_for_url�sh/	�*��,�&��

�

r�c@s^eZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�ZdS)�OauthUrlHelperN�/run/oauth_skew.jsoncCst||_|pd|_||_||_||_d|_d|_|j|j|jf}t|�sNd|_nt|�s^t	d��|�
�}|pli|_dS)Nr!Tr�FzBall or none of token_key, token_secret, or consumer_key can be set)�consumer_key�consumer_secret�	token_key�token_secret�skew_data_file�	_do_oauth�skew_change_limit�any�allrd�read_skew_file�	skew_data)rkr�rrr�rZrequired�oldr$r$r%rl�s 
�zOauthUrlHelper.__init__cCsn|jrjtj�|j�rjt�d|j����>t|jdd��$}t�|�W5QR�W5QR�SQRXW5QRXdS)NzReading �r��mode)	r�osr+�isfiler�Timed�open�json�load)rk�fpr$r$r%r�s�2zOauthUrlHelper.read_skew_filec
Csr|js
dS|��}|dkri}|||<t�d|j����0t|jdd��}|�t�|��W5QRXW5QRXdS)NzWriting �wr)rrrrrrTr�dumps)rkrK�valueZcurrr$r$r%�update_skew_files�zOauthUrlHelper.update_skew_filec
Cs�t|t�r|jdks"|jdks"dSd|jkr>t�d|j�dS|jd}zt�t|��}Wn6t	k
r�}zt�d||�WY�dSd}~XYnXt
|t���}t|j�j
}|j�|d�}t||�|jkr�|�||�t�d||�||j|<dS)Ni�i��datez$Missing header 'date' in %s responsez#Failed to convert datetime '%s': %srz$Setting oauth clockskew for %s to %d)r9rr?rGr<r=r�r�rr�r�rr#�netlocrr7�absrr)rkr�rZremote_timerWZskewrKZold_skewr$r$r%r�s0���


zOauthUrlHelper.exception_cbcCsZ|js
iSd}t|�j}|jr>||jkr>tt���|j|}t||j|j|j	|j
|d�S)N)r#r�rrr��	timestamp)rrrrr�r��
oauth_headersr�rrr�)rkr#rrKr$r$r%r�*s
�zOauthUrlHelper.headers_cbcCs6t|j|�d��|d<t|j|�d��|d<|||�S)Nr�r�)r�_headers_cbr7�
_exception_cb)rkZwrapped_funcrorDr$r$r%�_wrapped<s��zOauthUrlHelper._wrappedcOs|�t||�Sri)rr�rnr$r$r%r�EszOauthUrlHelper.wait_for_urlcOs|�t||�Sri)rrernr$r$r%reHszOauthUrlHelper.readurlc	Cs&d}z|r||�}W5|�|�X|S)NTr�)rkZextra_exception_cbr�Zretr$r$r%rKszOauthUrlHelper._exception_cbcCs$i}|r||�}|�|�|��|Sri)r�r�)rkZextra_headers_cbr#rGr$r$r%rTs
zOauthUrlHelper._headers_cb)NNNNr�)
rtrurvrlrrr�r�rr�rerrr$r$r$r%r��s�

		r�c
Cs|zddlm}Wn,tk
r<}ztd�|�W5d}~XYnX|rLt|�}nd}|j|||||j|d�}|�|�\}	}
}|
S)Nrzoauth support is not available)Z
client_secretZresource_owner_keyZresource_owner_secretZsignature_methodr)Zoauthlib.oauth1�oauth1�ImportError�NotImplementedErrorr)ZClientZSIGNATURE_PLAINTEXTZsign)r#r�rrr�rr rWZclientZ_uriZsigned_headersZ_bodyr$r$r%r\s"
�r)rA)N)r�r�)N)Mr�r4rPrZloggingr
r�r�Zconcurrent.futuresrrrZemail.utilsr�	functoolsrZhttp.clientr�	itertoolsrZsslr	�typingr
rrr
rrrrrZurllib.parserrrrr�rZ	cloudinitrrrZ	getLoggerrtr<rr�r�r&r.r�r@r)r��dictrYr_rfrgrZrBr`r]rr�r�r�rer�r�r�r�rRr�r�rr$r$r$r%�<module>s�,

�1%��%�
�6�
��
�S���