o
    fN)j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/finance.cargoinsureonline.com/_shared/backend-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}zt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|rt| q|  t|rt| 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\}}||_| rt|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sJ t|d}
t|	|
 W d   n1 sw   Y  |	  ||| |jd@ rt| 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 )zUnpack ``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