U ��.e�%�@sXdZddlmZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z mZmZddlmZddlmZer�ddlmZmZmZmZmZe�e�Zee ZzddlZee 7ZWnek r�e� d �YnXzddl!Z!ee7ZWn ek �re� d �YnXd d �Z"d d�Z#dd�Z$dd�Z%ddd�Z&dd�Z'ddd�Z(dS)zUtilities related archives. �)�absolute_importN)�InstallationError)�BZ2_EXTENSIONS�TAR_EXTENSIONS� XZ_EXTENSIONS�ZIP_EXTENSIONS)� ensure_dir)�MYPY_CHECK_RUNNING)�Iterable�List�Optional�Text�Unionzbz2 module is not availablezlzma module is not availablecCst�d�}t�|�|S)zBGet the current umask which involves having to set it temporarily.r)�os�umask)�mask�r�A/usr/lib/python3.8/site-packages/pip/_internal/utils/unpacking.py� current_umask2s  rcCsh|�d��d�}d|krHd|kr4|�d�|�d�ksd}n8|���t�rRd}n$|���d�rfd}nt�d|�d }t�||�}�z�t d d �|� �D��}|� �D�]�}|j }|r�t |�d }tj�||�}t||�s�d }t|�|||���zt�|j|d�|�Wntjk �rYnX|���r4t|�q�|���r�z|�||�Wn>tk �r�} zt�d||j | �WY�q�W5d} ~ XYnXq�z|�|�} WnBttfk �r�} zt�d||j | �WY�q�W5d} ~ XYnXttj�|��t|d��} t� | | �W5QRX| � �|�!||�|j"d@r�t�#|dt$�dB�q�W5|� �XdS)a� Untar the file (with path `filename`) to the destination `location`. All files are written based on system defaults and umask (i.e. permissions are not preserved), except that regular file members with any execute permissions (user, group, or world) have "chmod +x" applied after being written. Note that for windows, any execute changes using os.chmod are no-ops per the python docs. z.gzz.tgzzr:gzzr:bz2zr:xzz.tar�rz-Cannot determine compression type for file %szr:*cSsg|] }|j�qSr�r=)�.0�memberrrr� �szuntar_file..rzQThe tar file ({}) has a file ({}) trying to install outside target directory ({})rFz/In the tar file %s the member %s is invalid: %sNr*r(r))%r�lowerr2rr�loggerZwarning�tarfiler+r,r!Z getmembersr=rrrr/r%rr1Z data_filter�replaceZLinkOutsideDestinationError�isdirZissymZ_extract_member� ExceptionZ extractfile�KeyError�AttributeErrorr0r6r7�utimerBr5r) r.r8rBZtarr;rHr>rr@�excrArCrrr� untar_file�s� � �  � �   ��   rTcCs�tj�|�}|dks,|���t�s,t�|�rDt|||�d� d�nR|dkslt � |�sl|���t t t �rxt||�nt�d|||�td�|���dS)Nzapplication/zipz.whl)r9zapplication/x-gzipzZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz%Cannot determine archive format of {})rr�realpathrJr2rr-Z is_zipfilerDrLZ is_tarfilerrrrTrKZcriticalrr1)r.r8Z content_typerrr� unpack_file�s< � �� ��� �� ��rV)T)N))�__doc__Z __future__rZloggingrr6r3rLr-Zpip._internal.exceptionsrZpip._internal.utils.filetypesrrrrZpip._internal.utils.miscrZpip._internal.utils.typingr �typingr r r r rZ getLogger�__name__rKZSUPPORTED_EXTENSIONS�bz2� ImportError�debugZlzmarrr!r%rDrTrVrrrr�sB        4^