%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/cloudinit/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/cloudinit/__pycache__/url_helper.cpython-312.pyc

�

���fO���>�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZddlm
Z
ddlmZddlmZddlmZddlmZddlmZmZmZmZmZmZmZdd	lmZm Z m!Z!m"Z"ddl#Z#dd
l#m$Z$ddl%m&Z&m'Z'ejPe)�Z*dZ+d
�Z,d�Z-de.fd�Z/d@de0de1de2ddfd�Z3de0ddfd�Z4dedfd�Z5Gd�d�Z6Gd�de6�Z7Gd�de6�Z8Gd�d �Z9Gd!�d"e:�Z;d#�Z<																dAd&e=de9fd'�Z>	dBd(ed)efd*e0de.d+ej~d,ee1defd-�Z@		dCd(ed)efd/ee0d0e1de.def
d1�ZAe1d2�de*j�dddddd%d$d.fd3e1dee1d4ed5eed6ee1d7eed8eeee1ge1fd9e0d:e=d;e1fd<�ZCGd=�d>�ZD	dBd?�ZEy)D�N)�ThreadPoolExecutor�TimeoutError�as_completed)�	parsedate)�partial)�	NOT_FOUND)�count)�create_default_context)�Any�Callable�Iterator�List�Optional�Tuple�Union)�quote�urlparse�urlsplit�
urlunparse)�
exceptions)�util�version�REDACTEDc�r�tt|d���}|ds|dr
|d|d<d|d<t|�S)N�http)�scheme���)�listrr)�url�
parsed_urls  �6/usr/lib/python3/dist-packages/cloudinit/url_helper.py�	_cleanurlr$&sC���h�s�6�2�3�J��a�=�Z��]�#�1�
�
�1�
��
�1�
��j�!�!�c�0�d�}|}|D]}|||�}�
|S)Nc��tt|��}|d}|r|jd�s|dz
}|tt	|�d��z
}||d<t|�S)Nr�/z/:)�safe)r r�endswithr�strr)r!�add_on�
url_parsed�paths    r#�combine_singlez#combine_url.<locals>.combine_single1sY���(�3�-�(�
��!�}����
�
�c�*��C�K�D���c�&�k��-�-���
�1�
��*�%�%r%�)�base�add_onsr/r!r,s     r#�combine_urlr30s.��&��C��*���S�&�)��*��Jr%�returnc
�8�tjdtjdtjdtjdt
di}|j
t|��}|s5t|t�r|j}|Stjd�d}|S)z4helper for read_ftps to map return codes to a number�,���iXi�z9Unexpected exception type while connecting to ftp server.i����)
�ftplib�error_reply�
error_temp�
error_perm�error_proto�EOFError�get�type�
isinstance�OSError�errno�LOG�warning)�exc�ftp_error_codes�codes   r#�"ftp_get_return_code_from_exceptionrI@s���	���C����3����3����C��#��O����t�C�y�)�D���c�7�#��9�9�D��K�	
�K�K�K�
��D��Kr%r!�timeout�kwargs�FtpResponsec	�L�t|�}|jstdtd|���t	j
�5}|jxsd}|jxsd}d|jk(�rH	tjt���}tjd||�|j|j||xsd	�
�tjd|�	|j#||j$xsd��tjd�|j'�	tjd|j,�|j/d|j,��|j0��t3|j5�|�tjd�|j7�cddd�S	tj8�}
tjd||�|
j|j||xsd	�
�tjd|�|
j#||j$xsd��tjd|j,�|
j/d|j,��|j0��t3|j5�|�tjd�|
j7�cddd�S#tj$r'}t!|�}	td|�d|	�d
�|	d|��|�d}~wwxYw#tj($r*}tj+d�tddd|��|�d}~wwxYw#tj$r'}t!|�}	td|�d|	�d
�|	d|��|�d}~wwxYw#tjd�|j7�wxYw#tj$r'}t!|�}	td|�d|	�d
�|	d|��|�d}~wwxYw#tjd�
j7�wxYw#1swYyxYw)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��causerH�headersr!��	anonymous�ftps)�contextz3Attempting to connect to %s via port [%s] over tls.�@)�host�portrJz1Reading file from server over tls failed for url z [�]z"Attempting to login with user [%s]r)�user�passwdzCreating 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.r8zReading file: %szRETR )�callbackzClosing connectionz,Reading file from ftp server failed for url z(Attempting to connect to %s via port %s.)r�hostname�UrlErrorr�io�BytesIOrW�usernamerr9�FTP_TLSr
rD�debug�connect�
all_errorsrI�login�password�prot_pr<rEr.�
retrbinary�writerL�getvalue�close�FTP)r!rJrK�	url_parts�bufferrWrY�ftp_tls�erH�ftps           r#�	read_ftpsrrWs�� ��
�I�����(�y�$�C�
�	
�
����j���~�~�#����!�!�0�[���Y�%�%�%�
� �.�.�2�4����	�	�I����
���"�+�+��#�N�s� �� 
�I�I�:�D�A�
��
�
��$�-�-�3�����	�	�8�9���� �"
 ��	�	�,�i�n�n�=��"�"��I�N�N�+�,�v�|�|�#��#�6�?�?�#4�c�:��	�	�.�/��
�
��Sj�j�V
��j�j�l���	�	�>��T�����"�+�+��#�N�s���
�	�	�>��E��	�	��$�-�-�3�����	�	�,�i�n�n�=�����y�~�~�&6�7�&�,�,��O�"�6�?�?�#4�c�:��	�	�.�/��	�	��Uj�j��$�$�$�

�9�!�<���*�*-��b���a�9�� ������

��&�$�$�
����C��
�N�� ��	��	��

��.�$�$�

�9�!�<���+�+.�%�r�$��q�:�� ������

���	�	�.�/��
�
���(�$�$�

�9�!�<���+�+.�%�r�$��q�:�� ������

���	�	�.�/��	�	���Uj�j�s��1P�1AK�P�AL�&A#M�	%P�9C'N3� %P�L	�""L�L	�	P�M	�%M�M	�	P�N�"N�N�N	�	'N0�0P�3O-�"O(�(O-�-O0�0'P�P�P#r.�FileResponsec�*�|jd�rtjd|�	tj|�}t||�S#t$r}t|td|��|�d}~wt$r}t||jd|��|�d}~wwxYw)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 %sNrN)r?rDrEr�load_binary_filers�FileNotFoundErrorr]r�IOErrorrC)r.rK�contentsrps    r#�
_read_filerz�s���
�z�z�&�����=�t�D�M��(�(��.���H�d�+�+���O��Q�Y��$�G�Q�N���M��Q�Q�W�W�d��E�1�L��M�s#� A
�
	B�A'�'B�3B
�
B)rs�UrlResponserLc�^�|j�}	t|�}|j}|dk(s
|rd|dk(rt|jfi|��S|dvrt|fi|��S|dvrt|fi|��Stjd|�t|fi|��S#t$r}t||��|�d}~wwxYw)	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.
    )rOr!N�filer(r)rqrS)r�httpszAttempting unknown protocol %s)�lstripr�
