
    EZj5                       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Z(	 d"	 	 	 	 	 	 	 d#dZ)y# e$ r ej9                  d	       Y gw xY w# e$ r ej9                  d
       Y yw 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    _C:\Users\Rodrigo\frota-trucks-cliente\python\Lib\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#   @   sB     M(.""M}$  r   c                    t         j                  j                  |       }t         j                  j                  |      }||k(  xs" |j                  |t         j                  z         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)	directorytargetabs_directory
abs_targets       r   is_within_directoryr,   O   sO    
 GGOOI.M(J&W**?*?PRPVPV@V*WWr   c                 $    dt                z  dz  S )Ni  I   )r    r   r   !_get_default_mode_plus_executabler0   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   chmodr0   r   s    r   2set_extracted_file_to_default_mode_plus_executabler3   ^   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<   r3   )rF   locationflattenzipfpzipleadingr:   namefndirmessagefpdestfps                r   
unzip_filerY   m   sp    x4 E ooe5!#,,.1=gLLND==DB&t,Q/h+B''//"%C&x44  (xX(NOO{{;'23 XXd^Ob$6**2v6 ( HHJ-d3J2N7 #: 	 ( 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   rI   isfile)	memberr   	orig_modeexcrV   data_filterdefault_mode_plus_executablerF   rN   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)ro   tarfile.TarInfor   strreturnrv   )r   lowerrJ   r   r	   loggerwarningrh   rA   r#   
getmembersrS   rr   r0   r   islnklinkname
extractallAttributeError_untar_without_filterrM   )rF   rN   r;   tarro   rR   	name_lead	name_restlnk_leadlnk_restrt   rr   rs   s   ``         @@r   
untar_filer      s    x~~  '8>>+;+D+DV+L			"	">	2			"	"=	1			"	"6	*;	
 
,,x
8CC!S^^=M"N=M66;;=M"NO
:	8!--K ,M+N( "nn.F+<V[[+I(Iy"+FK||~->v-O*(#y0.6FO /% %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   rG   rH   rS   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                P   |j                         D ]  }|j                  }|rt        |      d   }t        j                  j                  ||      }t        ||      sd}t        |j                  | ||            |j                         rt        |       |j                         rRt        ||      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}~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|   rS   r   r   r   rG   r,   r   rI   isdirr   issymr   r~   _extract_member	Exceptionrz   r{   extractfiler   r   rH   rA   rK   rL   rM   utimer;   r3   )rF   rN   r   rR   ro   rT   r   rV   rq   rW   rX   s              r   r   r   	  s    .."[["2&q)Bww||Hb)"8T20  $GNN8T8$LMM<<>t\\^+C84  (NN8V[[&//J ##FD1__V, rwwt,->!>dD!V""2v. "HHJIIfd#{{U"B4Hq #0  	 EKK	 	 n- 	 EKK	 	 "!s<   &F$:GH$	G-"GGH,"HHH%	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)rO   )rY   )rF   rN   zip_flattens   r   _unzipzunpack_file.<locals>._unzip\  s    8X{;r   c                     t                y N)r   )rF   rN   s   r   _untarzunpack_file.<locals>._untar_  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 )rx   None)r   r   realpathrJ   ry   r
   r   r   r	   rB   
is_zipfilerh   
is_tarfilerz   errorcriticalr   )rF   rN   content_typer   r   r   r   r   s   ``     @r   unpack_filer   N  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   )rx   int)r   rw   rx   z	list[str])r   zIterable[str]rx   r7   )r(   rw   r)   rw   rx   r7   )r   rw   rx   r   )r:   r   rx   r7   )T)rF   rw   rN   rw   rO   r7   rx   r   )rF   rw   rN   rw   rx   r   )r   tarfile.TarFiler   rv   rx   r7   )
rF   rw   rN   rw   r   r   rR   r7   rx   r   r   )rF   rw   rN   rw   r   z
str | Nonerx   r   )*__doc__
__future__r   loggingr   rK   r8   rj   rh   rB   collections.abcr   r   pip._internal.exceptionsr   pip._internal.utils.filetypesr   r   r	   r
   pip._internal.utils.miscr   	getLogger__name__rz   SUPPORTED_EXTENSIONSbz2ImportErrordebuglzmar   r   r#   r,   r0   r3   r<   rY   r   r   r   r   r/   r   r   <module>r      sb   ! "  	   
   $  6  0			8	$ &6 0N*1M)
	X,8>+\]@BIBIBI 
BI 	BI
 
BIP  $/N/N/N /N 
	/N[	  0
LL./0  1
LL/01s$   !	B9 +	C 9CCC.-C.