a  ze@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)rr`/opt/bitninja-python-dojo/embedded/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 file_storage_domainshow_urlurl_without_fragmentrformatrr loggerinfogetEffectiveLevelloggingINFOrrr)rrr total_lengthurl logged_url show_progresschunksrrr_prepare_downloads.   r/)filenamercCs tj|S)zJ Sanitize the "filename" value from a Content-Disposition header. )ospathbasename)r0rrrsanitize_content_filenameGsr4)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. r0)cgi parse_headergetr4)r5r6_typeparamsr0rrrparse_content_dispositionNs  r<)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) r0rr9r<r mimetypesguess_extensionr+r1r2)rrr0r5extrrr_get_http_response_filename\s   rB)sessionrrcCs.|jddd}|j|tdd}t||S)N#r=rT)rstream)r+splitr9r r)rCr target_urlrrrr_http_get_downloadqsrHc@s8eZdZeeddddZeeeeefdddZdS) DownloaderNrCrrcCs||_||_dSN_session _progress_barselfrCrrrr__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-Typer>rHrMrresponser%critical status_coderBr1r2joinr/rNopenwriterr9) rPrrRrer0filepathr. content_filechunk content_typerrr__call__s    *zDownloader.__call__) __name__ __module__ __qualname__r strrQr rrbrrrrrIxs  rIc@sHeZdZeeddddZeeeeeeeeeffdddZ dS)BatchDownloaderNrJcCs||_||_dSrKrLrOrrrrQszBatchDownloader.__init__)linksrRrc 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.NrSrTrUr>rV) rPrhrRrrr]r0r^r.r_r`rarrrrbs&  *zBatchDownloader.__call__) rcrdrer rfrQrr rrbrrrrrgs rg).__doc__r7r(r?r1typingrrrZpip._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 getLoggerrcr%rrrfbytesr/r4r<rBrHrIrgrrrrs6        )