
    y/Yh.              
       N   d 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	m
Z
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
efdZde d
e
e    fdZ!de	e    d
e"fdZ#de de d
e"fdZ$d
efdZ%de d
dfdZ&ded
e"fdZ'd!de de de"d
dfdZ(de de d
dfdZ)de de dejT                  de"d
df
dZ+	 d"de de dee    d
dfd Z,y# e$ r ej9                  d       Y w xY w# e$ r ej9                  d	       Y w xY w)#zUtilities related archives.
    N)IterableListOptional)ZipInfo)InstallationError)BZ2_EXTENSIONSTAR_EXTENSIONSXZ_EXTENSIONSZIP_EXTENSIONS)
ensure_dirzbz2 module is not availablezlzma module is not availablereturnc                  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/profi_bot/bot/venv/lib/python3.12/site-packages/pip/_internal/utils/unpacking.pycurrent_umaskr   ,   s    88A;DHHTNK    pathc                     | 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r   s    r   split_leading_dirr   3   sz    ;;s""4(D
d{	$))C.499T?:t4?Ozz#q!!	zz$""bzr   pathsc                 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   )r    common_prefixr   prefixrests        r   has_leading_dirr%   ?   sB     M(.""M}$  r   	directorytargetc                     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)r&   r'   abs_directory
abs_targetr#   s        r   is_within_directoryr-   N   sL     GGOOI.M(JWW!!=*"=>F]""r   c                  $    dt                z  dz  S )Ni  I   )r    r   r   !_get_default_mode_plus_executabler1   Y   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   chmodr1   r   s    r   2set_extracted_file_to_default_mode_plus_executabler4   ]   s    
 HHT467r   infoc                 r    | j                   dz	  }t        |xr t        j                  |      xr |dz        S )N   r/   )external_attrboolstatS_ISREG)r5   modes     r   zip_item_is_executabler=   e   s6    #D <d+<u==r   filenamelocationflattenc                    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      s|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infolistr>   r   r   r   joindirnamer-   r   formatendswithshutilcopyfileobjcloser=   r4   )r>   r?   r@   zipfpzipleadingr5   namefndirmessagefpdestfps                r   
unzip_filerZ   l   s{    x4 E ooe5!#,,.1=gLLND==DB&t,Q/h+B''//"%C&x44  (xX(NOO{{32;;t#423 XXd^Ob$6**2v6 ( HHJ-d3J2N7 #: 	 ( HHJ-d3J2N 4 	sB   DG 3F'?FF'G ;G F$	 F'')GG G%c                 d    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t        j"                  dt$        dt        j"                  f 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)encodingmemberr   r   c                 |   | 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`   	   rc   r`   
      r`         z%Invalid member in the tar file {}: {}r/   )
r<   tarfileLinkOutsideDestinationErrorsysversion_info
tar_filterTarErrorr   rL   isfile)	r^   r   	orig_modeexcrW   data_filterdefault_mode_plus_executabler>   r?   s	        r   
pip_filterzuntar_file.<locals>.pip_filter   s    "KK	"!,VX!>4 ==?y5'8">FK  #'FKC #>> "++BQ/ 4  &-%7%7%IF! #" '' 	EG ,$ 		s0   	A   A B B BB B;B66B;)filterN)r   lowerrM   r   r
   loggerwarningrl   rE   r%   
getmembersrT   ru   r1   r   islnklinknameTarInfostr
extractallAttributeError_untar_without_filterrP   )r>   r?   r<   tarr^   rS   	name_lead	name_restlnk_leadlnk_restrw   ru   rv   s   ``         @@r   
untar_filer      s    x~~  '8>>+;+D+DV+L			"	">	2			"	"=	1			"	"6	*;	
 
,,x
8CD!S^^=M"N=M66;;=M"NO
;	8!--K ,M+N( "nn.F+<V[[+I(Iy"+FK||~->v-O*(#y0.6FO /&7?? &# &'// & &P NN8JN7 			G #O  	D!(Hc7C	Dx 			sP   0H G;H "H  2AH H AH ;H  HH HH H/r   rS   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: %sNrD   r/   )r|   rT   r   r   r   rJ   r-   r   rL   isdirr   issym_extract_member	Exceptionrz   r{   extractfileKeyErrorr   rK   rE   rN   rO   rP   utimer<   r4   )r>   r?   r   rS   r^   rU   r   rW   rt   rX   rY   s              r   r   r      s    .."[["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 #   	 EKK	 	 n- 	 EKK	 	 "!s<   (E&<FG&	F/"FFG."GGG'	content_typec                    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)r@   zapplication/x-gzipzZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz#Cannot determine archive format of )r   r   realpathry   rM   r   rF   
is_zipfilerZ   rl   
is_tarfiler	   r   r
   r   rz   criticalr   )r>   r?   r   s      r   unpack_filer   5  s    
 ww)H))>>$$^4h'8X83D3DV3L/LM,,h'>>$$^n%D}%TU8X& 	+	
  "EhZ PQQr   )T)N)-__doc__loggingr   rN   r:   rn   rl   rF   typingr   r   r   r   pip._internal.exceptionsr   pip._internal.utils.filetypesr   r	   r
   r   pip._internal.utils.miscr   	getLogger__name__rz   SUPPORTED_EXTENSIONSbz2ImportErrordebuglzmaintr   r   r   r9   r%   r-   r1   r4   r=   rZ   r   TarFiler   r   r0   r   r   <module>r      s    	   
   + +  6  0			8	$ &6 0N*1M)
s 	C 	DI 	8C= T #3 # # #,3 ,8S 8T 8> >T >+ + +d +d +\^ ^ ^ ^B7I7I7I 
7I 	7I
 
7Iz #'RRR 3-R 
	Rk  0
LL./0  1
LL/01s$   	C/ )	D /DDD$#D$