ValueErrorr]rrzr.rr�readurlrDrE)r!rK�parsedrprs     r#�read_file_or_urlr��s����*�*�,�C�0��#����]�]�F�
���C�C�3�q�6�M��&�+�+�0��0�0�	�?�	"���'��'�'�	�$�	$��s�%�f�%�%����4�f�=��s�%�f�%�%���0��Q�C�(�a�/��0�s�B�	B,�B'�'B,c� �eZdZdd�Zd�Zd�Zy)�StringResponsec�<�||_i|_||_||_y�N)rHrPryr!)�selfryr!rHs    r#�__init__zStringResponse.__init__s����	���� ��
���r%c�$�|jdk7ryy)N��FT�rH�r��argsrKs   r#�okzStringResponse.oks���9�9����r%c�8�|jjd�S)Nzutf-8)ry�decode�r�s r#�__str__zStringResponse.__str__s���}�}�#�#�G�,�,r%N�r�)�__name__�
__module__�__qualname__r�r�r�r0r%r#r�r�s����
-r%r�c�*��eZdZddedef�fd�
Z�xZS)rsryr!c�*��t�|�|||��y)Nr���superr�)r�ryr!rH�	__class__s    �r#r�zFileResponse.__init__s���
����3�T��2r%r��r�r�r��bytesr+r��
__classcell__�r�s@r#rsrss���3��3�S�3�3r%c�(��eZdZdedef�fd�Z�xZS)rLryr!c�&��t�|�||�yr�r�)r�ryr!r�s   �r#r�zFtpResponse.__init__s���
����3�'r%r�r�s@r#rLrLs���(��(�S�(�(r%c��eZdZdejfd�Zedefd��Zede	fd��Z
ddefd�Zed��Z
edefd��Zd	�Z	dd
eededeefd�Zy
)r{�responsec��||_yr�)�	_response)r�r�s  r#r�zUrlResponse.__init__"s	��!��r%r4c�\�|jj�y|jjS)Nr%)r��contentr�s r#ryzUrlResponse.contents%s%���>�>�!�!�)���~�~�%�%�%r%c�.�|jjSr�)r�r!r�s r#r!zUrlResponse.url+s���~�~�!�!�!r%c�@�d}|rd}d|jcxkr|kryyy)Nr6r7r�TFr�)r��redirects_ok�uppers   r#r�zUrlResponse.ok/s-������E��$�)�)�#�e�#��$�r%c�.�|jjSr�)r�rPr�s r#rPzUrlResponse.headers8s���~�~�%�%�%r%c�.�|jjSr�)r��status_coder�s r#rHzUrlResponse.code<s���~�~�)�)�)r%c�.�|jjSr�)r��textr�s r#r�zUrlResponse.__str__@s���~�~�"�"�"r%�
chunk_size�decode_unicodec#�XK�|jj||�Ed{���y7��w)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)r�r�r�s   r#r�zUrlResponse.iter_contentCs"�����>�>�.�.�z�>�J�J�J�s� *�(�*N)F)rF)r�r�r��requests�Responser��propertyr�ryr+r!�boolr�rP�intrHr�rr
r�r0r%r#r{r{!s���"��!2�!2�"��&�%�&��&�
�"�S�"��"�����&��&��*�c�*��*�#�EJ�K�"�3�-�K�=A�K�	�%��Kr%r{c��eZdZdd�Zy)r]Nc��tj|t|��||_||_||_|j
�i|_||_yr�)rxr�r+rOrHrPr!)r�rOrHrPr!s     r#r�zUrlError.__init__SsC������s�5�z�*���
���	�����<�<���D�L���r%)NNN)r�r�r�r�r0r%r#r]r]Rs��r%r]c���i}t|�j}|dk(rE|rCd|vr|dr	|d|d<nd|d<d|vrd|vr|d|dg|d<|Sd|vrt|d�|d<|S)Nr~�ca_certs�verifyT�	cert_file�key_file�cert)rrr+)r!�ssl_details�ssl_argsrs    r#�
_get_ssl_argsr�]s����H�
�c�]�
!�
!�F�
���[���$��Z�)@�!,�Z�!8�H�X��!%�H�X���+�%�*��*C��K�(��J�'� �H�V���O��K�
'�"�;�{�#;�<�H�V���Or%Tr�streamc	�z�t|�}||d�}|jt||��|
|d<|s|rdnd}||d<|�.t|t�r||d<ntt
|�d�|d<|�g}d	}|rtt|�d	zd	�}d
tj�z}|�|j�}ni}|r||d<|�d}|�tj�}t�D�]}|r||�}d
|vr||d
<||d<i}|j�D]g\}}|dk(r�|dk(rR|rP|D�cgc]}|j|�s�|��}}|s�7tj |�|<|D]}t"|||<��c|||<�i	|rt$j'd||
rdn|||�|j(di|��}|	r|j+�t$j'd||j,t/|j0�|d	z�t3|�cStId��cc}w#t4j6$r}t9||��|�d}~wt4j:$r�}t|t4j<�rZt?|d�rNt?|j@d�r8t9||j@j,|j@jB|��}n
t9||��}|r||j�|�s||�|
xs|d	z|k}|s||�|dkDr-|rt$j'd|�tEjF|�Yd}~��Pd}~wwxYw)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 which accepts the params
        msg and exception and returns a boolean 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��allow_redirects�POST�GET�methodNrJrrz
