
    dh.                       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	 ddlZeez  ZddZddZddZ ddZ!ddZ"ddZ#ddZ$dddZ%ddZ&	 	 	 	 	 	 	 	 	 	 ddZ'	 d 	 	 	 	 	 	 	 d!dZ(y# e$ r ej9                  d	       Y cw xY w# e$ r ej9                  d
       Y uw xY w)"z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 availablec                 Z    t        j                  d      } t        j                  |        | S )zBGet the current umask which involves having to set it temporarily.r   )osumask)masks    _/var/www/html/vivango/api/ia/venv/lib/python3.12/site-packages/pip/_internal/utils/unpacking.pycurrent_umaskr   -   s    88A;DHHTNK    c                    | j                  d      j                  d      } d| v r=d| v r#| j                  d      | j                  d      k  sd| vr| j                  dd      S d| v r| j                  dd      S | dgS )N/\    )lstripfindsplitpaths    r   split_leading_dirr   4   sz    ;;s""4(D
d{	$))C.499T?:t4?Ozz#q!!	zz$""bzr   c                R    d}| D ]   }t        |      \  }}|s y||}||k7  s  y y)zyReturns true if all the paths have the same leading path name
    (i.e., everything is in one subdirectory in an archive)NFT)r   )pathscommon_prefixr   prefixrests        r   has_leading_dirr#   @   sG     M (.""M}$ r   c                    t         j                  j                  |       }t         j                  j                  |      }t         j                  j                  ||g      }||k(  S )zL
    Return true if the absolute path of target is within the directory
    )r   r   abspathcommonprefix)	directorytargetabs_directory
abs_targetr!   s        r   is_within_directoryr+   O   sL     GGOOI.M(JWW!!=*"=>F]""r   c                 $    dt                z  dz  S )Ni  I   )r    r   r   !_get_default_mode_plus_executabler/   Z   s    MO##e++r   c                @    t        j                  | t                      y)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   s    r   2set_extracted_file_to_default_mode_plus_executabler2   ^   s    
 HHT467r   c                r    | j                   dz	  }t        |xr t        j                  |      xr |dz        S )N   r-   )external_attrboolstatS_ISREG)infomodes     r   zip_item_is_executabler;   f   s6    #D <d+<u==r   c                   t        |       t        | d      }	 t        j                  |d      }t	        |j                               xr |}|j                         D ]  }|j                  }|}|rt        |      d   }t        j                  j                  ||      }t        j                  j                  |      }	t        ||      sd}
