o
    àej5  ã                   @  sˆ  d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZ ddl	mZ ddlmZ ddlmZmZmZmZ ddlmZ e e¡Zee Zz
ddlZee7 ZW n eyi   e d	¡ Y nw z
ddlZee7 ZW n ey‚   e d
¡ Y nw d;dd„Zd<dd„Zd=dd„Z d>dd„Z!d;dd„Z"d?d d!„Z#d@d$d%„Z$dAdBd*d+„Z%dCd,d-„Z&dDd2d3„Z'dEd5d6„Z(	dFdGd9d:„Z)dS )HzUtilities related archives.é    )ÚannotationsN)ÚIterable)ÚZipInfo)ÚInstallationError)ÚBZ2_EXTENSIONSÚTAR_EXTENSIONSÚXZ_EXTENSIONSÚZIP_EXTENSIONS)Ú
ensure_dirzbz2 module is not availablezlzma module is not availableÚreturnÚintc                  C  s   t  d¡} t  | ¡ | S )zBGet the current umask which involves having to set it temporarily.r   )ÚosÚumask)Úmask© r   ú]/var/www/html/choboyeo/PHP/venv/lib/python3.10/site-packages/pip/_internal/utils/unpacking.pyÚcurrent_umask-   s   

r   ÚpathÚstrú	list[str]c                 C  sd   |   d¡  d¡} d| v r$d| v r|  d¡|  d¡k sd| vr$|  dd¡S d| v r.|  dd¡S | dgS )Nú/ú\é   Ú )ÚlstripÚfindÚsplit©r   r   r   r   Úsplit_leading_dir4   s   $r   ÚpathsúIterable[str]Úboolc                 C  sD   d}| D ]}t |ƒ\}}|s dS |du r|}q||kr dS qdS )zyReturns true if all the paths have the same leading path name
    (i.e., everything is in one subdirectory in an archive)NFT)r   )r   Úcommon_prefixr   ÚprefixÚrestr   r   r   Úhas_leading_dir@   s   ÿr%   Ú	directoryÚtargetc                 C  s0   t j | ¡}t j |¡}||kp| |t j ¡S )zƒ
    Return true if the absolute path of target is within the directory
    (including when target is equal to the directory).
    )r   r   ÚabspathÚ
startswithÚsep)r&   r'   Úabs_directoryÚ
abs_targetr   r   r   Úis_within_directoryO   s   r-   c                   C  s   dt ƒ  @ dB S )Niÿ  éI   )r   r   r   r   r   Ú!_get_default_mode_plus_executableZ   s   r/   ÚNonec                 C  s   t  | tƒ ¡ dS )zx
    Make file present at path have execute for user/group/world
    (chmod +x) is no-op on windows per python docs
    N)r   Úchmodr/   r   r   r   r   Ú2set_extracted_file_to_default_mode_plus_executable^   s   r2   Úinfor   c                 C  s$   | j d? }t|ot |¡o|d@ ƒS )Né   r.   )Úexternal_attrr!   ÚstatÚS_ISREG)r3   Úmoder   r   r   Úzip_item_is_executablef   s   
r9   TÚfilenameÚlocationÚflattenc              	   C  s@  t |ƒ t| dƒ}z‘tj|dd�}t| ¡ ƒo|}| ¡ D ]v}|j}|}|r,t|ƒd }t	j
 ||¡}t	j
 |¡}	t||ƒsId}
t|
 | ||¡ƒ‚| d¡rSt |ƒ qt |	ƒ | |¡}z)t|dƒ�}t ||¡ W d  ƒ n1 ssw   Y  W | ¡  t|ƒr…t|ƒ q| ¡  t|ƒr“t|ƒ w w W | ¡  dS | ¡  w )	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)Ú
allowZip64r   zQThe zip file ({}) has a file ({}) trying to install outside target directory ({}))r   r   ÚwbN)r
   ÚopenÚzipfileÚZipFiler%   ÚnamelistÚinfolistr:   r   r   r   ÚjoinÚdirnamer-   r   ÚformatÚendswithÚshutilÚcopyfileobjÚcloser9   r2   )r:   r;   r<   ÚzipfpÚzipÚleadingr3   ÚnameÚfnÚdirÚmessageÚfpÚdestfpr   r   r   Ú
unzip_filem   sF   	

ÿ


ÿ€€þ
ÿærU   c                   sb  t ˆƒ ˆ ¡  d¡sˆ ¡  d¡rd}n&ˆ ¡  t¡rd}nˆ ¡  t¡r)d}nˆ ¡  d¡r3d}nt dˆ¡ d	}tjˆ|d
d�}zht	dd„ | 
¡ D ƒƒ}ztj‰ W n tyd   tˆˆ||ƒ Y nAw tƒ ‰|r�| 
¡ D ]}t|jƒ\}}||_| ¡ rŒt|jƒ\}}	||krŒ|	|_qnd‡ ‡‡‡fdd„}
|jˆ|
d� W | ¡  dS W | ¡  dS | ¡  w )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 on top of the
    default.  Note that for windows, any execute changes using os.chmod are
    no-ops per the python docs.
    z.gzz.tgzzr:gzzr:bz2zr:xzz.tarÚrz-Cannot determine compression type for file %szr:*zutf-8)Úencodingc                 S  s   g | ]}|j ‘qS r   )rO   )Ú.0Úmemberr   r   r   Ú
<listcomp>¶   s    zuntar_file.<locals>.<listcomp>rY   útarfile.TarInfor   r   r   c              
     s¤   | j }z%zˆ | ˆƒ} W n tjy&   tjd d… dv r#t | ˆ¡} n‚ Y nw W n tjy? } z