Cloud-Init/%sru���z
User-AgentrPz'[%s/%s] open '%s' with %s configuration�infinitez(Read from %s (%s, %sb) after %s attempts)r!r�r��rHrPr!�1Please wait %s seconds while we wait to try againz"This path should be unreachable...r0)%r$�updater�rA�tuple�max�floatr�r�version_string�copyr��Sessionr	�itemsr?�deepcopyrrDrb�request�raise_for_statusr��lenr�r{r�SSLErrorr]�RequestException�	HTTPError�hasattrr�rP�time�sleep�RuntimeError)r!rurJ�retries�sec_betweenrP�
headers_cb�headers_redactr��check_statusr��exception_cb�sessionr��log_req_resp�request_methodr��req_args�manual_tries�
user_agent�i�filtered_req_args�k�v�matched_headers�key�rrp�	url_error�
will_retrys                              r#r�r�osi��h�C�.�C����H�
�O�O�M�#�{�3�4�"1�H�
���#'��U��'�H�X�����g�u�%�")�H�Y��"%�e�G�n�a�"8�H�Y�������L���3�w�<�!�+�Q�/�� �G�$:�$:�$<�=�J����,�,�.����������������"�"�$���W�R(��� ��o�G��w�&�$.�G�L�!�%�������N�N�$�
	)�D�A�q��F�{���I�~�.�.<�"I�����a��1�"I��"I�"�+/�=�=��+;�%�a�(�.�=��4<�)�!�,�S�1�=�()�!�!�$�
	)�>	(���	�	�=��"*�J���%�� ����+�(�+�A���"�"�$��I�I�:���
�
��A�I�I���Q��
��q�>�!�YR(�h�;�
<�<��O#J��@�"�"�	.��1�#�&�A�-���*�*�!	(��1�z�3�3�5��A�z�*���J�J�
��%�����/�/��J�J�.�.��	�	�%�Q�C�0�	��L�����)�$L� �Q�&�!�;�a�!�e�l�&:�J���Q�&��Q����I�I�K�#���
�
�;�'���C!	(�s2�*H�H�>BH�L:�+H9�9L:�C L5�5L:�func.�addr�event�delayc�>�|r|j|��ry|||�S)z Execute func with optional delay�rJN��wait�r�r�rJr�r�s     r#�_run_func_with_delayrs'��
�
�:�:�e�:�$����g��r%�333333�?�	addresses�
stagger_delayc
�N�d}d}d}g}tj�}tt|���}		t	|�D�
�cic]$\}
}|	jt|||||
|z��|��&}}
}t||��D]h}
||
}|
j�}|r|}|j|��/|
j�}|s�B|j�||fc|	jd��S|rtjd||�|�tjd|�t!d	��cc}}
w#t"$rFtjd
dj%|�dj%t't(|���YnwxYw	|	jd��||fS#|	jd��wxYw)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)�max_workersrr�Fr�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��	enumerate�submitrr�	exception�append�result�set�shutdownrDrE�errorr�r�join�mapr+)r�rrrJ�
return_result�returned_address�last_exceptionr�is_done�executorr�r��futures�future�return_exceptions               r#�
dual_stackr1s����M���.2�N��J��o�o��G�"�c�)�n�=�H�5&�%�Y�/�

