
    *,hu"              	       
   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	 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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(y# e$ r ej7                  d       Y w xY w# e$ r ej7                  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/Resume-Scraper/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   2   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%   >   sG     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-   M   sL     GGOOI.M(JWW!!=*"=>F]""r   c                 N    t        j                  | dt                z  dz         y)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!    
 HHTE]_,,u46r   infoc                 r    | j                   dz	  }t        |xr t        j                  |      xr |dz        S )N   r/   )external_attrboolstatS_ISREG)r2   modes     r   zip_item_is_executabler:   `   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:   r1   )r;   r<   r=   zipfpzipleadingr2   namefndirmessagefpdestfps                r   
unzip_filerW   g   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{{32;;t#4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 3F'?FF'G ;G F$	 F'')GG G%c                 b   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}      }|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                  j5                  |             |
J t        |d      5 }t7        j8                  |
|       ddd       |
j;                          |j=                  ||       |j>                  dz  sFtA        |       S 	 |j;                          yc c}w # t,        $ r-}	t
        j                  d| |j                  |	       Y d}	~	d}	~	ww xY w# t0        t2        f$ r-}	t
        j                  d| |j                  |	       Y d}	~	d}	~	ww xY w# 1 sw Y   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 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)encodingr   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   tarmemberrP   rR   r   rT   excrU   rV   s               r   
untar_filerk      s    x~~  '8>>+;+D+DV+L			"	">	2			"	"=	1			"	"6	*;	
 
,,x
8C4!S^^=M"N66;;"NOnn& 0	MFB&r*1-77<<"-D&x64  (xx(PQQ||~4 ''50B 277??401~%$% 3&&r623
		&$';;&FtLa0	Md 			g #O" ! 	 NNI 	 	 !.1 	 NNI 	 	3 3 			s   ,L JB-L JL K)8L !L89L 3L L 	K!"K	L 	KL L "LL LL L	L L.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   realpathr[   rJ   r   rC   
is_zipfilerW   r^   
is_tarfiler	   r   r
   rk   r\   criticalr   )r;   r<   rl   s      r   unpack_filerr      s    
 ww)H))>>$$^4h'8X83D3DV3L/LM,,h'>>$$^n%D}%TU8X& 	+	
  "EhZ PQQr   )T)N))__doc__loggingr   rK   r7   r^   rC   typingr   r   r   r   pip._internal.exceptionsr   pip._internal.utils.filetypesr   r	   r
   r   pip._internal.utils.miscr   	getLogger__name__r\   SUPPORTED_EXTENSIONSbz2ImportErrordebuglzmaintr   strr   r6   r%   r-   r1   r:   rW   rk   rr    r   r   <module>r      s    	     + +  6  0			8	$ &6 0N*1M)
s 	C 	DI 	8C= T #3 # # #7S 7T 7> >T >+ + +d +d +\M M M Mf #'RRR 3-R 
	RM  0
LL./0  1
LL/01s$   	C %	C) C&%C&)DD