Current File : //lib/python3.9/site-packages/pip/_internal/network/__pycache__/download.cpython-39.pyc
a

[��f��@sTdZddlZddlZddlZddlZddlmZmZmZddl	m
Z
mZddlm
Z
ddlmZddlmZddlmZdd	lmZdd
lmZddlmZmZmZddlmZmZmZe� e!�Z"eee#d
�dd�Z$eee%ee&d�dd�Z'e%e%d�dd�Z(e%e%e%d�dd�Z)eee%d�dd�Z*eeed�dd�Z+Gdd �d �Z,Gd!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
Cs0zt|jd�WStttfy*YdS0dS)Nzcontent-length)�int�headers�
ValueError�KeyError�	TypeError)r�r�B/usr/lib/python3.9/site-packages/pip/_internal/network/download.py�_get_http_response_sizesr)r�link�progress_barrcCs�t|�}|jtjkr|j}n|j}t|�}|r>d�|t|��}t	|�rTt
�d|�nt
�d|�t
��t
jkrtd}n*t	|�r�d}n|s�d}n|dkr�d}nd}t|t�}|s�|St||d�|�S)Nz{} ({})zUsing cached %szDownloading %sFTi@�)�max)r�netlocr	Zfile_storage_domainZshow_urlZurl_without_fragmentr�formatrr�logger�infoZgetEffectiveLevel�logging�INFOrrr)rrrZtotal_length�urlZ
logged_urlZ
show_progress�chunksrrr�_prepare_downloads.
r()�filenamercCstj�|�S)zJ
    Sanitize the "filename" value from a Content-Disposition header.
    )�os�path�basename)r)rrr�sanitize_content_filenameGsr-)�content_disposition�default_filenamercCs,t�|�\}}|�d�}|r$t|�}|p*|S)z�
    Parse the "filename" value from a Content-Disposition header, and
    return the default filename if the result is empty.
    r))�cgiZparse_header�getr-)r.r/Z_type�paramsr)rrr�parse_content_dispositionNs

r3)rrrcCs�|j}|j�d�}|r t||�}t|�d}|sPt�|j�dd��}|rP||7}|s~|j|jkr~tj	�|j�d}|r~||7}|S)zoGet an ideal filename from the given HTTP response, falling back to
    the link filename if not provided.
    zcontent-disposition�zcontent-type�)
r)rr1r3r�	mimetypesZguess_extensionr&r*r+)rrr)r.�extrrr�_get_http_response_filename\s
r8)�sessionrrcCs.|j�dd�d}|j|tdd�}t|�|S)N�#r4rT)r�stream)r&�splitr1r
r)r9rZ
target_urlrrrr�_http_get_downloadqsr=c@s8eZdZeedd�dd�Zeeeeefd�dd�ZdS)�
DownloaderN�r9rrcCs||_||_dS�N��_session�
_progress_bar��selfr9rrrr�__init__yszDownloader.__init__)r�locationrc
Cs�zt|j|�}WnFtyV}z.|jdus.J�t�d|jj|��WYd}~n
d}~00t||�}tj	�
||�}t|||j�}t
|d��$}|D]}	|�|	�q�Wd�n1s�0Y|j�dd�}
||
fS)z.Download the file given by link into location.N�HTTP error %s while getting %s�wb�Content-Typer5�r=rBrZresponser"ZcriticalZstatus_coder8r*r+�joinr(rC�open�writerr1)rErrGr�er)�filepathr'�content_file�chunk�content_typerrr�__call__�s 
�
*zDownloader.__call__)	�__name__�
__module__�__qualname__r�strrFr
rrTrrrrr>xs
�r>c@sHeZdZeedd�dd�Zeeeeeeeeeffd�dd�Z	dS)�BatchDownloaderNr?cCs||_||_dSr@rArDrrrrF�szBatchDownloader.__init__)�linksrGrccs�|D]�}zt|j|�}WnFty^}z.|jdus6J�t�d|jj|��WYd}~n
d}~00t||�}tj	�
||�}t|||j�}t
|d��$}	|D]}
|	�|
�q�Wd�n1s�0Y|j�dd�}|||ffVqdS)z0Download the files given by links into location.NrHrIrJr5rK)rErZrGrrrOr)rPr'rQrRrSrrrrT�s&�
*zBatchDownloader.__call__)
rUrVrWrrXrFrr
rrTrrrrrY�s�	�rY).�__doc__r0r$r6r*�typingrrrZpip._vendor.requests.modelsrrZpip._internal.cli.progress_barsrZpip._internal.exceptionsrZpip._internal.models.indexr	Zpip._internal.models.linkr
Zpip._internal.network.cacherZpip._internal.network.sessionrZpip._internal.network.utilsr
rrZpip._internal.utils.miscrrrZ	getLoggerrUr"rrrX�bytesr(r-r3r8r=r>rYrrrr�<module>s6
�)