���4�
�O�O�$������=�(�

�
��
�

��

�#�7�G�<�	=�F�&�v���%�/�/�1���!1��!�
�!�!�.�1� &�
�
��
� ��K�K�M�,�m�<�<�2	���u��%�O	=�$��K�K�-�� �	
�!� ��I�I�3�5E�F��1�2�2��S

��X�
����
4��H�H�Y���H�H�S��j�)�*�		
�
��	
�	���u��%��m�,�,��	���u��%�s>�D'�)D!�*AD'�<D'�$AD'�'AE6�3F�5E6�6F�F$�inf�max_wait�	status_cbr��
sleep_timer��
sleep_time_cbr��connect_synchronously�async_delayc�n������	�������dtdtf�fd�}ddtdtdtfd��d	����fd
�����	fd��������fd�}
����fd
�}tj�}�r
|rt	d��|
r|
n|}|xs|}d�d}	||��}|||||�}|r|\}}||j
fS��||�rn`�dz�tjd|�tj|�tj�}|r||z|�zkDr�||z
z
}|dkrn��tjd��y)a1	
    urls:      a list of urls to try
    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
    timeout:   the timeout provided to urlopen
    status_cb: call method with string message when a url is not available
    headers_cb: call method with single argument of url to get headers
                for request.
    headers_redact: a list of header names to redact from the log
    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`.
    exception_cb: call method with 2 arguments 'msg' (per status_cb) and
                  'exception', the exception that occurred.
    sleep_time_cb: call method with 2 arguments (response, loop_n) that
                   generates the next sleep time. Cannot be specified
                   along with 'sleep_time`.
    request_method: indicate the type of HTTP request, GET, PUT, or POST
    connect_synchronously: if false, enables executing requests in parallel
    async_delay: delay before parallel metadata requests, see RFC 6555
    returns: tuple of (url, response contents), on failure, (False, None)

    the idea of this routine is to wait for the EC2 metadata service to
    come up.  On both Eucalyptus and EC2 we have seen the case where
    the instance hit the MD before the MD service was up.  EC2 seems
    to have permanently fixed this, though.

    In openstack, the metadata service might be painfully slow, and
    unable to avoid hitting a timeout of even up to 10 seconds or more
    (LP: #894279) for a simple GET.

    Offset those needs with the need to not hang forever (and block boot)
    on a system where cloud-init is configured to look for EC2 Metadata
    service but is not going to find one.  It is possible that the instance
    data host (169.254.169.254) may be firewalled off Entirely for a system,
    meaning that the connection will block forever unless a timeout is set.

    The default value for max_wait will retry indefinitely.
    �loop_numberr4c������S|dzdzS)N�rr0)�_r%r s  �r#�default_sleep_timez(wait_for_url.<locals>.default_sleep_time�s���'�3�z�M���9I�A�9M�Mr%rr�
start_timer c�j�|td�dfvry|dkxstj�|z
|z|kDS)z4Check if time is up based on start time and max waitrNFr)r�r��	monotonic)rr*r s   r#�timeupzwait_for_url.<locals>.timeup�s@����e��d�+�+���A�
�
��N�N��z�)�J�6��A�	
r%c�F�|js?d|jz}tt|�|j|j|��}||fS|j�s?d|jz}tt|�|j|j|��}||fSd}d}||fS)z?Map requests response code/contents to internal "UrlError" typezempty response [%s]r�zbad status code [%s]rN)ryrHr]r�rPr�)r�r!�reason�url_excs    r#�handle_url_responsez)wait_for_url.<locals>.handle_url_response�s���� � �*�h�m�m�<�F���6�"��]�]� �(�(��	�G�"�� � �����+�x�}�}�=�F���6�"��]�]� �(�(��	�G��� � ��F��G��� � r%c�l��d}d}	||�\}}�
||�\}}|s||fS	ttj�|z
�}
�rd�znd}d|xs
t|dd��d	|
�d
|�d|��}||�|r|||��yy#t$r}	d|	z}|	}Yd}	~	�qd}	~	wt$r}	d|	z}|	}Yd}	~	��d}	~	wwxYw)
z:Execute request, handle response, optionally log exceptionrNzrequest error [%s]zunexpected error [%s]z%ss�	unlimitedz	Calling 'r!z
' failed [r(z]: )�msgr)r]�	Exceptionr�r�r,�getattr)�
url_reader_cb�urlsr*�exc_cb�log_cbr/r!r�r0rp�
time_taken�max_wait_str�
status_msgr1rs             ��r#�read_url_handle_exceptionsz0wait_for_url.<locals>.read_url_handle_exceptions�s��������
	�)�$�/�M�C��1�(�C�@�O�G�V���X��&������)�J�6�7�
�+3�u�x�'����1�7�7�E�5�1�1����	
�
�	�z���
�z�W�5�	���	�)�A�-�F��G���	�,�q�0�F��G��	�s#�B�	B3�
B�B3�"B.�.B3c�:��t|��in�|��|d���S)NF)rPr�rJr�r�)r�)r!rJr�r�r�s  ���r#�read_url_cbz!wait_for_url.<locals>.read_url_cb�s-�����$�,�B�*�S�/�)���)�

