o
    ©„jÅ9  ã                   @  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œdAdd„Z!d>d d!„Z"dBd#d$„Z#dCd'd(„Z$dDdEd-d.„Z%dFd/d0„Z&dGd5d6„Z'dHd8d9„Z(	dIdJd<d=„Z)dS )Kz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/django_cbt/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%   F©Úresolve_symlinksÚ	directoryÚtargetr'   c                C  sN   |rt j | ¡}t j |¡}nt j | ¡}t j |¡}||kp&| |t j ¡S )a  
    Return true if the absolute path of target is within the directory
    (including when target is equal to the directory).

    When ``resolve_symlinks`` is true, resolve symlinks before comparing so
    traversal through a symlink (e.g. "link/../file") is also caught.
    )r   r   ÚrealpathÚabspathÚ
startswithÚsep)r(   r)   r'   Úabs_directoryÚ
abs_targetr   r   r   Úis_within_directoryO   s   
r0   c                   C  s   dt ƒ  @ dB S )Niÿ  éI   )r   r   r   r   r   Ú!_get_default_mode_plus_executablec   s   r2   Ú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   Úchmodr2   r   r   r   r   Ú2set_extracted_file_to_default_mode_plus_executableg   s   r5   Úinfor   c                 C  s$   | j d? }t|ot |¡o|d@ ƒS )Né   r1   )Úexternal_attrr!   ÚstatÚS_ISREG)r6   Úmoder   r   r   Úzip_item_is_executableo   s   
r<   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Údirnamer0   r   ÚformatÚendswithÚshutilÚcopyfileobjÚcloser<   r5   )r=   r>   r?   ÚzipfpÚzipÚleadingr6   ÚnameÚfnÚdirÚmessageÚfpÚdestfpr   r   r   Ú
unzip_filev   sF   	

ÿ


ÿ€€þ
ÿærX   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   )rR   )Ú.0Úmemberr   r   r   Ú
<listcomp>¿   s    zuntar_file.<locals>.<listcomp>r\   ú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 {}: {}r1   )
r;   ÚtarfileÚLinkOutsideDestinationErrorÚsysÚversion_infoÚ
tar_filterÚTarErrorr   rJ   Úisfile)r\   r   Ú	orig_modeÚexcrU   ©Údata_filterÚdefault_mode_plus_executabler=   r>   r   r   Ú
pip_filter×   s4   
þõ€þÿ€ü
ÿzuntar_file.<locals>.pip_filter)ÚfilterN)r\   r^   r   r   r   r^   )r
   ÚlowerrK   r   r   ÚloggerÚwarningri   rC   r%   Ú
getmembersrs   ÚAttributeErrorÚ_untar_without_filterr2   r   rR   ÚislnkÚlinknameÚ
extractallrN   )r=   r>   r;   ÚtarrQ   r\   Ú	name_leadÚ	name_restÚlnk_leadÚlnk_restru   r   rr   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   rH   rI   rR   r~   ÚnormpathÚreplaceÚ	getmemberÚKeyError)r€   r‡   r~   r   r   r   Úis_symlink_target_in_tar  s   
ÿrŒ   rQ   c                 C  sì  |  ¡ D ]ï}|j}|rt|ƒd }tj ||¡}t||ƒr$t||dd�s/d}t| | ||¡ƒ‚| 	¡ r8t
|ƒ q| ¡ r’tj tj |¡|j¡}t||dd�s\d}t| | |j|j¡ƒ‚t||ƒsnd}t| | |j|j¡ƒ‚z| ||¡ W q ty‘ }	 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   Tr&   zQThe tar file ({}) has a file ({}) trying to install outside target directory ({})z/In the tar file %s the member %s is invalid: %sNrB   r1   )rz   rR   r   r   r   rH   r0   r   rJ   Úisdirr
   ÚissymrI   r~   rŒ   Ú_extract_memberÚ	Exceptionrx   ry   Úextractfiler‹   r{   rC   rL   rM   rN   Úutimer;   r5   )r=   r>   r€   rQ   r\   rS   r   rU   r)   rq   rV   rW   r   r   r   r|     s|   
ÿÿ
ÿÿ
ÿÿü€÷ü€÷
ÿ
€·r|   Ú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   r3   c                     s   t ˆ ˆˆd� d S )N)r?   )rX   r   ©r=   r>   Úzip_flattenr   r   Ú_unzipv  s   zunpack_file.<locals>._unzipc                     s   t ˆ ˆƒ d S ©N)r…   r   )r=   r>   r   r   Ú_untary  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   r3   )r   r   r*   rK   rw   r	   r   r   r   rD   Ú
is_zipfileri   Ú
is_tarfilerx   ÚerrorÚcriticalr   )r=   r>   r“   r—   r™   rš   r›   r   r•   r   Úunpack_fileh  s6   

ûrž   )r   r   )r   r   r   r   )r   r    r   r!   )r(   r   r)   r   r'   r!   r   r!   )r   r   r   r3   )r6   r   r   r!   )T)r=   r   r>   r   r?   r!   r   r3   )r=   r   r>   r   r   r3   )r€   r†   r‡   r^   r   r!   )
r=   r   r>   r   r€   r†   rQ   r!   r   r3   r˜   )r=   r   r>   r   r“   r”   r   r3   )*Ú__doc__Ú
__future__r   Úloggingr   rL   r9   rk   ri   rD   Úcollections.abcr   r   Úpip._internal.exceptionsr   Úpip._internal.utils.filetypesr   r   r   r	   Úpip._internal.utils.miscr
   Ú	getLoggerÚ__name__rx   ÚSUPPORTED_EXTENSIONSÚbz2ÚImportErrorÚdebugÚlzmar   r   r%   r0   r2   r5   r<   rX   r…   rŒ   r|   rž   r   r   r   r   Ú<module>   sT    
ÿÿ


ÿ



.
`
Yý