U ��.eEQ�@s�ddlmZddlZddlZddlZddlZddlZddlZddlZddl 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+�r�ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:ddl;mZ>ddl?m@Z@ddlAmBZBe�r�ed0d �ZSd1d2�ZTd3d4�ZUd?d5d�ZVd@d6d!�ZWd7d#�ZXd8d"�ZYd9d:�ZZd;d<�Z[dS)A�)�absolute_importN)�requests)�CONTENT_CHUNK_SIZE�Response)�PY2)�parse)� HashMismatch�InstallationError)�PyPI)� PipSession)� auto_decode)� copy2_fixed) �ask_path_exists� backup_dir�consume� display_path� format_size�hide_url�path_to_display�rmtree�splitext)� TempDirectory)�MYPY_CHECK_RUNNING)�DownloadProgressProvider)� unpack_file)�get_url_scheme)�vcs)�IO�Callable�List�Optional�Text�Tuple)� TypedDict)�Link)�Hashes)�VersionControl�CopytreeKwargs��ignore�symlinksF)Ztotal)� copy_functionr)Zignore_dangling_symlinksr*�get_file_content�unpack_vcs_link�unpack_file_url�unpack_http_url� unpack_url�parse_content_disposition�sanitize_content_filenamec Cs6|dkrtd��t|�}|dkr>|�|�}|��|j|jfS|dkr�|rd|�d�rdtd||f��|�dd�d}|� d d �}t � |�}|r�|� d�d|�d d�d}t �|�}|�d �r�d |�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')�httpZhttps�filer3z6Requirements file %s references URL %s, which is local�:��\�/�|�rbz$Could not open requirements file: %s)� TypeErrorr�get�raise_for_status�url�text� startswithr �split�replace�_url_slash_drive_re�match�group� urllib_parseZunquote�lstrip�openr �read�IOError�str) r>Z comes_from�session�scheme�resp�pathrD�fZcontent�exc�rR�:/usr/lib/python3.8/site-packages/pip/_internal/download.pyr,UsB �  ��      �z /*([a-z])\|cCs,t|�}|dk st�|j|t|j�d�dS)N)r>)�_get_used_vcs_backend�AssertionError�unpackrr>)�link�location� vcs_backendrRrRrSr-�s cCs$tjD]}|j|jkr|SqdS)z1 Return a VersionControl object or None. N)rZbackendsrMZschemes)rWrYrRrRrSrT�s   rTcOs|S�NrR)�iterable�args�kwargsrRrRrS�_progress_indicator�sr^c s6zt�jd�}Wntttfk r0d}YnXt�dd�}t��tj krRd}n&|r\d}n|dkrjd}n|std}nd}|j }�fdd�} �fd d �} t } |j t j kr�|} n|j} |r�t||d �} |r�t�d | t|��n t�d | �n|r�t�d| �n t�d | �| | | t�t��} |�r*|�| �nt| �dS)Nzcontent-lengthrZ from_cacheFi@�Tc3sTz �jj|dd�D] }|VqWn.tk rN�j�|�}|sBqJ|Vq0YnXdS)NF)Zdecode_content)�raw�stream�AttributeErrorrI)Z chunk_size�chunk)rNrRrS� resp_read�s�   z _download_url..resp_readc3s|D]}��|�|VqdSrZ)�write)Zchunksrb)� content_filerRrS�written_chunks�s z%_download_url..written_chunks)�maxzDownloading %s (%s)zDownloading %szUsing cached %s)�int�headers� ValueError�KeyErrorr;�getattr�loggerZgetEffectiveLevel�logging�INFO�show_urlr^Znetlocr Zurl_without_fragmentr�inforrZcheck_against_chunksr)rNrWre�hashes� progress_barZ total_lengthZ cached_respZ show_progressrprcrfZprogress_indicatorr>Zdownloaded_chunksrR)rerNrS� _download_url�sP   %  � �� rtcCs�d}tj�||j�}tj�|�r�tdt|�d�}|dkr@d}nj|dkrdt�dt|��t� |�nF|dkr�t |�}t�d t|�t|��t � ||�n|d kr�t �d �|r�t �||�t�d t|��dS) NTz8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)abort)�i�w�b�aruFrvz Deleting %srwzBacking up %s to %srx�����zSaved %s)�osrO�join�filename�existsrrrm�warning�remover�shutilZmove�sys�exit�copyrq)r|rXrWr�Zdownload_location�responseZ dest_filerRrRrS� _copy_files6 �� �  r��onc Cs�|dkrtd��tdd��v}d}|r0t|||�}|rH|}t�|�d} nt|||j||�\}} t||| �|r~|s~t|||�|s�t � |�W5QRXdS)Nz@unpack_http_url() missing 1 required keyword argument: 'session'rV)Zkindr) r;r�_check_download_dir� mimetypes� guess_type�_download_http_urlrOrr�rz�unlink) rWrX� download_dirrLrrrs�temp_dir�already_downloaded_path� from_path� content_typerRrRrSr/s2 � ��  c CsTzt||�Wn@tjk rN}z t�dt|�t|�t|��W5d}~XYnXdS)z�Copying 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 r�ZSpecialFileErrorrmr~rKr)�src�dest�erRrRrS�_copy2_ignoring_special_filesJs�r�cs`tj�|�}tj�|��tj�|�����fdd�}t|dd�}tsLt|d<tj �|f|�dS)Ncs6g}|�kr|ddg7}tj�|��kr2|�g7}|S)Nz.toxz.nox)rzrO�abspath)�d�namesZskipped��sourceZtarget_basenameZtarget_dirnamerRrSr)es   z!_copy_source_tree..ignoreTr(r+) rzrOr��basename�dirname�dictrr�r�Zcopytree)r��targetZtarget_abspathr)r]rRr�rS�_copy_source_tree_s    r�cCs�|j}|��r>tj�|�r"t|�t||�|r:t�d�dS|rL|� |�d}|r`t |||�}|rj|}n|}t � |�d}t |||�|r�|s�t|||�dS)z�Unpack 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_dirrzrO�isdirrr�rmrq�check_against_pathr�r�r�rr�)rWrXr�rrZ link_pathr�r�r�rRrRrSr.~s.     � cCsP|jrt||�n:|jr*t||||d�n"|dkr8t�}t||||||d�dS)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. )rrN)rrrs)Zis_vcsr-�is_filer.r r/)rWrXr�rLrrrsrRrRrSr0�s �cCs tj�|�S)zJ Sanitize the "filename" value from a Content-Disposition header. )rzrOr�)r|rRrRrSr2�scCs,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|rRrRrSr1�s  c Cs*|j�dd�d}z |j|ddidd�}|��Wn8tjk rj}zt�d|jj |��W5d }~XYnX|j �d d �}|j } |j �d �} | r�t | | �} t | �d} | s�t�|�} | r�| | 7} | s�|j|jkr�tj� |j�d} | r�| | 7} tj�|| �} t| d ��} t||| ||�W5QRX| |fS)z6Download link url into temp_dir using provided session�#r6rzAccept-EncodingZidentityT)rir`zHTTP error %s while getting %sNz content-type�zcontent-disposition�wb)r>rAr<r=rZ HTTPErrorrmZcriticalr�Z status_coderir|r1rr�Zguess_extensionrzrOr{rHrt)rWrLr�rrrsZ target_urlrNrQr�r|r�Zextr�rerRrRrSr��sB � �     r�cCsptj�||j�}tj�|�s dSt�d|�|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.) rzrOr{r|r}rmrqr�rr~r�)rWr�rrZ download_pathrRrRrSr�7s  � r�)NN)NNNr�)NN)NNNr�)\Z __future__rr�rnr�rz�rer�r�Z 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.vcsr�typingrrrr r!r"Zmypy_extensionsr#Zpip._internal.models.linkr$Zpip._internal.utils.hashesr%Z pip._internal.vcs.versioncontrolr&rK�boolr'�__all__Z getLogger�__name__rmr,�compile�IrCr-rTr^rtr�r/r�r�r.r0r2r1r�r�rRrRrRrS�s�        ,           �� �� �  0 d� -"� 8� .?