a Ra@sTdZddlZddlZddlZddlZddlmZmZmZddl m Z m Z ddl m Z ddlmZddlmZddlmZdd lmZdd lmZdd lmZmZmZdd lmZmZmZe e!Z"e ee#d ddZ$e ee%ee&dddZ'e%e%dddZ(e%e%e%dddZ)e ee%dddZ*eee dddZ+Gdd d Z,Gd!d"d"Z-dS)#z)Download files with progress indicators. N)IterableOptionalTuple)CONTENT_CHUNK_SIZEResponse)DownloadProgressProvider)NetworkConnectionError)PyPI)Link) is_from_cache) PipSession)HEADERSraise_for_statusresponse_chunks) format_sizeredact_auth_from_urlsplitext)respreturnc Cs0zt|jdWStttfy*YdS0dS)Nzcontent-length)intheaders ValueErrorKeyError TypeError)rrO/opt/alt/python39/lib/python3.9/site-packages/pip/_internal/network/download.py_get_http_response_sizesr)rlink progress_barrcCst|}|jtjkr|j}n|j}t|}|r>d|t|}t |rTt d|n t d|t t jkrtd}n*t |rd}n|sd}n|dkrd}nd}t|t}|s|St||d|S)Nz{} ({})zUsing cached %szDownloading %sFTi@)max)rnetlocr Zfile_storage_domainZshow_urlZurl_without_fragmentrformatrr loggerinfoZgetEffectiveLevelloggingINFOrrr)rrrZ total_lengthurlZ logged_urlZ show_progresschunksrrr_prepare_downloads.   r()filenamercCs tj|S)zJ Sanitize the "filename" value from a Content-Disposition header. )ospathbasename)r)rrrsanitize_content_filenameGsr-)content_dispositiondefault_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_headergetr-)r.r/Z_typeparamsr)rrrparse_content_dispositionNs  r3)rrrcCs|j}|jd}|r t||}t|d}|sPt|jdd}|rP||7}|s~|j|jkr~tj |jd}|r~||7}|S)zoGet an ideal filename from the given HTTP response, falling back to the link filename if not provided. zcontent-dispositionz content-type) r)rr1r3r mimetypesZguess_extensionr&r*r+)rrr)r.Zextrrr_get_http_response_filename\s   r7)sessionrrcCs.|jddd}|j|tdd}t||S)N#r4rT)rstream)r&splitr1r r)r8rZ target_urlrrrr_http_get_downloadqsr<c@s8eZdZeeddddZeeeeefdddZdS) DownloaderNr8rrcCs||_||_dSN_session _progress_barselfr8rrrr__init__yszDownloader.__init__)rlocationrc Cszt|j|}WnFtyV}z.|jdus.Jtd|jj|WYd}~n d}~00t||}tj ||}t |||j }t |d$}|D]} || qWdn1s0Y|jdd} || fS)z.Download the file given by link into location.NHTTP error %s while getting %swb Content-Typer5r<rArZresponser"ZcriticalZ status_coder7r*r+joinr(rBopenwriterr1) rDrrFrer)filepathr' content_filechunk content_typerrr__call__s    *zDownloader.__call__) __name__ __module__ __qualname__r strrEr rrSrrrrr=xs  r=c@sHeZdZeeddddZeeeeeeeeeffdddZ dS)BatchDownloaderNr>cCs||_||_dSr?r@rCrrrrEszBatchDownloader.__init__)linksrFrc cs|D]}zt|j|}WnFty^}z.|jdus6Jtd|jj|WYd}~n d}~00t||}tj ||}t |||j }t |d$} |D]} | | qWdn1s0Y|jdd} ||| ffVqdS)z0Download the files given by links into location.NrGrHrIr5rJ) rDrYrFrrrNr)rOr'rPrQrRrrrrSs&  *zBatchDownloader.__call__) rTrUrVr rWrErr rrSrrrrrXs rX).__doc__r0r$r6r*typingrrrZpip._vendor.requests.modelsrrZpip._internal.cli.progress_barsrZpip._internal.exceptionsrZpip._internal.models.indexr Zpip._internal.models.linkr Zpip._internal.network.cacher Zpip._internal.network.sessionr Zpip._internal.network.utilsr rrZpip._internal.utils.miscrrrZ getLoggerrTr"rrrWbytesr(r-r3r7r<r=rXrrrrs6        )