%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/uaclient/http/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/uaclient/http/__pycache__/__init__.cpython-312.pyc

�

�Hcf-���ddlZddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
ddlmZm
Z
ddlmZmZddlmZmZmZdZdZdZd	Zd
Zej4ej6e��Ze	ddefd
eeeffdefg�Z e	ddefd
eeeffdefdeeeffdeefg�Z!dede"fd�Z#dede
edede
efd�Z$ia%de
ede
eddfd�Z&deeeffd�Z'	d)de
jPde
ede fd�Z)d �Z*d!�Z+		d*de
jPde
ede
ede fd"�Z,de
efd#�Z-diddd$fded%e
e.d
eeefd&e
ede
ed'e"de!fd(�Z/y)+�N)�Any�Dict�List�
NamedTuple�Optional)�error�request)�ParseResult�urlparse)�defaults�
exceptions�util)z169.254.169.254�metadataz[fd00:ec2::254]zhttp://archive.ubuntu.comzhttps://esm.ubuntu.comzhttp://api.snapcraft.iozhttps://api.snapcraft.io�UnparsedHTTPResponse�code�headers�body�HTTPResponse�	json_dict�	json_list�url�returnc��	t|�}|jdvry	|jy#t$rYywxYw#t$rYywxYw)NF)�https�httpT)r�
ValueError�scheme�port)r�
parsed_urls  �8/usr/lib/python3/dist-packages/uaclient/http/__init__.py�is_service_urlr!(s\����c�]�
���� 1�1�����������������s�*�9�	6�6�	A�A�protocol�proxy�test_urlc
�x�|syt|�stj|���tj|d��}|dk(rMt|�jdk(r5	t||��}|j dk(r|Stj|���tj"||i�}tj$|�}	|j'|�|S#tj$r�tj$r�tj$r�t$r<}tjd||t|��tj|���d}~wwxYw#t(j*tj,f$rG}tjd||t/|d	t|���tj|���d}~wwxYw)
N)r#�HEAD)�methodr��https_proxyz:Error trying to use "%s" as pycurl proxy to reach "%s": %s��z:Error trying to use "%s" as urllib proxy to reach "%s": %s�reason)r!r
�ProxyInvalidUrlr	�Requestrr�_readurl_pycurl_https_in_https�PycurlRequiredError�ProxyAuthenticationFailed�PycurlCACertificatesError�	Exception�LOGr�str�ProxyNotWorkingErrorr�ProxyHandler�build_opener�open�socket�timeout�URLError�getattr)r"r#r$�req�response�e�
proxy_handler�openers        r �validate_proxyrB9s������%� ��(�(�u�5�5�
�/�/�(�6�
2�C��7��x���5�5��@�	?�5�c�u�M�H� �=�=�C���L��1�1��>�>��(�(�(�E�):�;�M�
�
!�
!�-�
0�F�
;����C�����3�-�-�	���3�3�	���3�3�	���	?��I�I�L����A��	
��1�1��>�>��	?��(
�N�N�E�N�N�+�;��	�	�H����A�x��Q��(�		
��-�-�E�:�:��;�s2�
C�;E�AE�7E�E�#F9�2AF4�4F9�
http_proxyr)c
�~�i}|r||d<|r||d<djtt��}dD]r}tjj|�}|s�%djtt
|jd��jt
t����}�ttjd|�|tjd<|tjd<|r?tj|�}tj|�}tj|�tjdd	|i�
�|ay)aW
    Globally configure pro-client to use http and https proxies.

    - sets global proxy configuration for urllib
    - sets the no_proxy environment variable for the current process
      which gets inherited for all subprocesses
    - sets module variable for use in https-in-https pycurl requests
      this is retrieved later using get_configured_web_proxy

    :param http_proxy: http proxy to be used by urllib. If None, it will
                       not be configured
    :param https_proxy: https proxy to be used by urllib. If None, it will
                        not be configured
    rr�,)�no_proxy�NO_PROXYzSetting no_proxy: %srFrGzSetting global proxy dict�extra)rHN)�join�sorted�UA_NO_PROXY_URLS�os�environ�get�set�split�unionr3�debugr	r6r7�install_opener�_global_proxy_dict)rCr)�
