HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/pip/_internal/network/__pycache__/download.cpython-310.pyc
o

��h�1�@s�dZddlmZddlZddlZddlZddlZddlm	Z	m
Z
ddlmZddl
mZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZmZddlm Z m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'm(Z(ddl)m*Z*m+Z+ddl,m-Z-m.Z.m/Z/ddl0m1Z1m2Z2m3Z3e�4e5�Z6d5dd�Z7d6dd�Z8	d7d8d%d&�Z9d9d)d*�Z:d:d-d.�Z;d;d/d0�Z<eGd1d2�d2��Z=Gd3d4�d4�Z>dS)<z(Download files with progress indicators.�)�annotationsN)�Iterable�Mapping)�	dataclass)�
HTTPStatus)�BinaryIO)�PreparedRequest)�Response)�HTTPResponse)�HTTPHeaderDict)�ReadTimeoutError)�BarType�get_download_progress_renderer)�IncompleteDownloadError�NetworkConnectionError)�PyPI)�Link)�
SafeFileCache�
is_from_cache)�CacheControlAdapter�
PipSession)�HEADERS�raise_for_status�response_chunks)�format_size�redact_auth_from_url�splitext�respr	�return�
int | Nonec
Cs,zt|jd�WStttfyYdSw)N�content-length)�int�headers�
ValueError�KeyError�	TypeError�r�r'�I/usr/local/lib/python3.10/dist-packages/pip/_internal/network/download.py�_get_http_response_size s
�r)�
str | NonecCs|j�d|j�d��S)z�
    Return either the ETag or Last-Modified header (or None if neither exists).
    The return value can be used in an If-Range header.
    �etagz
