o ai @sjdZddlZddlZddlZddlZddlmZmZmZddl m Z m Z ddl m Z ddlmZddlmZddlmZdd lmZdd lmZdd lmZmZmZdd lmZmZmZe e!Z"d e dee#fddZ$d e dede%dee&fddZ'de%de%fddZ(de%de%de%fddZ)d e dede%fddZ*dedede fdd Z+Gd!d"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_urlsplitextrespreturnc Cs,zt|jdWStttfyYdSw)Nzcontent-length)intheaders ValueErrorKeyError TypeError)rr/builddir/build/BUILDROOT/alt-python310-pip-21.3.1-5.el8.x86_64/opt/alt/python310/lib/python3.10/site-packages/pip/_internal/network/download.py_get_http_response_sizes rlink progress_barcCst|}|jtjkr|j}n|j}t|}|rd|t|}t |r*t d|nt d|t t jkr:d}nt |rAd}n|sFd}n |dkrMd}nd}t|t}|sX|St||d|S)Nz{} ({})zUsing cached %szDownloading %sFTi@)max)rnetlocr file_storage_domainshow_urlurl_without_fragmentrformatrr loggerinfogetEffectiveLevelloggingINFOrrr)rrr total_lengthurl logged_url show_progresschunksrrr_prepare_downloads.   r/filenamecCs tj|S)zJ Sanitize the "filename" value from a Content-Disposition header. )ospathbasename)r0rrrsanitize_content_filenameGs r4content_dispositiondefault_filenamecCs,t|\}}|d}|rt|}|p|S)z Parse the "filename" value from a Content-Disposition header, and return the default filename if the result is empty. r0)cgi parse_headergetr4)r5r6_typeparamsr0rrrparse_content_dispositionNs  r<cCs|j}|jd}|rt||}t|d}|s(t|jdd}|r(||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) r0rr9r<r mimetypesguess_extensionr+r1r2)rrr0r5extrrr_get_http_response_filename\s   rBsessioncCs.|jddd}|j|tdd}t||S)N#r=rT)rstream)r+splitr9r r)rCr target_urlrrrr_http_get_downloadqsrHc@s@eZdZdededdfddZdededeeeffd d ZdS) DownloaderrCrrNcC||_||_dSN_session _progress_barselfrCrrrr__init__y zDownloader.__init__rlocationc Cszt|j|}Wnty%}z|jdusJtd|jj|d}~wwt||}tj ||}t |||j }t |d}|D]} || qAWdn1sSwY|jdd} || fS)z.Download the file given by link into location.NHTTP error %s while getting %swb Content-Typer>rHrMrresponser%critical status_coderBr1r2joinr/rNopenwriterr9) rPrrSrer0filepathr. content_filechunk content_typerrr__call__s(    zDownloader.__call__) __name__ __module__ __qualname__r strrQr rrcrrrrrIxs "rIc @sPeZdZdededdfddZdeededeeeeeefffd d Z dS) BatchDownloaderrCrrNcCrJrKrLrOrrrrQrRzBatchDownloader.__init__linksrSc cs|D]h}zt|j|}Wnty*}z|jdusJtd|jj|d}~wwt||}tj ||}t |||j }t |d} |D]} | | qFWdn1sXwY|jdd} ||| ffVqdS)z0Download the files given by links into location.NrTrUrVr>rW) rPrirSrrr^r0r_r.r`rarbrrrrcs2   zBatchDownloader.__call__) rdrerfr rgrQrr rrcrrrrrhs rh).__doc__r7r(r?r1typingrrrpip._vendor.requests.modelsrrpip._internal.cli.progress_barsrpip._internal.exceptionsrpip._internal.models.indexr pip._internal.models.linkr pip._internal.network.cacher pip._internal.network.sessionr pip._internal.network.utilsr rrpip._internal.utils.miscrrr getLoggerrdr%rrrgbytesr/r4r<rBrHrIrhrrrrs@        )