
    Wh.                       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j        e          Zeez   Z	 ddlZeez  Zn # e$ r e                    d	           Y nw xY w	 ddlZeez  Zn # e$ r e                    d
           Y nw xY wd,dZd-dZd.dZ d/dZ!d,dZ"d0dZ#d1dZ$d2d3d#Z%d4d$Z&d5d(Z'	 d6d7d+Z(dS )8z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                 V    t          j        d          } t          j        |            | S )zBGet the current umask which involves having to set it temporarily.r   )osumask)masks    o/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/pip/_internal/utils/unpacking.pycurrent_umaskr   -   s!    8A;;DHTNNNK    pathstr	list[str]c                *   |                      d                               d          } d| v rJd| 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   s    r   split_leading_dirr!   4   s    ;;s""4((D
d{{	$))C..499T??::t4?O?Ozz#q!!!	zz$"""bzr   pathsIterable[str]boolc                ^    d}| D ]'}t          |          \  }}|s dS ||}||k    r dS (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rests        r   has_leading_dirr)   @   sa     M  (.. 	55""MM}$$55 %4r   	directorytargetc                    t           j                            |           }t           j                            |          }t           j                            ||g          }||k    S )zL
    Return true if the absolute path of target is within the directory
    )r   r   abspathcommonprefix)r*   r+   abs_directory
abs_targetr'   s        r   is_within_directoryr1   O   sO     GOOI..M((JW!!=*"=>>F]""r   c                 ,    dt                       z  dz  S )Ni  I   )r    r   r   !_get_default_mode_plus_executabler5   Z   s    MOO##e++r   Nonec                H    t          j        | 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   chmodr5   r    s    r   2set_extracted_file_to_default_mode_plus_executabler9   ^   s#    
 HT46677777r   infor   c                f    | j         dz	  }t          |ot          j        |          o|dz            S )N   r3   )external_attrr$   statS_ISREG)r:   modes     r   zip_item_is_executablerA   f   s7    #D <d++<u===r   Tfilenamelocationflattenc                R   t          |           t          | d          }	 t          j        |d          }t	          |                                          o|}|                                D ]}|j        }|}|rt          |          d         }t          j
                            ||          }t          j
                            |          }	t          ||          s&d}
t          |
                    | ||                    |                    d          rt          |           t          |	           |                    |          }	 t          |d          5 }t#          j        ||           ddd           n# 1 swxY w Y   |                                 t)          |          rt+          |           S# |                                 t)          |          rt+          |           w w xY w	 |                                 dS # |                                 w xY 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infolistrB   r!   r   r   joindirnamer1   r   formatendswithshutilcopyfileobjcloserA   r9   )rB   rC   rD   zipfpzipleadingr:   namefndirmessagefpdestfps                r   
unzip_filer^   m   sD    x4  E oe555!#,,..11=gLLNN 	O 	OD=DB 0&t,,Q/h++B'//"%%C&x44 P4  (xX(N(NOOO{{;'' O23 XXd^^Ob$ 76*2v6667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 HHJJJ-d33 OJ2NNN HHJJJ-d33 OJ2NNNNO5	O: 	sH   D.H G F6GF	G	F	
G4H 5G66H H&c                    t                                                                          d          s'                                                     d          rd}n                                                     t                    rd}nv                                                     t                    rd}nG                                                     d          rd}nt
                              d            d	}t          j         |d
          }	 t          d |
                                D                       }	 t          j        t                      |rm|
                                D ]X}t          |j                  \  }}||_        |                                r$t          |j                  \  }}	||k    r|	|_        Yd fd}
|                    |
           n"# t$          $ r t'           ||           Y nw xY w|                                 dS # |                                 w xY 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                    g | ]	}|j         
S r4   )rX   ).0members     r   
<listcomp>zuntar_file.<locals>.<listcomp>   s    "N"N"N66;"N"N"Nr   rd   tarfile.TarInfor   r   r   c                   | j         }	 	  |           } nB# t          j        $ r0 t          j        d d         dv rt          j        |           } n Y nw xY wn<# t          j        $ r*}d}t          |                    |                    d }~ww xY w| 	                                r|dz  r| _         nd | _         | S )N   >   rh   	      rh   
      rh         z%Invalid member in the tar file {}: {}r3   )