proxy_dictrF�env_var�proxy_valuer@rAs        r �configure_web_proxyrXns��"�J��'�
�6���)�
�7���x�x��/�0�1�H�+����j�j�n�n�W�-����x�x����)�)�#�.�/�5�5�c�:J�6K�L���H�	��I�I�$�h�/�%�B�J�J�z��%�B�J�J�z����,�,�Z�8�
��%�%�m�4�����v�&��I�I�)�'�:�1F�I�G�#��c��tS�N)rT�rYr �get_configured_web_proxyr]�s���rYr=r:c�$�	tj||��}|j�jd�}|jj�D��cic]\}}|j!�|��}}}t#|j$||��S#tj$r}|}Yd}~��d}~wtj$rN}t
j
t|j��tj||j���d}~wwxYwcc}}w)N�r:)�causer�utf-8�rrr)r	�urlopenr�	HTTPErrorr;r3�	exceptionr4r+r
�ConnectivityError�full_url�read�decoder�items�lowerrr)r=r:�respr?r�k�vrs        r �_readurl_urllibro�s���F����s�G�4���9�9�;���g�&�D�*.���);�);�)=�>���1�q�w�w�y�!�|�>�G�>��
�Y�Y��
�����?�?������>�>�F��
�
�c�!�(�(�m�$��*�*�����E�E��F��?s*�B�D�D	�B%�%D	�;A	D�D	c���t|�}t|�}|jdk(xr7tj|j
�xr|duxr|jdk(}tjd|�|S)a�
    We only want to use pycurl if all of the following are true

    - The target url scheme is https
    - The target host is not in no_proxy
    - An https_proxy is configured either via pro's config or via environment
    - The https_proxy url scheme is https

    urllib.request provides some helpful functions that we re-use here.

    This function also returns the https_proxy to use, since it is calculated
    here anyway.
    rNzShould use pycurl: %r)r�_parse_https_proxyrr	�proxy_bypass�hostnamer3rR)r)�
target_url�parsed_target_url�parsed_https_proxy�rets     r �should_use_pycurlrx�s���!��,��+�K�8��� � �G�+�	1��$�$�%6�%?�%?�@�@�	1��d�*�	1�
�%�%��0�	��I�I�%�s�+��JrYc�F�d}d}t|j�dkDr|jd}t|j�dkDr|jd}||k(r|rd|vrtj��||k(rtj|���tj
|���)Nr��407)r)r?)�len�argsr
r0r1�PycurlError)rr�authentication_error_code�ca_certificates_error_coder�msgs      r �_handle_pycurl_errorr��s����D�
�C�
�5�:�:�����z�z�!�}��
�5�:�:�����j�j��m���(�(�S�U�c�\��2�2�4�4�	
�+�	+��2�2�s�;�;��$�$�u�-�-rYc����	ddl}|j	�}|j�j
�}|dk(r|j|jd�n�|dk(r|j|jd�nn|dk(rO|j|jd�|jrA|j|j|j�ntdj|���|j|j|j!��|j#�D��cgc]\}}dj||���}}}t%|�dkDr|j|j&|�|j|j(d�|j|j*t,j.�|r|j|j0|�|rXt3|�}	|	r|	j5�nd}|j|j6|�|j|j8d�nt:j=d	�t?j@�}
|j|jB|
�i��fd
�}|j|jD|�	|jG�tQ|jS|jT��}
|
jW�jYd�}|j[�t]|
�|�
�S#t$rtj��wxYwcc}}w#|jH$r;}tK||j!�|jL|jN��Yd}~��d}~wwxYw)Nr�GETTr&�POSTz5HTTP method "{}" not supported in HTTPS-in-HTTPS modez{}: {}�z1in pycurl request function without an https proxyc����|jd�}d|vry|jdd�\}}|j�j�}|j�}|�|<y)Nz
iso-8859-1�:rz)rirP�striprk)�header_line�name_raw�	value_raw�name�valuers     �r �save_headerz3_readurl_pycurl_https_in_https.<locals>.save_header"s_���!�(�(��6���k�!��)�/�/��Q�7���)��~�~��%�%�'�����!�����
rY)rrr�rarb)/�pycurl�ImportErrorr
r/�Curl�
get_method�upper�setopt�HTTPGET�NOBODYr��data�COPYPOSTFIELDSr�format�URL�get_full_url�header_itemsr|�
HTTPHEADER�FOLLOWLOCATION�CAINFOr�SSL_CERTS_PATH�TIMEOUTrq�geturl�PROXY�	PROXYTYPEr3�warning�io�BytesIO�	WRITEDATA�HEADERFUNCTION�performrr��E_RECV_ERROR�E_SSL_CACERT_BADFILE�int�getinfo�
RESPONSE_CODE�getvalueri�closer)r=r:r)r��cr'r��val�header_str_listrv�body_outputr�r?rrrs               @r r.r.�s����
/��	���
�A��^�^�
�
#�
#�
%�F�
���	�������&�	�6�	�	�������%�	�6�	�	������d�#��8�8�
�H�H�V�*�*�C�H�H�5��C�J�J��
�
�	
��H�H�V�Z�Z��)�)�+�,�58�4D�4D�4F��'0�t�S�����c�"��O���?��a��	����"�"�O�4��H�H�V�
"�
"�D�)��H�H�V�]�]�H�3�3�4��	�������)��/��<��+=��%�%�'�4�	�	
������{�+�	����!�!�1�%����G�H��*�*�,�K��H�H�V�
�
�{�+��G���H�H�V�
"�
"�K�0�
�	�	�	���q�y�y��-�-�.�/�D����!�(�(��1�D��G�G�I��
��
����c�/��,�,�.�.�/��4��T�<�<�
��
�� � �"�&,�&9�&9�'-�'B�'B�		
�	
��
�s)�L�$L&�L,�L#�,M6�;1M1�1M6c�j�|s#tj�jd�}|rt|�SdS)Nr)r	�
getproxiesrNrr(s r rqrqDs0����(�(�*�.�.�w�7��$/�8�K� �9�T�9rYTr�r'�log_response_bodyc
�\�|r|sd}tj||||��}djt|�D�cgc]}dj	|||���c}�}t
j
dj	|xsd|||r|jd�nd��t�jd�}	t|	|�rt|||	�	�}
n
t||�
�}
i}g}d|
jjdd
�vrTtj|
j t"j$��}
t'|
t(�r|
}nt'|
t*�r|
}djt|
j�D�cgc]!}dj	||
j|���#c}�}dj	|xsd||�}|r)|
j }|r|}n|r|}|dj	|�z
}t
j
|�t-|
j.|
j|
j ||��Scc}wcc}w)Nr�)r�rr'z, z
'{}': '{}'z'URL [{}]: {}, headers: {{{}}}, data: {}r�rar)r:r)r_zapplication/jsonzcontent-type�)�clsz&URL [{}] response: {}, headers: {{{}}}z
, data: {})rrrrr)r	r-rIrJr�r3rRrir]rNrxr.ror�json�loadsrr�DatetimeAwareJSONDecoder�
isinstance�dict�listrr)rr�rr'r:r�r=rm�sorted_header_strr)rlrr�	json_body�	debug_msg�body_to_logs                r �readurlr�Js����F���
�/�/�#�D�'�&�
I�C��	�	�5;�G�_�E���	�	�Q���
�	+�E����I�I�1�8�8��O�e���$(�D�K�K�� �d�		
��+�,�0�0��9�K���c�*�-���k�
���s�G�4���I��I��T�\�\�-�-�n�b�A�A��J�J�t�y�y�d�.K�.K�L�	��i��&�!�I�
�	�4�
(�!�I��	�	�:@����:N�O�Q��	�	�Q����Q��	0�O���9�?�?���%��/��I���i�i���#�K�
�#�K��\�(�(��5�5�	��I�I�i���
�Y�Y����
�Y�Y������Y	F��:	Ps�H$�2&H)r[)NN)0r�r��loggingrLr9�typingrrrrr�urllibrr	�urllib.parser
r�uaclientrr
rrK�PROXY_VALIDATION_APT_HTTP_URL�PROXY_VALIDATION_APT_HTTPS_URL�PROXY_VALIDATION_SNAP_HTTP_URL�PROXY_VALIDATION_SNAP_HTTPS_URL�	getLogger�replace_top_level_logger_name�__name__r3r�r4rr�boolr!rBrTrXr]r-rorxr�r.rq�bytesr�r\rYr �<module>r�sZ��	���	�
�8�8�!�.�/�/�E�� ;��!9��!:��"<���g���:��:�:�8�D�E��!��	��
�	�D��c��N�#�	��
������	��
�	�D��c��N�#�	��
�	�d�3��8�n�%�	�d�3�i� ��	�������"/;��/;�"�3�-�/;�36�/;�
�c�]�/;�d��.$���
�.$�,4�S�M�.$�	�.$�b�$�s�C�x�.��
48��	����#+�C�=����.�4.�&"�!%�\�	���\�
�c�]�\��#��\��	\�~:�x��'<�:�!� � �!�"�
?�	�?�
�5�/�?��#�s�(�^�?�
�S�M�	?�
�c�]�?��
?��?rY

Zerion Mini Shell 1.0