
    鴀j9                       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d2dZd3dZd4dZ ddd5dZ!d2dZ"d6dZ#d7d!Z$d8d9d&Z%d:d'Z&d;d,Z'd<d.Z(	 d=d>d1Z)dS )?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 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    g/workspace/show-city-briefing-agent/.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   Fresolve_symlinks	directorytargetr+   c               P   |r?t           j                            |           }t           j                            |          }n>t           j                            |           }t           j                            |          }||k    p!|                    |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)r,   r-   r+   abs_directory
abs_targets        r   is_within_directoryr5   O   s      -((33W%%f--

	22W__V,,
&W**?*?PRPV@V*W*WWr   c                 ,    dt                       z  dz  S )Ni  I   )r    r   r   !_get_default_mode_plus_executabler9   c   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   chmodr9   r    s    r   2set_extracted_file_to_default_mode_plus_executabler=   g   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   r7   )external_attrr$   statS_ISREG)r>   modes     r   zip_item_is_executablerE   o   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infolistrF   r!   r   r   joindirnamer5   r   formatendswithshutilcopyfileobjcloserE   r=   )rF   rG   rH   zipfpzipleadingr>   namefndirmessagefpdestfps                r   
unzip_filerb   v   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 r8   )r\   ).0members     r   
<listcomp>zuntar_file.<locals>.<listcomp>   s    "N"N"N66;"N"N"Nr   rh   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   >   rl   	      rl   
      rl         z%Invalid member in the tar file {}: {}r7   )
rD   tarfileLinkOutsideDestinationErrorsysversion_info
tar_filterTarErrorr   rT   isfile)	rh   r   	orig_modeexcr_   data_filterdefault_mode_plus_executablerF   rG   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)rh   rj   r   r   r   rj   )r   lowerrU   r   r	   loggerwarningrv   rM   r)   
getmembersr   r9   r!   r\   islnklinkname
extractallAttributeError_untar_without_filterrX   )rF   rG   rD   tarr[   rh   	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.TarFiletarinforj   c                L   t           j                            t           j                            |j                  |j                  }t           j                            |          }|                    dd          }	 |                     |           dS # t          $ r Y dS w xY w)zGCheck if the file pointed to by the symbolic link is in the tar archiver   r   TF)
r   r   rR   rS   r\   r   normpathreplace	getmemberKeyError)r   r   r   s      r   is_symlink_target_in_tarr     s    w||BGOOGL997;KLLHw))Hc**Hht   uus   >B 
B#"B#r[   c                   |                                 D ]}|j        }|rt          |          d         }t          j                            ||          }t          ||          rt          ||d          s&d}t          |                    | ||                    |	                                rt          |           |                                rt          j                            t          j                            |          |j                  }t          ||d          s0d}t          |                    | |j        |j                            t          ||          s0d}t          |                    | |j        |j                            	 |                    ||           # t           $ r-}	t"                              d| |j        |	           Y d}	~	d}	~	ww xY w	 |                    |          }
nA# t(          t*          f$ r-}	t"                              d| |j        |	           Y d}	~	)d}	~	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t9          |           dS )	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: %sNrL   r7   )r   r\   r!   r   r   rR   r5   r   rT   isdirr   issymrS   r   r   _extract_member	Exceptionr   r   extractfiler   r   rM   rV   rW   rX   utimerD   r=   )rF   rG   r   r[   rh   r]   r   r_   r-   r~   r`   ra   s               r   r   r     sn    .."" II II[ 	*"2&&q)Bw||Hb))
 #8T22 	N:MdT;
 ;
 ;
 	N0  $GNN8T8$L$LMMM<<>> 8	It\\^^ 6	I W\\"'//$"7"7IIF&x$OOO 4  (NN8V[&/JJ   ,C88 4  (NN8V[&/JJ  ##FD1111 	 	 	 EK	   	__V,,n- 	 	 	 EK	   	 rwt,,--->>>dD!! /V"2v.../ / / / / / / / / / / / / / /HHJJJIIfd###{U" IB4HHHSII IIsB   F44
G+>"G&&G+/HI"H>>IJ((J,	/J,	content_type
str | Nonec                    t           j                                                             d           d fd}d fd}|dk    r
 |            S |dk    r
 |            S                                                      t
                    r
 |            S                                                      t          t          z   t          z             r
 |            S t          j
                   }t          j                   }|r|s
 |            S |r|s
 |            S |r|rt                              d            t                              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.whlr   r:   c                 ,    t                      d S )N)rH   )rb   )rF   rG   zip_flattens   r   _unzipzunpack_file.<locals>._unzipv  s    8X{;;;;;;r   c                 (    t                      d S N)r   )rF   rG   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 N)r   r:   )r   r   r/   rU   r   r
   r   r   r	   rN   
is_zipfilerv   
is_tarfiler   errorcriticalr   )rF   rG   r   r   r   r   r   r   s   ``     @r   unpack_filer   h  s    w))H''///K< < < < < < < <' ' ' ' ' ' ' (((vxx+++vxx~~  00 vxx~~  .!@=!PQQ vxx #H--J#H--J * vxx * vxx Bj B6AAA
OO	'   L(LL
M
MMr   )r   r   )r   r   r   r   )r"   r#   r   r$   )r,   r   r-   r   r+   r$   r   r$   )r   r   r   r:   )r>   r   r   r$   )T)rF   r   rG   r   rH   r$   r   r:   )rF   r   rG   r   r   r:   )r   r   r   rj   r   r$   )
rF   r   rG   r   r   r   r[   r$   r   r:   r   )rF   r   rG   r   r   r   r   r:   )*__doc__
__future__r   loggingr   rV   rB   rx   rv   rN   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)   r5   r9   r=   rE   rb   r   r   r   r   r8   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   	 	 	 	     >CX X X X X X(, , , ,8 8 8 8> > > >+ + + + +\] ] ] ]@   SI SI SI SIr  $/N /N /N /N /N /N /Ns$   	A) )BB
	B B10B1