r@   tarfileLinkOutsideDestinationErrorsysversion_info
tar_filterTarErrorr   rP   isfile)	rd   r   	orig_modeexcr[   data_filterdefault_mode_plus_executablerB   rC   s	        r   
pip_filterzuntar_file.<locals>.pip_filter   s   "K	"!,VX!>!>"> " " "+BQB/ 4   &-%7%I%IFF! #F" ' 	 	 	EG ,$   		 ==?? 'y5'8 '">FKK #'FKs2    A <AA AA B*%BB)filterN)rd   rf   r   r   r   rf   )r   lowerrQ   r   r	   loggerwarningrr   rI   r)   
getmembersr{   r5   r!   rX   islnklinkname
extractallAttributeError_untar_without_filterrT   )rB   rC   r@   tarrW   rd   	name_lead	name_restlnk_leadlnk_restr}   r{   r|   s   ``         @@r   
untar_filer      sr    x~~  '' 8>>+;+;+D+DV+L+L 				"	">	2	2 				"	"=	1	1 					"	"6	*	* ;	
 	
 	
 
,x
8
8
8CC!"N"NS^^=M=M"N"N"NOO
:	8!-K ,M+N+N( 
7 "nn.. 7 7F+<V[+I+I(Iy"+FK||~~ 7->v-O-O*(#y00.6FO% % % % % % % % %N NN8JN7777q  	D 	D 	D!(Hc7CCCCC	Dv 					s1   "+H0 G8 BH0 8HH0 HH0 0Ir   tarfile.TarFilerW   c                B   |                                 D ]}|j        }|rt          |          d         }t          j                            ||          }t          ||          s&d}t          |                    | ||                    |	                                rt          |           |                                rQ	 |                    ||           # t          $ r,}t                              d| |j        |           Y d}~d}~ww xY w	 |                    |          }	nA# t"          t$          f$ r-}t                              d| |j        |           Y d}~Pd}~ww xY wt          t          j                            |                     |	J t)          |d          5 }
t+          j        |	|
           ddd           n# 1 swxY w Y   |	                                 |                    ||           |j        dz  rt5          |           
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: %sNrH   r3   )r   rX   r!   r   r   rN   r1   r   rP   isdirr   issym_extract_member	Exceptionr   r   extractfileKeyErrorr   rO   rI   rR   rS   rT   utimer@   r9   )rB   rC   r   rW   rd   rY   r   r[   rz   r\   r]   s              r   r   r      s    .."" 0I 0I[ 	*"2&&q)Bw||Hb))"8T22 	N0  $GNN8T8$L$LMMM<<>> %	It\\^^ #	I##FD1111 	 	 	 EK	   	__V,,n- 	 	 	 EK	   	 rwt,,--->>>dD!! /V"2v.../ / / / / / / / / / / / / / /HHJJJIIfd###{U" IB4HHHa0I 0IsB   C
D&"DDD,,E*="E%%E*-GG	G	content_type
str | Nonec                J   t           j                            |           } |dk    s@|                                                     t
                    st          j        |           r(t          | ||                     d                      d S |dk    sPt          j
        |           s<|                                                     t          t          z   t          z             rt          | |           d S t                              d| ||           t#          d|           )Nzapplication/zipz.whl)rD   zapplication/x-gzipzZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz#Cannot determine archive format of )r   r   realpathr   rQ   r
   rJ   
is_zipfiler^   rr   
is_tarfiler   r   r	   r   r   criticalr   )rB   rC   r   s      r   unpack_filer   5  s&   
 w))H)))>>$$^44 	*h'' 	* 	8X83D3DV3L3L/LMMMMMM,,,h'' 	->>$$^n%D}%TUU 	- 	8X&&&&& 	+	
 	
 	
   Ph P PQQQr   )r   r   )r   r   r   r   )r"   r#   r   r$   )r*   r   r+   r   r   r$   )r   r   r   r6   )r:   r   r   r$   )T)rB   r   rC   r   rD   r$   r   r6   )rB   r   rC   r   r   r6   )
rB   r   rC   r   r   r   rW   r$   r   r6   )N)rB   r   rC   r   r   r   r   r6   ))__doc__
__future__r   loggingr   rR   r>   rt   rr   rJ   collections.abcr   r   pip._internal.exceptionsr   pip._internal.utils.filetypesr   r   r	   r
   pip._internal.utils.miscr   	getLogger__name__r   SUPPORTED_EXTENSIONSbz2ImportErrordebuglzmar   r!   r)   r1   r5   r9   rA   r^   r   r   r   r4   r   r   <module>r      s   ! ! " " " " " "  				   



   $ $ $ $ $ $       6 6 6 6 6 6            0 / / / / /		8	$	$ &6 0JJJN* 0 0 0
LL./////01KKKM) 1 1 1
LL/000001   	 	 	 	   # # # #, , , ,8 8 8 8> > > >+ + + + +\] ] ] ]@7I 7I 7I 7Iz  $R R R R R R Rs$   	A) )BB
	B B10B1