
    3iw                        S r SSKJr  SSKrSSKrSSKJr  SSKJr  SSK	J
r
  SSKJrJr  S	S
/r\" \S5      r S     SS jjrSS jrg)zh
Extract package to directory, with checks against tar members extracting outside
the target directory.
    )annotationsN)	Generator)ELOOP)Path   )
exceptionspackage_streamingextract_streamextract
tar_filterc                  ^^^ [         R                  R                  T5      mU4S jmU  HS  u  mnUU4S jn TU" 5       S.n[        (       a  U=(       d    SUS'   TR                  " S0 UD6  U R                  5         MU     g! [
         a0  nUR                  [        :X  a  [        R                  " 5       Uee SnAff = f)z
Pipe ``stream_conda_component`` output here to extract every member into
dest_dir.

For ``.conda`` will need to be called twice (for info and pkg components);
for ``.tar.bz2`` every member is extracted.
c                   > [         R                  R                  [         R                  R                  TU 5      5      n[         R                  R	                  TU45      nUT:H  $ N)ospathrealpathjoin
commonpath)name
abs_targetprefixdest_dirs      ?lib/python3.13/site-packages/conda_package_streaming/extract.pyis_within_dest_dir*extract_stream.<locals>.is_within_dest_dir"   sJ    WW%%bggll8T&BC
##Xz$:;!!    c               3     >#    T HA  n T" U R                   5      (       d#  [        R                  " SU R                    35      eU v   MC     g 7f)Nzcontains unsafe path: )r   r   SafetyError)memberr   tar_files    r   checked_members'extract_stream.<locals>.checked_members)   sA     ")&++66$003I&++1WXX #s   A	A)r   membersfully_trustedfilterN )r   r   r   HAS_TAR_FILTER
extractallOSErrorerrnor   r   CaseInsensitiveFileSystemErrorclose)	streamr   r   _r!   tar_argser   r    s	    `     @@r   r
   r
      s     ww)H"
 !		 !)_5FGH~%/%B?"+(+ 	/ "  	ww% ??AqH	s   5B
B=+B88B=c                   U(       d   S5       e[        U 5      R                  S5      (       a5  [        R                  R                  [        R                  R
                  /nO[        R                  R                  /nSnU(       d  [        U S5      nSn U H#  n[        R                  " XUS9n[        Xa5        M%     U(       a  UR                  5         gg! U(       a  UR                  5         f f = f)zw
Extract all components of conda package to dest_dir.

fileobj: must be seekable if provided, if a ``.conda`` package.
zdest_dir is requiredz.condaFrbT)	componentN)
strendswithr	   CondaComponentpkginfoopenstream_conda_componentr
   r,   )filenamer   fileobj
componentsclosefdr3   r-   s          r   r   r   A   s     +++8
8}h'',,00,,11


 (66::;
Gx&#I&==YF 6,	 $ MMO 7MMO s   )C C2r   )r-   z2Generator[tuple[tarfile.TarFile, tarfile.TarInfo]]r   z
Path | strr   z
str | None)NN)__doc__
__future__r   r   tarfilecollections.abcr   r*   r   pathlibr    r   r	   __all__hasattrr'   r
   r   r&   r   r   <module>rG      sa   
 # 	  %   +Y
',/ "*>** *Zr   