d}t| ˆ|¡ƒ‚d }~ww |  	¡ rM|d@ rMˆ| _ | S d | _ | S )Né   >   ©r\   é	   é   ©r\   é
   é   ©r\   é   é   z%Invalid member in the tar file {}: {}r.   )
r8   ÚtarfileÚLinkOutsideDestinationErrorÚsysÚversion_infoÚ
tar_filterÚTarErrorr   rG   Úisfile)rY   r   Ú	orig_modeÚexcrR   ©Údata_filterÚdefault_mode_plus_executabler:   r;   r   r   Ú
pip_filterÎ   s4   
þõ€þÿ€ü
ÿzuntar_file.<locals>.pip_filter)ÚfilterN)rY   r[   r   r   r   r[   )r
   ÚlowerrH   r   r   ÚloggerÚwarningrf   r@   r%   Ú
getmembersrp   ÚAttributeErrorÚ_untar_without_filterr/   r   rO   ÚislnkÚlinknameÚ
extractallrK   )r:   r;   r8   ÚtarrN   rY   Ú	name_leadÚ	name_restÚlnk_leadÚlnk_restrr   r   ro   r   Ú
untar_file›   sJ   	þ
ÿ€'Æ:r‚   r}   útarfile.TarFileÚtarinfor[   c                 C  sX   t j t j |j¡|j¡}t j |¡}| dd¡}z|  |¡ W dS  t	y+   Y dS w )zGCheck if the file pointed to by the symbolic link is in the tar archiver   r   TF)
r   r   rE   rF   rO   r{   ÚnormpathÚreplaceÚ	getmemberÚKeyError)r}   r„   r{   r   r   r   Úis_symlink_target_in_tarû   s   
ÿr‰   rN   c                 C  sž  |  ¡ D ]È}|j}|rt|ƒd }tj ||¡}t||ƒs(d}t| | ||¡ƒ‚| 	¡ r1t
|ƒ q| ¡ rkt||ƒsGd}t| | |j|j¡ƒ‚z| ||¡ W q tyj } zt d| |j|¡ W Y d}~qd}~ww z| |¡}	W n ttfy� } zt d| |j|¡ W Y d}~qd}~ww t
tj |¡ƒ |	dusžJ ‚t|dƒ�}
t |	|
¡ W d  ƒ n1 s´w   Y  |	 ¡  | ||¡ |jd@ rÌt|ƒ qdS )z/Fallback for Python without tarfile.data_filterr   zQThe tar file ({}) has a file ({}) trying to install outside target directory ({})z/In the tar file %s the member %s is invalid: %sNr?   r.   )rw   rO   r   r   r   rE   r-   r   rG   Úisdirr
   Úissymr‰   r{   Ú_extract_memberÚ	Exceptionru   rv   Úextractfilerˆ   rx   rF   r@   rI   rJ   rK   Úutimer8   r2   )r:   r;   r}   rN   rY   rP   r   rR   rn   rS   rT   r   r   r   ry   	  sj   

ÿ

ÿÿü€÷ü€÷
ÿ
€Èry   Úcontent_typeú
str | Nonec                   sè   t j ˆ ¡‰ ˆ  d¡ ‰d‡ ‡‡fdd„}d‡ ‡fdd„}|dkr$|ƒ S |d	kr+|ƒ S ˆ  ¡  t¡r5|ƒ S ˆ  ¡  tt t ¡rC|ƒ S t	 
ˆ ¡}t ˆ ¡}|rT|sT|ƒ S |r[|s[|ƒ S |re|ret d
ˆ ¡ t dˆ ˆ|¡ tdˆ› �ƒ‚)zÑUnpack ``filename`` into ``location``.

    Archive format is chosen in order of decreasing reliability:
    ``content_type``, then filename extension, then magic signature
    (unambiguous matches only).
    z.whlr   r0   c                     s   t ˆ ˆˆd� d S )N)r<   )rU   r   ©r:   r;   Úzip_flattenr   r   Ú_unzip\  s   zunpack_file.<locals>._unzipc                     s   t ˆ ˆƒ d S ©N)r‚   r   )r:   r;   r   r   Ú_untar_  s   zunpack_file.<locals>._untarzapplication/zipzapplication/x-gzipzAmbiguous file signature in %s.zZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz#Cannot determine archive format of N)r   r0   )r   r   ÚrealpathrH   rt   r	   r   r   r   rA   Ú
is_zipfilerf   Ú
is_tarfileru   ÚerrorÚcriticalr   )r:   r;   r�   r”   r–   r˜   r™   r   r’   r   Úunpack_fileN  s6   

ûrœ   )r   r   )r   r   r   r   )r   r    r   r!   )r&   r   r'   r   r   r!   )r   r   r   r0   )r3   r   r   r!   )T)r:   r   r;   r   r<   r!   r   r0   )r:   r   r;   r   r   r0   )r}   rƒ   r„   r[   r   r!   )
r:   r   r;   r   r}   rƒ   rN   r!   r   r0   r•   )r:   r   r;   r   r�   r‘   r   r0   )*Ú__doc__Ú
__future__r   Úloggingr   rI   r6   rh   rf   rA   Úcollections.abcr   r   Úpip._internal.exceptionsr   Úpip._internal.utils.filetypesr   r   r   r	   Úpip._internal.utils.miscr
   Ú	getLoggerÚ__name__ru   ÚSUPPORTED_EXTENSIONSÚbz2ÚImportErrorÚdebugÚlzmar   r   r%   r-   r/   r2   r9   rU   r‚   r‰   ry   rœ   r   r   r   r   Ú<module>   sR    
ÿÿ







.
`
Hý