� ��^i� � � � d Z ddlZddlZddlZddlZddlmZmZmZ ddl m Z mZ ddlm Z ddlmZ ddlmZ ddlmZ dd lmZ dd lmZ ddlmZmZmZ ddlmZmZmZ ej e!� � Z"d edee# fd�Z$d edede%dee& fd�Z'de%de%fd�Z(de%de%de%fd�Z)d edede%fd�Z*dededefd�Z+ G d� d� � Z, G d� d� � Z-dS )z)Download files with progress indicators. � N)�Iterable�Optional�Tuple)�CONTENT_CHUNK_SIZE�Response)�DownloadProgressProvider)�NetworkConnectionError)�PyPI)�Link)� is_from_cache)� PipSession)�HEADERS�raise_for_status�response_chunks)�format_size�redact_auth_from_url�splitext�resp�returnc �t � t | j d � � S # t t t f$ r Y d S w xY w)Nzcontent-length)�int�headers� ValueError�KeyError� TypeError)r s ��/builddir/build/BUILDROOT/alt-python311-pip-21.3.1-4.el8.x86_64/opt/alt/python311/lib/python3.11/site-packages/pip/_internal/network/download.py�_get_http_response_sizer sF � ���4�<� 0�1�2�2�2����)�,� � � ��t�t����s � �7�7�link�progress_barc �Z � t | � � }|j t j k r|j }n|j }t |� � }|r#d� |t |� � � � }t | � � rt � d|� � nt � d|� � t � � � t j k rd}n"t | � � rd}n|sd}n|dk rd}nd}t | t � � }|s|S t# ||�� � |� � S )Nz{} ({})zUsing cached %szDownloading %sFTi@� )�max)r �netlocr �file_storage_domain�show_url�url_without_fragmentr �formatr r �logger�info�getEffectiveLevel�logging�INFOr r r )r r r �total_length�url� logged_url� show_progress�chunkss r �_prepare_downloadr1 s: � � +�4�0�0�L��{�d�.�.�.��m����'��%�c�*�*�J�� M��%�%�j�+�l�2K�2K�L�L� ��T��� 2����%�z�2�2�2�2����$�j�1�1�1� ���!�!�G�L�0�0�� � � �t� � � �� � � � �� � � �� #� #�� � �� � �T�#5� 6� 6�F�� �� �C�#�L�l�C�C�C�F�K�K�K� �filenamec �@ � t j � | � � S )zJ Sanitize the "filename" value from a Content-Disposition header. )�os�path�basename)r3 s r �sanitize_content_filenamer8 G s � � �7���H�%�%�%r2 �content_disposition�default_filenamec � � t j | � � \ }}|� d� � }|rt |� � }|p|S )z� Parse the "filename" value from a Content-Disposition header, and return the default filename if the result is empty. r3 )�cgi�parse_header�getr8 )r9 r: �_type�paramsr3 s r �parse_content_dispositionrA N sM � � �$�%8�9�9�M�E�6��z�z�*�%�%�H�� 7� -�X�6�6���'�'�'r2 c � � |j }| j � d� � }|rt ||� � }t |� � d }|s4t j | j � dd� � � � }|r||z }|sA|j | j k r1t j � | j � � d }|r||z }|S )zoGet an ideal filename from the given HTTP response, falling back to the link filename if not provided. zcontent-disposition� zcontent-type� ) r3 r r> rA r � mimetypes�guess_extensionr- r5 r6 )r r r3 r9 �exts r �_get_http_response_filenamerH \ s� � � �}�H��,�*�*�+@�A�A��� L�,�-@�(�K�K��!�(�+�+�A�.�C�� ��'���(8�(8���(L�(L�M�M��� ���O�H�� �4�8�t�x�'�'��g���t�x�(�(��+��� ���O�H��Or2 �sessionc � � |j � dd� � d }| � |t d�� � }t |� � |S )N�#rC r T)r �stream)r- �splitr> r r )rI r � target_urlr s r �_http_get_downloadrO q sF � ������Q�'�'��*�J��;�;�z�7�4�;�@�@�D��T�����Kr2 c �F � e Zd Zdededdfd�Zdededeeef fd�ZdS ) � DownloaderrI r r Nc �" � || _ || _ d S �N��_session� _progress_bar��selfrI r s r �__init__zDownloader.__init__y � � � �� �)����r2 r �locationc � � t | j |� � }nB# t $ r5}|j �J �t � d|j j |� � � d}~ww xY wt ||� � }t j � ||� � }t ||| j � � }t |d� � 5 }|D ]} |� | � � � ddd� � n# 1 swxY w Y |j � dd� � } || fS )z.Download the file given by link into location.N�HTTP error %s while getting %s�wb�Content-TyperD �rO rU r �responser' �critical�status_coderH r5 r6 �joinr1 rV �open�writer r> )rX r r[ r �er3 �filepathr0 �content_file�chunk�content_types r �__call__zDownloader.__call__� sY � � �%�d�m�T�:�:�D�D��%� � � ��:�)�)�)��O�O�0�!�*�2H�$� � � � ����� ���� /�t�T�:�:���7�<�<��(�3�3��"�4��t�/A�B�B�� �(�D� !� !� *�\�� *� *���"�"�5�)�)�)�)� *� *� *� *� *� *� *� *� *� *� *� *���� *� *� *� *� �|�'�'���;�;����%�%s&