
    5>qj9                       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	 	 	 	 	 	 	 ddZ!ddZ"ddZ#ddZ$dd dZ%d!dZ&d"dZ'	 	 	 	 	 	 	 	 	 	 d#dZ(	 d$	 	 	 	 	 	 	 d%dZ)y# e$ r ej9                  d	       Y qw xY w# e$ r ej9                  d
       Y w 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    \/opt/rentech/trading_bot/.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   Fresolve_symlinksc               R   |r?t         j                  j                  |       }t         j                  j                  |      }n>t         j                  j                  |       }t         j                  j                  |      }||k(  xs" |j	                  |t         j
                  z         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)	directorytargetr%   abs_directory
abs_targets        r   is_within_directoryr/   O   sz     ((3WW%%f-
	2WW__V,
&W**?*?PRPVPV@V*WWr   c                 $    dt                z  dz  S )Ni  I   )r    r   r   !_get_default_mode_plus_executabler3   c   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   chmodr3   r   s    r   2set_extracted_file_to_default_mode_plus_executabler6   g   s    
 HHT467r   c                r    | j                   dz	  }t        |xr t        j                  |      xr |dz        S )N   r1   )external_attrboolstatS_ISREG)infomodes     r   zip_item_is_executabler?   o   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?   r6   )rI   locationflattenzipfpzipleadingr=   namefndirmessagefpdestfps                r   
unzip_filer\   v   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   >   ra   	      ra   
      ra         z%Invalid member in the tar file {}: {}r1   )
r>   tarfileLinkOutsideDestinationErrorsysversion_info
tar_filterTarErrorr   rL   isfile)	memberr   	orig_modeexcrY   data_filterdefault_mode_plus_executablerI   rQ   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)rr   tarfile.TarInfor   strreturnry   )r   lowerrM   r   r	   loggerwarningrk   rD   r#   
getmembersrV   ru   r3   r   islnklinkname
extractallAttributeError_untar_without_filterrP   )rI   rQ   r>   tarrr   rU   	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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   t         j                  j                  t         j                  j                  |j                        |j
                        }t         j                  j                  |      }|j                  dd      }	 | j                  |       y# t        $ r Y yw xY w)zGCheck if the file pointed to by the symbolic link is in the tar archiver   r   TF)
r   r   rJ   rK   rV   r   normpathreplace	getmemberKeyError)r   tarinfor   s      r   is_symlink_target_in_tarr     sy    ww||BGGOOGLL97;K;KLHww)Hc*Hh s   B 	B"!B"c                |   |j                         D ]$  }|j                  }|rt        |      d   }t        j                  j                  ||      }t        ||      rt        ||d      sd}t        |j                  | ||            |j                         rt        |       |j                         rt        j                  j                  t        j                  j                  |      |j                        }t        ||d      s2d}t        |j                  | |j                  |j                              t        ||      s2d}t        |j                  | |j                  |j                              	 |j                  ||       ~	 |j'                  |      }
t        t        j                  j                  |             |
J t-        |d      5 }t/        j0                  |
|       ddd       |
j3                          |j5                  ||       |j6                  dz  st9        |       ' y# t         $ r-}	t"        j%                  d| |j                  |	       Y d}	~	Zd}	~	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   Tr$   zQThe tar file ({}) has a file ({}) trying to install outside target directory ({})z/In the tar file %s the member %s is invalid: %sNrC   r1   )r   rV   r   r   r   rJ   r/   r   rL   isdirr   issymrK   r   r   _extract_member	Exceptionr}   r~   extractfiler   r   rD   rN   rO   rP   utimer>   r6   )rI   rQ   r   rU   rr   rW   r   rY   r,   rt   rZ   r[   s               r   r   r     s\    .." II[["2&q)Bww||Hb)
 #8T2:MdT;
0  $GNN8T8$LMM<<>t\\^ WW\\"''//$"7IF&x$O4  (NN8V[[&//J  ,C84  (NN8V[[&//J ##FD1__V, rwwt,->!>dD! /V""2v./HHJIIfd#{{U"B4HSIIR  	 EKK	 	 n- 	 EKK	 	/ /s<   ;H:I3J2:	I0"I++I03J/"J**J/2J;	c                |    t         j                  j                           j                  d       d	 fd}d	 fd}|dk(  r |       S |dk(  r |       S  j	                         j                  t
              r |       S  j	                         j                  t        t        z   t        z         r |       S t        j                         }t        j                         }|r	|s |       S |r	|s |       S |r|rt        j                  d        t        j                  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.whlc                 "    t                y )N)rR   )r\   )rI   rQ   zip_flattens   r   _unzipzunpack_file.<locals>._unzipv  s    8X{;r   c                     t                y N)r   )rI   rQ   s   r   _untarzunpack_file.<locals>._untary  s    8X&r   z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 )r{   None)r   r   r'   rM   r|   r
   r   r   r	   rE   
is_zipfilerk   
is_tarfiler}   errorcriticalr   )rI   rQ   content_typer   r   r   r   r   s   ``     @r   unpack_filer   h  s    ww)H''//K<' ((x++x~~  0x~~  .!@=!PQx ##H-J##H-J*x*xj6A
OO	' A(L
MMr   )r{   int)r   rz   r{   z	list[str])r   zIterable[str]r{   r:   )r+   rz   r,   rz   r%   r:   r{   r:   )r   rz   r{   r   )r=   r   r{   r:   )T)rI   rz   rQ   rz   rR   r:   r{   r   )rI   rz   rQ   rz   r{   r   )r   tarfile.TarFiler   ry   r{   r:   )
rI   rz   rQ   rz   r   r   rU   r:   r{   r   r   )rI   rz   rQ   rz   r   z
str | Noner{   r   )*__doc__
__future__r   loggingr   rN   r;   rm   rk   rE   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#   r/   r3   r6   r?   r\   r   r   r   r   r2   r   r   <module>r      s   ! "  	   
   $  6  0			8	$ &6 0N*1M)
	  >CXXX6:X	X(,8>+\]@SISISI 
SI 	SI
 
SIr  $/N/N/N /N 
	/NO
  0
LL./0  1
LL/01s$   !	C +	C CCC87C8