t        |
j                  | ||            |j!                  d      rt        |       t        |	       |j                  |      }	 t        |d      5 }t#        j$                  ||       ddd       |j'                          t)        |      st+        |        	 |j'                          y# 1 sw Y   FxY w# |j'                          t)        |      rt+        |       w w xY w# |j'                          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infolistfilenamer   r   r   joindirnamer+   r   formatendswithshutilcopyfileobjcloser;   r2   )rE   locationflattenzipfpzipleadingr9   namefndirmessagefpdestfps                r   
unzip_filerX   m   s    x4 E ooe5!#,,.1=gLLN 	OD==DB&t,Q/h+B''//"%C&x44  (xX(NOO{{;'23 XXd^Ob$ 76**2v67 HHJ-d3J2N7	O: 	7 7 HHJ-d3J2N 4 	sB   DG "F.F
FG *G 
F	F)F??G Gc                    t                j                         j                  d      s j                         j                  d      rd}n j                         j                  t              rd}n` j                         j                  t              rd}n: j                         j                  d      rd}nt
        j                  d        d	}t        j                   |d
      }	 t        |j                         D cg c]  }|j                   c}      }	 t        j                  t               |rj|j                         D ]W  }t        |j                        \  }}||_        |j                         s3t        |j                         \  }}	||k(  sQ|	|_        Y d fd}
|j#                  |
       |j)                          yc c}w # t$        $ r t'         ||       Y /w xY w# |j)                          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                |   | j                   }	 	  |       } | j                         r|dz  r	| _         | S d | _         | S # t        j                  $ r0 t        j                  d d dv rt        j
                  |       } n Y iw xY w# t        j                  $ r"}d}t        |j                  |            d }~ww xY w)N   >   r]   	      r]   
      r]         z%Invalid member in the tar file {}: {}r-   )
r:   tarfileLinkOutsideDestinationErrorsysversion_info
tar_filterTarErrorr   rH   isfile)	memberr   	orig_modeexcrU   data_filterdefault_mode_plus_executablerE   rM   s	        r   
pip_filterzuntar_file.<locals>.pip_filter   s    "KK	"!,VX!>2 ==?y5'8">FK  #'FKA #>> "++BQ/ 4  &-%7%7%IF! #" '' 	EG ,$ 		s0   	A   A B B BB B;B66B;)filterN)rn   tarfile.TarInfor   strreturnru   )r   lowerrI   r   r	   loggerwarningrg   r@   r#   
getmembersrR   rq   r/   r   islnklinkname
extractallAttributeError_untar_without_filterrL   )rE   rM   r:   tarrn   rQ   	name_lead	name_restlnk_leadlnk_restrs   rq   rr   s   ``         @@r   
untar_filer      s    x~~  '8>>+;+D+DV+L			"	">	2			"	"=	1			"	"6	*;	
 
,,x
8CC!S^^=M"N66;;"NO
:	8!--K ,M+N( "nn. 7F+<V[[+I(Iy"+FK||~->v-O*(#y0.6FO7% %N NN8JN7 			E #O  	D!(Hc7C	Dv 			sO   0G7 GG7 "G 2AG7 G7 %G7 G7 G41G7 3G44G7 7H	c                   |j                         D ]P  }|j                  }|rt        |      d   }t        j                  j                  ||      }t        ||      sd}t        |j                  | ||            |j                         rt        |       |j                         r	 |j                  ||       	 |j!                  |      }	t        t        j                  j'                  |             |	J t)        |d      5 }
t+        j,                  |	|
       ddd       |	j/                          |j1                  ||       |j2                  dz  sFt5        |       S y# t        $ r-}t        j                  d| |j                  |       Y d}~d}~ww xY w# t"        t$        f$ r-}t        j                  d| |j                  |       Y d}~d}~ww xY w# 1 sw Y   xY w)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-   )r{   rR   r   r   r   rF   r+   r   rH   isdirr   issym_extract_member	Exceptionry   rz   extractfileKeyErrorr   rG   r@   rJ   rK   rL   utimer:   r2   )rE   rM   r   rQ   rn   rS   r   rU   rp   rV   rW   s              r   r   r      s    .." 0I[["2&q)Bww||Hb)"8T20  $GNN8T8$LMM<<>t\\^##FD1__V, rwwt,->!>dD! /V""2v./HHJIIfd#{{U"B4Ha0I   	 EKK	 	 n- 	 EKK	 	/ /s<   (E&<FG&	F/"FFG."GGG'	c                   t         j                  j                  |       } |dk(  s8| j                         j	                  t
              st        j                  |       rt        | || j	                  d              y |dk(  sFt        j                  |       s1| j                         j	                  t        t        z   t        z         rt        | |       y t        j!                  d| ||       t#        d|       )Nzapplication/zipz.whl)rN   zapplication/x-gzipzZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz#Cannot determine archive format of )r   r   realpathrx   rI   r
   rA   
is_zipfilerX   rg   
is_tarfiler   r   r	   r   ry   criticalr   )rE   rM   content_types      r   unpack_filer   5  s    
 ww)H))>>$$^4h'8X83D3DV3L/LM,,h'>>$$^n%D}%TU8X& 	+	
  "EhZ PQQr   )rw   int)r   rv   rw   z	list[str])r   zIterable[str]rw   r6   )r'   rv   r(   rv   rw   r6   )r   rv   rw   None)r9   r   rw   r6   )T)rE   rv   rM   rv   rN   r6   rw   r   )rE   rv   rM   rv   rw   r   )
rE   rv   rM   rv   r   ztarfile.TarFilerQ   r6   rw   r   )N)rE   rv   rM   rv   r   z
str | Nonerw   r   ))__doc__
__future__r   loggingr   rJ   r7   ri   rg   rA   collections.abcr   r   pip._internal.exceptionsr   pip._internal.utils.filetypesr   r   r	   r
   pip._internal.utils.miscr   	getLogger__name__ry   SUPPORTED_EXTENSIONSbz2ImportErrordebuglzmar   r   r#   r+   r/   r2   r;   rX   r   r   r   r.   r   r   <module>r      sV   ! "  	   
   $  6  0			8	$ &6 0N*1M)
	#,8>+\]@7I7I7I 
7I 	7I
 
7Iz  $RRR R 
	Ri  0
LL./0  1
LL/01s$   !	B5 +	C 5CCC*)C*