�	
r%c������
�fd�}�
D]X}tj�}�dk7r+��	|�ry�	��r|�z|�	zkDrt|�	z|z
���|||||�}|s�V|cSy)z|iterate over list of urls, request each one and handle responses
        and thrown exceptions individually per url
        c���|�|��fSr�r0)r!r@rJs ��r#�url_reader_serialz@wait_for_url.<locals>.read_url_serial.<locals>.url_reader_serials�����S�'�2�3�3r%rN)r�r,r�)r*rJr9r:rCr!�now�out�loop_nrr@r>r-r8s `      ������r#�read_url_serialz%wait_for_url.<locals>.read_url_serial	s����
	4��	�C��.�.�"�C���{��(�J�/���(���w��*�x�*?�@�"�:��#8�C�"?�@�G�,�!�3�
�F�F��C���
�#	r%c�L��tt��|��}�|�	|||�}|r|Sy)z�pass list of urls to dual_stack which sends requests in parallel
        handle response and exceptions of the first endpoint to respond
        )rrJN)rr)
r*rJr9r:�url_reader_parallelrEr#r@r>r8s
      ����r#�read_url_parallelz'wait_for_url.<locals>.read_url_parallel$sB���&���%��	
��)���z�6�6�
����J�r%z3sleep_time and sleep_time_cb are mutually exclusiveNrr�z$Timed out, no response from urls: %s)FN)r)
r�r�r�r,r�ryrDrbr�r)r8rrJrr�r�r r�r!r�r"r#r)rGrJr*�do_read_url�calculate_sleep_timer��current_sleep_timer!�address�current_timer1rFr@r>r-s``  ```  ` `           @@@@@r#�wait_for_urlrP�sf����rN�3�N�5�N�
��
�E�
�u�
�!�.6�@
���6� ���!�J��m��N�O�O�1��6G��)�>�,>���F��H�
�1�(�F�C���*�g�|�Y�G��� #��G�X��X�.�.�/�/��(�J�(:�;���!����	�	�?��	
�	
�
�
�%�&��~�~�'���|�g�-�
�X�0E�E��,��";�<�G��!�|��1�4�I�I�4�d�;�r%c�T�eZdZ					dd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zy)
�OauthUrlHelperNc�<�||_|xsd|_||_||_||_d|_d|_|j|j|jf}t|�sd|_nt|�std��|j�}|xsi|_y)NrTr'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�allr��read_skew_file�	skew_data)r�rTrVrWrUrX�required�olds        r#r�zOauthUrlHelper.__init__ds���)���.�4�"���"���(���,������!"����N�N�D�$5�$5�t�7H�7H�I���8�}�"�D�N��X���*��
�
�!�!�#������r%c���|jr_tjj|j�r6t	|jd��5}tj|�cddd�Sy#1swYyxYw)Nr���mode)rX�osr.�isfile�open�json�load)r��fps  r#r]zOauthUrlHelper.read_skew_filesX�����2�7�7�>�>�$�2E�2E�#F��d�)�)��4�
%���y�y��}�
%�
%��
%��s�
A-�-A6c���|jsy|j�}|�i}|||<t|jd��5}|jt	j
|��ddd�y#1swYyxYw)N�wrb)rXr]rfrirg�dumps)r�rV�value�curris     r#�update_skew_filezOauthUrlHelper.update_skew_file�sj���"�"���!�!�#���;��C���D�	�
�$�%�%�C�
0�	&�B��H�H�T�Z�Z��_�%�	&�	&�	&�s�%A,�,A5c���t|t�r|jdk(s|jdk(syd|jvr!tjd|j�y|jd}	t
jt|��}t|t
j�z
�}t|j�j}|jj|d�}t!||z
�|j"kDr)|j%||�tjd||�||j|<y#t$r!}tjd||�Yd}~yd}~wwxYw)Ni�i��datez$Missing header 'date' in %s responsez#Failed to convert datetime '%s': %srz$Setting oauth clockskew for %s to %d)rAr]rHrPrDrEr��mktimerr5r�rr!�netlocr^r?�absrZro)	r�r4rrq�remote_timerp�skewrV�old_skews	         r#r�zOauthUrlHelper.exception_cb�s!���y�(�+����3�&�)�.�.�C�*?����*�*�*��K�K�>�	���O��� � ��(��	��+�+�i��o�6�K�
�;�����,�-���	�
�
�&�-�-���>�>�%�%�d�A�.���x�$���$�"8�"8�8��!�!�$��-��K�K�>��d�K�#����t�����	��K�K�=�t�Q�G���	�s�/D<�<	E&�E!�!E&c�L�|jsiSd}t|�j}|jr;||jvr-t	tj
��|j|z}t
||j|j|j|j|��S)N)r!rTrVrWrU�	timestamp)rYrrsr^r�r��
oauth_headersrTrVrWrU)r�r!ryrVs    r#r�zOauthUrlHelper.headers_cb�s����~�~��I��	���}�#�#���>�>�d�d�n�n�4��D�I�I�K�(�4�>�>�$�+?�?�I����*�*��n�n��*�*� �0�0��

�	
r%c��t|j|jd��|d<t|j|jd��|d<||i|��S)Nr�r�)r�_headers_cbr?�
_exception_cb)r��wrapped_funcr�rKs    r#�_wrappedzOauthUrlHelper._wrapped�s\��&����f�j�j��6� 
��|��")�����
�
�>� :�"
��~���T�,�V�,�,r%c�0�|jt||�Sr�)rrPr�s   r#rPzOauthUrlHelper.wait_for_url�s���}�}�\�4��8�8r%c�0�|jt||�Sr�)rr�r�s   r#r�zOauthUrlHelper.readurl�s���}�}�W�d�F�3�3r%c�t�d}	|r	|||�}|j||�|S#|j||�wxYwr�)r�)r��extra_exception_cbr4r�rets     r#r}zOauthUrlHelper._exception_cb�sD����	.�!�(��i�8�����c�9�-��
��
���c�9�-�s�#�7c�^�i}|r||�}|j|j|��|Sr�)r�r�)r��extra_headers_cbr!rPs    r#r|zOauthUrlHelper._headers_cb�s.�����&�s�+�G����t���s�+�,��r%)NNNNz/run/oauth_skew.json)
r�r�r�r�r]ror�r�rrPr�r}r|r0r%r#rRrRcsE������-�
#�6�	&��8
�$-�9�4��r%rRc���	ddlm}|rt	|�}nd}|j|||||j|��}|j|�\}	}
}|
S#t$r}td�|�d}~wwxYw)Nrzoauth support is not available)�
client_secret�resource_owner_key�resource_owner_secret�signature_methodry)�oauthlib.oauth1�oauth1�ImportError�NotImplementedErrorr+�Client�SIGNATURE_PLAINTEXT�sign)r!rTrVrWrUryr�rp�client�_uri�signed_headers�_bodys            r#rzrz�s���K�(���	�N�	��	�
�]�]��%�$�*��3�3��
��F�#)�+�+�c�"2��D�.�%����#�K�!�"B�C��J��K�s�A�	A*�A%�%A*)rU)NNrrNNNNTTNNFTrFr�)r�
)Fr�r9r^rg�loggingrdrr��concurrent.futuresrrr�email.utilsr�	functoolsr�http.clientr�	itertoolsr	�sslr
�typingrrr
rrrr�urllib.parserrrrr�r�	cloudinitrr�	getLoggerr�rDrr$r3r�rIr+r��dictrrrzr�r�rsrLr{rxr]r�r�r�r	rrrbrPrRrzr0r%r#�<module>r�s����
�	���	���M�M�!��!��&�H�H�H�>�>���#��g����!����"�
� �s��.�3��������D
M�S�
M�~�
M� &�
�7�8�&�<
-�
-� 3�>�3�
(�.�(�
.K�.K�b�w���(
��
����������
����#m=�"
�#m=�$�%m=�j"��
�3��8�
��

�����?�?�	�
�E�?��	�
�*!��	P-�
�3��8�
�P-��C�y�P-��P-��	P-�
�P-�j�E�l�#��)�)�%)��"&�'+�=A��"&��\��\��e�_�\��	\�
��"�\����\��8�$�\��H�c�5�\�5�%8�9�:�\��\� �\��\�~x�x�xLP�r%

Zerion Mini Shell 1.0