관리-도구
편집 파일: unpacking.cpython-38.pyc
U ��.e�% � @ sX d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl m Z ddlmZm Z mZmZ ddlmZ ddlmZ er�ddlmZmZmZmZmZ e�e�Zee ZzddlZee7 ZW n ek r� e� d � Y nX zddl!Z!ee7 ZW n ek �r e� d � Y nX dd� 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 availablec C s t �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_umask2 s r c C sh | � d�� d�} d| krHd| kr4| �d�| �d�k s<d| krH| �dd�S d| kr\| �dd�S | dgS d S )N�/�\� � )�lstrip�find�split)�pathr r r �split_leading_dir9 s ����r c C sD d}| D ]6}t |�\}}|s" dS |dkr0|}q||kr dS qdS )zyReturns true if all the paths have the same leading path name (i.e., everything is in one subdirectory in an archive)NFT)r )�pathsZ common_prefixr �prefix�restr r r �has_leading_dirI s r! c C s0 t j�| �}t j�|�}t j�||g�}||kS )zL Return true if the absolute path of target is within the directory )r r �abspath�commonprefix)Z directory�targetZ abs_directoryZ abs_targetr r r r �is_within_directoryY s r% Tc C sF t |� t| d�}�z"tj|dd�}t|�� �o2|}|�� D ]�}|j}|}|rZt |�d }t j�||�}t j� |�} t||�s�d} t| �| ||���|�d�s�|�d�r�t |� q<t | � |�|�}z&t|d��} t�|| � W 5 Q R X W 5 |�� |jd? }|�r0t�|��r0|d @ �r0t �|d t� d B � X q<W 5 |�� X dS ) a� Unzip 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. �rbT)Z allowZip64r zQThe zip file ({}) has a file ({}) trying to install outside target directory ({})r r � �I � �wbN)r �open�close�zipfileZZipFiler! ZnamelistZinfolist�filenamer r r �join�dirnamer% r �format�endswithZ external_attr�stat�S_ISREG�chmodr �shutil�copyfileobj)r. �location�flattenZzipfp�zip�leading�info�name�fn�dir�message�fp�mode�destfpr r r � unzip_filee s8 � rD c C s\ t |� | �� �d�s$| �� �d�r*d}nL| �� �t�r>d}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�|� W n tjk �r Y nX |�� �r4t |� q�|�� �r�z|�||� W n> tk �r� } zt�d| |j| � W Y �q�W 5 d} ~ X Y nX q�z|�|�} W nB ttfk �r� } zt�d| |j| � W Y �q�W 5 d} ~ X Y nX t tj�|�� t|d��}t� | |� W 5 Q R X | � � |�!||� |j"d@ r�t�#|dt$� dB � q�W 5 |� � X dS )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:*c S s g | ] }|j �qS r �r= )�.0�memberr r r � <listcomp>� s zuntar_file.<locals>.<listcomp>r zQThe tar file ({}) has a file ({}) trying to install outside target directory ({})rF z/In the tar file %s the member %s is invalid: %sNr* r( r) )%r �lowerr2 r r �loggerZwarning�tarfiler+ r, r! Z getmembersr= r r r r/ r% r r1 Zdata_filter�replaceZLinkOutsideDestinationError�isdirZissymZ_extract_member� ExceptionZextractfile�KeyError�AttributeErrorr0 r6 r7 �utimerB r5 r )r. r8 rB Ztarr; rH r>