
    eu"              	       .   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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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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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dedede
e         d
dfdZ(dS ) 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                  V    t          j        d          } t          j        |            | S )zBGet the current umask which involves having to set it temporarily.r   )osumask)masks    T/var/www/html/api/venv/lib/python3.11/site-packages/pip/_internal/utils/unpacking.pycurrent_umaskr   +   s!    8A;;DHTNNNK    pathc                 *   |                      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   2   s    ;;s""4((D
d{{	$))C..499T??::t4?O?Ozz#q!!!	zz$"""bzr   pathsc                 ^    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   	directorytargetc                     t           j                            |           }t           j                            |          }t           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-   M   sO     GOOI..M((JW!!=*"=>>F]""r   c                 V    t          j        | dt                       z  dz             dS )zx
    Make file present at path have execute for user/group/world
    (chmod +x) is no-op on windows per python docs
    i  I   N)r   chmodr   r   s    r   2set_extracted_file_to_default_mode_plus_executabler1   X   s-    
 HTE]__,,u466666r   infoc                 f    | j         dz	  }t          |ot          j        |          o|dz            S )N   r/   )external_attrboolstatS_ISREG)r2   modes     r   zip_item_is_executabler:   `   s7    #D <d++<u===r   Tfilenamelocationflattenc                 |   t          |           t          | d          }	 t          j        |d          }t	          |                                          o|}|                                D ]}|j        }|}|rt          |          d         }t          j
                            ||          }t          j
                            |          }	t          ||          s&d}
t          |
                    | ||                    |                    d          s|                    d          rt          |           t          |	           |                    |          }	 t          |d          5 }t#          j        ||           d	d	d	           n# 1 swxY w Y   |                                 t)          |          rt+          |           h# |                                 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infolistr;   r   r   r   joindirnamer-   r   formatendswithshutilcopyfileobjcloser:   r1   )r;   r<   r=   zipfpzipleadingr2   namefndirmessagefpdestfps                r   
unzip_filerW   g   sX    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{{3 O2;;t#4#4 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   EH% %G5FGF	GF	G"4H% 5H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                       }|
                                D ]}|j        }|rt          |          d         }t          j                            ||          }t!          ||          s&d}t#          |                    | ||                    |                                rt          |           |                                rQ	 |                    ||           # t,          $ r,}	t
                              d| |j        |	           Y d}	~	d}	~	ww xY w	 |                    |          }
nA# t0          t2          f$ r-}	t
                              d| |j        |	           Y d}	~	Pd}	~	ww xY wt          t          j                            |                     |
J t          |d          5 }t7          j        |
|           ddd           n# 1 swxY w Y   |
                                 |                    ||           |j        dz  rtA          |           
	 |                                 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 after being
    written.  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  )rQ   ).0members     r   
<listcomp>zuntar_file.<locals>.<listcomp>   s    "N"N"N66;"N"N"Nr   r   zQThe tar file ({}) has a file ({}) trying to install outside target directory ({})z/In the tar file %s the member %s is invalid: %sNrA   r/   )!r   lowerrJ   r   r
   loggerwarningtarfilerB   r%   
getmembersrQ   r   r   r   rG   r-   r   rI   isdirissym_extract_member	ExceptionextractfileKeyErrorAttributeErrorrH   rK   rL   rM   utimer9   r1   )r;   r<   r9   tarrP   r^   rR   r   rT   excrU   rV   s               r   
untar_filero      s    x~~  '' 8>>+;+;+D+DV+L+L 				"	">	2	2 				"	"=	1	1 					"	"6	*	* ;	
 	
 	
 
,x
8
8
8C4!"N"NS^^=M=M"N"N"NOOnn&& 0	M 0	MFB .&r**1-7<<"--D&x66 R4  (xx(P(PQQQ||~~ %M4     #M''5555  	 	 	 NNI 	   HHHH	00BB .1 	 	 	 NNI 	   HHHH	 27??400111~~~$%% 3&r62223 3 3 3 3 3 3 3 3 3 3 3 3 3 3


		&$''';& MFtLLLa0	Md 					s   C.M> H$#M> $
I."IM> IM> I43M> 4J2"J-'M> -J22AM> 5LM> L	M> L	AM> >Ncontent_typec                 J   t           j                            |           } |dk    s@|                                                     t
                    st          j        |           r(t          | ||                     d                      d S |dk    sPt          j
        |           s<|                                                     t          t          z   t          z             rt          | |           d S t                              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   realpathr`   rJ   r   rC   
is_zipfilerW   rc   
is_tarfiler	   r   r
   ro   ra   criticalr   )r;   r<   rp   s      r   unpack_filerv      s&   
 w))H)))>>$$^44 	*h'' 	* 	8X83D3DV3L3L/LMMMMMM,,,h'' 	->>$$^n%D}%TUU 	- 	8X&&&&& 	+	
 	
 	
   Ph P PQQQr   )T)N))__doc__loggingr   rK   r7   rc   rC   typingr   r   r   r   pip._internal.exceptionsr   pip._internal.utils.filetypesr   r	   r
   r   pip._internal.utils.miscr   	getLogger__name__ra   SUPPORTED_EXTENSIONSbz2ImportErrordebuglzmaintr   strr   r6   r%   r-   r1   r:   rW   ro   rv   r\   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s    	C 	DI 	 	 	 	8C= T    #3 # # # # # #7S 7T 7 7 7 7> >T > > > >+ + + +d +d + + + +\M M M M M M Mf #'R RRR 3-R 
	R R R R R Rs$   	A# #B ?B 	B B+*B+