U .eEQ@sddlmZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z ddlmZddlmZddlmZmZddlmZdd lmZdd lmZdd lmZdd lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'dd l(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3e+rddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:ddl;mZ>ddl?m@Z@ddlAmBZBered0d ZSd1d2ZTd3d4ZUd?d5dZVd@d6d!ZWd7d#ZXd8d"ZYd9d:ZZd;d<Z[dS)A)absolute_importN)requests)CONTENT_CHUNK_SIZEResponse)PY2)parse) HashMismatchInstallationError)PyPI) PipSession) auto_decode) copy2_fixed) ask_path_exists backup_dirconsume display_path format_sizehide_urlpath_to_displayrmtreesplitext) TempDirectory)MYPY_CHECK_RUNNING)DownloadProgressProvider) unpack_file)get_url_scheme)vcs)IOCallableListOptionalTextTuple) TypedDict)Link)Hashes)VersionControlCopytreeKwargsignoresymlinksF)Ztotal) copy_functionr)Zignore_dangling_symlinksr*get_file_contentunpack_vcs_linkunpack_file_urlunpack_http_url unpack_urlparse_content_dispositionsanitize_content_filenamec Cs6|dkrtdt|}|dkr>||}||j|jfS|dkr|rd|drdtd||f|ddd}| d d }t |}|r| dd|d dd}t |}|d rd |d }|}z&t|d }t|}W5QRXWn4tk r,} ztd t| W5d} ~ XYnX||fS)a*Gets the content of a file; it may be a filename, file: URL, or http: URL. Returns (location, content). Content is unicode. :param url: File path or url. :param comes_from: Origin description of requirements. :param session: Instance of pip.download.PipSession. NzAget_file_content() missing 1 required keyword argument: 'session')httpZhttpsfiler3z6Requirements file %s references URL %s, which is local:\/|rbz$Could not open requirements file: %s) TypeErrorrgetraise_for_statusurltext startswithr splitreplace_url_slash_drive_rematchgroup urllib_parseZunquotelstripopenr readIOErrorstr) r>Z comes_fromsessionschemeresppathrDfZcontentexcrR:/usr/lib/python3.8/site-packages/pip/_internal/download.pyr,UsB         z /*([a-z])\|cCs t|}|j|t|jddS)N)r>)_get_used_vcs_backendunpackrr>)linklocation vcs_backendrRrRrSr-scCs$tjD]}|j|jkr|SqdS)z1 Return a VersionControl object or None. N)rZbackendsrMZschemes)rVrXrRrRrSrTs   rTcOs|SNrR)iterableargskwargsrRrRrS_progress_indicatorsr]c s6ztjd}Wntttfk r0d}YnXtdd}ttj krRd}n&|r\d}n|dkrjd}n|std}nd}|j }fdd} fd d } t } |j t j kr|} n|j} |rt||d } |rtd | t|n td | n|rtd| n td | | | | tt} |r*|| nt| dS)Nzcontent-lengthrZ from_cacheFi@Tc3sTz jj|ddD] }|VqWn.tk rNj|}|sBqJ|Vq0YnXdS)NF)Zdecode_content)rawstreamAttributeErrorrI)Z chunk_sizechunk)rNrRrS resp_reads   z _download_url..resp_readc3s|D]}||VqdSrY)write)Zchunksra) content_filerRrSwritten_chunkss z%_download_url..written_chunks)maxzDownloading %s (%s)zDownloading %szUsing cached %s)intheaders ValueErrorKeyErrorr;getattrloggerZgetEffectiveLevelloggingINFOshow_urlr]Znetlocr Zurl_without_fragmentrinforrZcheck_against_chunksr)rNrVrdhashes progress_barZ total_lengthZ cached_respZ show_progressrorbreZprogress_indicatorr>Zdownloaded_chunksrR)rdrNrS _download_urlsP   %    rscCsd}tj||j}tj|rtdt|d}|dkr@d}nj|dkrdtdt|t |nF|dkrt |}td t|t|t ||n|d krt d |rt ||td t|dS) NTz8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)abort)iwbartFruz Deleting %srvzBacking up %s to %srwzSaved %s)osrOjoinfilenameexistsrrrlwarningremovershutilZmovesysexitcopyrp)r{rWrVrZdownload_locationresponseZ dest_filerRrRrS _copy_files6    ronc Cs|dkrtdtddv}d}|r0t|||}|rH|}t|d} nt|||j||\}} t||| |r~|s~t||||st |W5QRXdS)Nz@unpack_http_url() missing 1 required keyword argument: 'session'rU)Zkindr) r;r_check_download_dir mimetypes guess_type_download_http_urlrOrrryunlink) rVrW download_dirrLrqrrtemp_diralready_downloaded_path from_path content_typerRrRrSr/s2    c CsTzt||Wn@tjk rN}z tdt|t|t|W5d}~XYnXdS)zCopying special files is not supported, but as a convenience to users we skip errors copying them. This supports tools that may create e.g. socket files in the project source directory. z>Ignoring special file error '%s' encountered copying %s to %s.N)r rZSpecialFileErrorrlr}rKr)srcdesterRrRrS_copy2_ignoring_special_filesJsrcs`tj|}tj|tj|fdd}t|dd}tsLt|d<tj |f|dS)Ncs6g}|kr|ddg7}tj|kr2|g7}|S)Nz.toxz.nox)ryrOabspath)dnamesZskippedsourceZtarget_basenameZtarget_dirnamerRrSr)es   z!_copy_source_tree..ignoreTr(r+) ryrOrbasenamedirnamedictrrrZcopytree)rtargetZtarget_abspathr)r\rRrrS_copy_source_tree_s    rcCs|j}|r>tj|r"t|t|||r:tddS|rL| |d}|r`t |||}|rj|}n|}t |d}t ||||r|st|||dS)zUnpack link into location. If download_dir is provided and link points to a file, make a copy of the link file inside download_dir. z*Link is a directory, ignoring download_dirNr) file_pathZis_existing_dirryrOisdirrrrlrpcheck_against_pathrrrrr)rVrWrrqZ link_pathrrrrRrRrSr.~s.      cCsP|jrt||n:|jr*t||||dn"|dkr8t}t||||||ddS)avUnpack link. If link is a VCS link: if only_download, export into download_dir and ignore location else unpack into location for other types of link: - unpack into location - if download_dir, copy the file into download_dir - if only_download, mark location for deletion :param hashes: A Hashes object, one of whose embedded hashes must match, or HashMismatch will be raised. If the Hashes is empty, no matches are required, and unhashable types of requirements (like VCS ones, which would ordinarily raise HashUnsupported) are allowed. )rqN)rqrr)Zis_vcsr-is_filer.r r/)rVrWrrLrqrrrRrRrSr0s cCs tj|S)zJ Sanitize the "filename" value from a Content-Disposition header. )ryrOr)r{rRrRrSr2scCs,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_headerr<r2)content_dispositionZdefault_filenameZ_typeZparamsr{rRrRrSr1s  c Cs*|jddd}z |j|ddidd}|Wn8tjk rj}ztd|jj |W5d }~XYnX|j d d }|j } |j d } | rt | | } t | d} | st|} | r| | 7} | s|j|jkrtj |jd} | r| | 7} tj|| } t| d } t||| ||W5QRX| |fS)z6Download link url into temp_dir using provided session#r6rzAccept-EncodingZidentityT)rhr_zHTTP error %s while getting %sNz content-typezcontent-dispositionwb)r>rAr<r=rZ HTTPErrorrlZcriticalrZ status_coderhr{r1rrZguess_extensionryrOrzrHrs)rVrLrrqrrZ target_urlrNrQrr{rZextrrdrRrRrSrsB       rcCsptj||j}tj|s dStd||rlz||Wn,tk rjt d|t |YdSX|S)z Check download_dir for previously downloaded file with correct hash If a correct file is found return its path else None NzFile was already downloaded %sz;Previously-downloaded file %s has bad hash. Re-downloading.) ryrOrzr{r|rlrprrr}r)rVrrqZ download_pathrRrRrSr7s   r)NN)NNNr)NN)NNNr)\Z __future__rrrmrryrerrZ pip._vendorrZpip._vendor.requests.modelsrrZpip._vendor.sixrZpip._vendor.six.moves.urllibrrFZpip._internal.exceptionsrr Zpip._internal.models.indexr Zpip._internal.network.sessionr Zpip._internal.utils.encodingr Zpip._internal.utils.filesystemr Zpip._internal.utils.miscrrrrrrrrrZpip._internal.utils.temp_dirrZpip._internal.utils.typingrZpip._internal.utils.uirZpip._internal.utils.unpackingrZpip._internal.utils.urlsrZpip._internal.vcsrtypingrrrr r!r"Zmypy_extensionsr#Zpip._internal.models.linkr$Zpip._internal.utils.hashesr%Z pip._internal.vcs.versioncontrolr&rKboolr'__all__Z getLogger__name__rlr,compileIrCr-rTr]rsrr/rrr.r0r2r1rrrRrRrRrSs        ,               0 d -" 8 .?