%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/landscape/lib/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/landscape/lib/__pycache__/fetch.cpython-312.pyc

�

�~�e����ddlZddlZddlZddlmZddlmZddlmZddl	m
Z
ddl	mZGd�de�Z
Gd	�d
e
�ZGd�de
�Zd
diddddd
dddfd�Zd�Zdd�Zdd�Zdd�Zd�Zedk(reej.dd�yy)�N)�OptionParser)�DeferredList)�
deferToThread)�	iteritems)�
networkStringc��eZdZy)�
FetchErrorN)�__name__�
__module__�__qualname__���5/usr/lib/python3/dist-packages/landscape/lib/fetch.pyr	r	s��rr	c��eZdZd�Zd�Zd�Zy)�
HTTPCodeErrorc� �||_||_y�N)�	http_code�body)�selfrrs   r�__init__zHTTPCodeError.__init__s��"�����	rc�"�d|jd��S)NzServer returned HTTP code �d�r�rs r�__str__zHTTPCodeError.__str__s��+�D�N�N�1�+=�>�>rc�$�d|jd�d�S)Nz<HTTPCodeError http_code=r�>rrs r�__repr__zHTTPCodeError.__repr__s��*�4�>�>�!�*<�A�>�>rN)r
rrrrrr
rrrrs���?�?rrc�.�eZdZd�Zd�Zd�Zed��Zy)�PyCurlErrorc� �||_||_yr)�
error_code�_message)rr#�messages   rrzPyCurlError.__init__s��$�����
rc�<�d|jd�d|j��S)NzError r�: �r#r%rs rrzPyCurlError.__str__!s �������*�"�T�\�\�N�;�;rc�>�d|jd�d|j�d�S)Nz<PyCurlError args=(rz, 'z')>r(rs rrzPyCurlError.__repr__$s"��$�T�_�_�Q�$7�s�4�<�<�.��L�Lrc��|jSr)r$rs rr%zPyCurlError.message's���}�}�rN)r
rrrrr�propertyr%r
rrr!r!s&�� �<�M����rr!F��iXTc
��ddl}t|t�s|jd�}t	j
|�}
t	j
�}|�|j
�}|j|jtt|���|ri|j|jd�|rK|j|jt|��|j|j|
j�|r6|j!d�r%|j|j"t|��|rF|j|j$t't)|��D��cgc]\}}|�d|����c}}�|r|j|j*d�|	r|j|j,d�|
�%|j|j.t|
��|�%|j|j0t|��|j|j2d	�|j|j4|�|j|j6d�|j|j8|�|j|j:d�|j|j<|j>�|j|j@d�|j|jBd
�	|jE�|jM�}|jO|jP�}|dk7rtS||��|Scc}}w#|jF$r+}tI|jJd|jJd��d}~wwxYw)aCRetrieve a URL and return the content.

    @param url: The url to be fetched.
    @param post: If true, the POST method will be used (defaults to GET).
    @param data: Data to be sent to the server as the POST content.
    @param headers: Dictionary of header => value entries to be used on the
        request.
    @param curl: A pycurl.Curl instance to use. If not provided, one will be
        created.
    @param cainfo: Path to the file with CA certificates.
    @param insecure: If true, perform curl using insecure option which will
        not attempt to verify authenticity of the peer's certificate. (Used
        during autodiscovery)
    @param follow: If True, follow HTTP redirects (default True).
    @param user_agent: The user-agent to set in the request.
    @param proxy: The proxy url to use for the request.
    rNzutf-8Tzhttps:r'F��sgzip,deflate��)*�pycurl�
isinstance�bytes�encode�io�BytesIO�Curl�setopt�URLr�str�POST�
POSTFIELDSIZE�len�READFUNCTION�read�
startswith�CAINFO�
HTTPHEADER�sortedr�SSL_VERIFYPEER�FOLLOWLOCATION�	USERAGENT�PROXY�	MAXREDIRS�CONNECTTIMEOUT�LOW_SPEED_LIMIT�LOW_SPEED_TIME�NOSIGNAL�
WRITEFUNCTION�write�DNS_CACHE_TIMEOUT�ENCODING�perform�errorr!�args�getvalue�getinfo�	HTTP_CODEr)�url�post�data�headers�cainfo�curl�connect_timeout�
total_timeout�insecure�follow�
user_agent�proxyr2�output�input�key�value�errs                    r�fetchri,s���>��d�E�"��{�{�7�#��
�Z�Z��
�F��J�J�L�E��|��{�{�}��	�K�K��
�
�M�#�c�(�3�4�����F�K�K��&���K�K��,�,�c�$�i�8��K�K��+�+�V�[�[�9�
�#�.�.��*����F�M�M�=��#8�9��������39�)�G�:L�3M�N�<�C���u�B�u�g�
�N�	
�
����F�)�)�5�1�
����F�)�)�1�-������F�$�$�m�J�&?�@������F�L�L�-��"6�7��K�K�� � �!�$��K�K��%�%��7��K�K��&�&��*��K�K��%�%�}�5��K�K�����#��K�K��$�$�e�k�k�2��K�K��(�(�!�,��K�K�����1�0������>�>��D����V�-�-�.�I��C���I�t�,�,��K��G
O��4�<�<�0��!�&�&��)�Q�V�V�A�Y�/�/��0�s�!L=�/M�M=�&M8�8M=c�(�ttg|��i|��S)z]Retrieve a URL asynchronously.

    @return: A C{Deferred} resulting in the URL content.
    )rri)rT�kwargss  r�fetch_asyncrl�s��
��0��0��0�0rc��g}|D]G}t|fi|��}|r|j||�|r|j||�|j|��It	|dd��S)a9
    Retrieve a list of URLs asynchronously.

    @param callback: Optionally, a function that will be fired one time for
        each successful URL, and will be passed its content and the URL itself.
    @param errback: Optionally, a function that will be fired one time for each
        failing URL, and will be passed the failure and the URL itself.
    @return: A C{DeferredList} whose callback chain will be fired as soon as
        all downloads have terminated. If an error occurs, the errback chain
        of the C{DeferredList} will be fired immediatly.
    T)�fireOnOneErrback�
consumeErrors)rl�addCallback�
addErrback�appendr)�urls�callback�errbackrk�resultsrX�results       r�fetch_many_asyncrx�sj���G�����S�+�F�+������x��-�����g�s�+����v��
���$�d�K�Krc��|jd�jd�d}|� tjj	||�}|S)z�Return the last component of the given C{url}.

    @param url: The URL to get the filename from.
    @param directory: Optionally a path to prepend to the returned filename.

    @note: Any trailing slash in the C{url} will be removed
    �/���)�rstrip�split�os�path�join)rX�	directory�filenames   r�url_to_filenamer��s@���z�z�#��$�$�S�)�"�-�H����7�7�<�<�	�8�4���Orc�8����fd�}�fd�}t|f||d�|��S)aJ
    Retrieve a list of URLs and save their content as files in a directory.

    @param urls: The list URLs to fetch.
    @param directory: The directory to save the files to, the name of the file
        will equal the last fragment of the URL.
    @param logger: Optional function to be used to log errors for failed URLs.
    c�z��t|���}t|d�}|j|�|j�y)N)r��wb)r��openrO�close)rZrXr��fdr�s    �rrOzfetch_to_files.<locals>.write�s/���"�3�)�<��
�(�D�
!��
�����
���
rc�b���r+�dj|t|j���|S)Nz Couldn't fetch file from {} ({}))�formatr;rg)�failurerX�loggers  �r�	log_errorz!fetch_to_files.<locals>.log_error�s2�����2�9�9����
�
�&��
��r)rtru)rx)rsr�r�rkrOr�s ``   r�fetch_to_filesr��s&������D�N�5�)�N�v�N�Nrc��t�}|jdd��|jdd��|jd�|j|�\}\}tt	||j
|j|j���y)	Nz--post�
store_true)�actionz--datar,)�defaultz--cainfo)rYrZr\)r�
add_option�
parse_args�printrirYrZr\)rT�parser�optionsrXs    r�testr��s{��
�^�F�
���h�|��4�
���h���+�
���j�!��'�'��-�O�G�V�c�	�
���������>�>�		
�r�__main__r/)NNr)r6r~�sys�optparser�twisted.internet.deferr�twisted.internet.threadsr�twisted.python.compatrr�	Exceptionr	rr!rirlrxr�r�r�r
�argvr
rr�<module>r�s���	�	�
�!�/�2�+�/�	��	�	?�J�	?�
�*�
�$
�	���	
���
���
�]�@1�L�.�O�:
� �z������!�"���r

Zerion Mini Shell 1.0