last-modified)r"�getr&r'r'r(�(_get_http_response_etag_or_last_modified'sr-�linkr�progress_barr
�total_length�range_start�Iterable[bytes]c
Cs�|jtjkr
|j}n|j}t|�}|r/|r%|�dt|��dt|��d�}n
|�dt|��d�}t|�r:t�	d|�n|rCt�	d|�nt�	d|�t�
�tjkrSd}nt|�rZd}n|s_d}n	|d	krfd}nd}t
|�}|sp|St|||d
�}	|	|�S)Nz (�/�)zUsing cached %szResuming download %szDownloading %sFTi)�bar_type�size�initial_progress)�netlocr�file_storage_domain�show_url�url_without_fragmentrrr�logger�info�getEffectiveLevel�logging�INFOrr)
rr.r/r0r1�url�
logged_url�
show_progress�chunks�rendererr'r'r(�
_log_download/s<��rF�filename�strcCstj�|�S)zJ
    Sanitize the "filename" value from a Content-Disposition header.
    )�os�path�basename)rGr'r'r(�sanitize_content_filenamebsrL�content_disposition�default_filenamecCs4tj��}||d<|�d�}|rtt|��}|p|S)z�
    Parse the "filename" value from a Content-Disposition header, and
    return the default filename if the result is empty.
    �content-typerG)�email�message�Message�	get_paramrLrH)rMrN�mrGr'r'r(�parse_content_dispositionis

rUcCs�|j}|j�d�}|rt||�}t|�d}|s(t�|j�dd��}|r(||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�rO�)
rGr"r,rUr�	mimetypes�guess_extensionrArIrJ)rr.rGrM�extr'r'r(�_get_http_response_filenamexs
r[c@s`eZdZUdZded<ded<ded<dZd	ed
<dZd	ed<ddd�Zddd�Zddd�Z	dS)�
_FileDownloadz+Stores the state of a single link download.rr.r�output_filerr6rr!�bytes_received�
reattemptsr�boolcCst|jduo|j|jk�S�N)r`r6r^��selfr'r'r(�
is_incomplete�sz_FileDownload.is_incomplete�data�bytes�NonecCs"|jt|�7_|j�|�dSra)r^�lenr]�write)rcrer'r'r(�write_chunk�sz_FileDownload.write_chunkcCs |j�d�|j��d|_dS)z1Delete any saved data and reset progress to zero.rN)r]�seek�truncater^rbr'r'r(�
reset_file�s

z_FileDownload.reset_fileN)rr`)rerfrrg)rrg)
�__name__�
__module__�__qualname__�__doc__�__annotations__r^r_rdrjrmr'r'r'r(r\�s


r\c@s`eZdZd+d	d
�Zd,dd�Zd-dd�Zd.dd�Zd/dd�Zd0d!d"�Zd1d$d%�Z	e
fd2d(d)�Zd*S)3�
Downloader�sessionrr/r
�resume_retriesr!rrgcCs&|dksJd��||_||_||_dS)Nrz<Number of max resume retries must be bigger or equal to zero)�_session�
_progress_bar�_resume_retries)rcrtr/rur'r'r(�__init__�s
�
zDownloader.__init__�links�Iterable[Link]�locationrH�&Iterable[tuple[Link, tuple[str, str]]]ccs,�|D]}|||�\}}|||ffVqdS)z.Convenience method to download multiple links.Nr')rcrzr|r.�filepath�content_typer'r'r(�batch�s
��zDownloader.batchr.r�tuple[str, str]c	Cs�|�|�}t|�}tj�|t||��}t|d��}t|||�}|�||�|�	�r/|�
||�Wd�n1s9wY|j�dd�}||fS)z+Download a link and save it under location.�wbNzContent-TyperW)
�	_http_getr)rIrJ�joinr[�openr\�_process_responserd�_attempt_resumes_or_redownloadsr"r,)	rcr.r|r�
download_sizer~�content_file�downloadrr'r'r(�__call__�s
��zDownloader.__call__r�r\rr	c
Cstt||j|j|j|jd�}z
|D]}|�|�qWdSty9}z|jdur)|�t�d�WYd}~dSd}~ww)z)Download and save chunks from a response.)r1Nz'Connection timed out while downloading.)	rFr.rwr6r^rjrr<�warning)rcr�rrD�chunk�er'r'r(r��s"��
��zDownloader._process_response�
first_respc
Cs�|j|jkr`|��r`|jdusJ�|jd7_t�dt|j�t|j�|j�z"|j||d�}|j	t
jk}|rB|��t
|�|_|}|�||�WntttfyUYqw|j|jkr`|��s
|��rot�|jj�t|��|jdkr||�||�dSdS)zAAttempt to resume/restart the download if connection was dropped.NrVz<Attempting to resume incomplete download (%s/%s, attempt %d))�should_matchr)r_rxrdr6r<r�rr^�_http_get_resume�status_coder�PARTIAL_CONTENTrmr)r��ConnectionErrorr�OSErrorrI�remover]�namer�_cache_resumed_download)rcr�r��resume_resp�must_restartr'r'r(r��s6�
��
�z*Downloader._attempt_resumes_or_redownloads�original_responsec
Cs&|jj}|j�|�}t|t�st�d|�dSt|jt	�s!Jd��t
�}|jd|id�t�}|j
��D]\}}|��dvrB|||<q4t|j�|d<td|d	d
d�}	|j�|�}
|jj�||	d�}|j�|
|�|j��t|jjd
��}|j�|
|�Wd�n1s�wYt�d|�dS)an
        Manually cache a file that was successfully downloaded via resume retries.

        cachecontrol doesn't cache 206 (Partial Content) responses, since they
        are not complete files. This method manually adds the final file to the
        cache as though it was downloaded in a single request, so that future
        requests can use the cache.
        z<Skipping resume download caching: no cache controller for %sNzseparate body cache not in use!�GET)�methodrAr")z
content-ranger r rW��F)�bodyr"�status�preload_content��rbz?Cached resumed download as complete response for future use: %s)r.r;rv�get_adapter�
isinstancerr<�debug�cacherr�preparerr"�items�lowerrHr6�URLlib3Response�
controller�	cache_url�
serializer�dumps�setr]�flushr�r��set_body_from_io)
rcr�r�rA�adapter�synthetic_request�synthetic_response_headers�key�value�synthetic_responser��
metadata_blob�fr'r'r(r�sL
������
��z"Downloader._cache_resumed_downloadr�cCs<t��}d|j�d�|d<t|�}r||d<|�|j|�S)z2Issue a HTTP range request to resume the download.zbytes=�-�RangezIf-Range)r�copyr^r-r�r.)rcr�r�r"�
identifierr'r'r(r�=s
zDownloader._http_get_resumer"�Mapping[str, str]c
Csb|j}z|jj||dd�}t|�W|Sty0}z|jdus"J�t�d|jj|��d}~ww)NT)r"�streamzHTTP error %s while getting %s)	r;rvr,rr�responser<�criticalr�)rcr.r"�
target_urlrr�r'r'r(r�Ks
�
���zDownloader._http_getN)rtrr/r
rur!rrg)rzr{r|rHrr})r.rr|rHrr�)r�r\rr	rrg)r�r\r�r	rrg)r�r\r�r	rrg)r�r\r�r	rr	)r.rr"r�rr	)rnrorpryr�r�r�r�r�r�rr�r'r'r'r(rs�s





(
8rs)rr	rr)rr	rr*)r)rr	r.rr/r
r0rr1rrr2)rGrHrrH)rMrHrNrHrrH)rr	r.rrrH)?rq�
__future__r�
email.messagerPr?rXrI�collections.abcrr�dataclassesr�httpr�typingr�pip._vendor.requestsr�pip._vendor.requests.modelsr	�pip._vendor.urllib3r
r�� pip._vendor.urllib3._collectionsr�pip._vendor.urllib3.exceptionsr�pip._internal.cli.progress_barsr
r�pip._internal.exceptionsrr�pip._internal.models.indexr�pip._internal.models.linkr�pip._internal.network.cacherr�pip._internal.network.sessionrr�pip._internal.network.utilsrrr�pip._internal.utils.miscrrr�	getLoggerrnr<r)r-rFrLrUr[r\rsr'r'r'r(�<module>sD



�
3