
    nd                    b   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m	Z	 ddl
mZ  ej        d          Z ej        e           	 ddlZn!# e$ r ddlZ ej        d           dZY nw xY w G d de	          Z G d	 d
ej                  Zej        dfddZ	 dddZdej        fddZdS )z7
Unpack conda packages without using a temporary file.
    )annotationsN)Enum)	Generatorz@zstandard could not be imported. Running without .conda support.c                      e Zd ZdZdZd ZdS )CondaComponentpkginfoc                    | j         S N)value)selfs    Ilib/python3.11/site-packages/conda_package_streaming/package_streaming.py__str__zCondaComponent.__str__"   s
    z    N)__name__
__module____qualname__r   r	   r    r   r   r   r      s-        
CD    r   r   c                  0     e Zd Zed fd
Zd Zd Z xZS )TarfileNoSameOwner)umaskc               H     t                      j        |i | || _        dS )a  Open an (uncompressed) tar archive `name'. `mode' is either 'r' to
        read from an existing archive, 'a' to append data to an existing
        file or 'w' to create a new file overwriting an existing one. `mode'
        defaults to 'r'.
        If `fileobj' is given, it is used for reading or writing data. If it
        can be determined, `mode' is overridden by `fileobj's mode.
        `fileobj' is not closed, when TarFile is closed.
        N)super__init__r   )r   r   argskwargs	__class__s       r   r   zTarfileNoSameOwner.__init__'   s,     	$)&)))


r   c                    dS )z
        Override chown to be a no-op, since we don't want to preserve ownership
        here. (tarfile.TarFile only lets us toggle all of (chown, chmod, mtime))
        Nr   )r   tarinfo
targetpathnumeric_owners       r   chownzTarfileNoSameOwner.chown3   s	    
 	r   c                    	 t          j        ||j        d| j        z
  z             dS # t          $ r}t          j        d          |d}~ww xY w)zd
        Set file permissions of targetpath according to tarinfo, respecting
        umask.
        i  zcould not change modeN)oschmodmoder   OSErrortarfileExtractError)r   r   r    es       r   r%   zTarfileNoSameOwner.chmod:   se    
	GHZ1C!DEEEEE 	G 	G 	G&'>??QF	Gs   %) 
AAA)r   r   r   UMASKr   r"   r%   __classcell__)r   s   @r   r   r   &   sj        $) 
 
 
 
 
 
 
  G G G G G G Gr   r   Freturn>Generator[tuple[tarfile.TarFile, tarfile.TarInfo], None, None]c              #     K   	  || d          5 }|D ]}||fV  		 ddd           n# 1 swxY w Y   |r|                                   dS dS # |r|                                   w w xY w)z+
    Yield (tar, member) from fileobj.
    zr|)fileobjr&   N)close)r0   tarfile_openclosefdtarmembers        r   tar_generatorr6   E   s      \'555 	" " "6k!!!!"	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"  	MMOOOOO	 	7 	MMOOOO	s&   A *A .A .A A(c                (    d}t          | ||          S )a  
    Yield members from conda's embedded info/ tarball.

    For .tar.bz2 packages, yield all members.

    Yields (tar, member) tuples. You must only use the current member to
    prevent tar seeks and scans.

    To extract to disk, it's possible to call ``tar.extractall(path)`` on the
    first result and then ignore the rest of this generator. ``extractall`` takes
    care of some directory permissions/mtime issues, compared to ``extract`` or
    writing out the file objects yourself.
    r	   )stream_conda_component)filenamer0   	components      r   stream_conda_infor;   V   s      I!(GY???r   r:   CondaComponent | strc                   t          |                               d          rt          t          d          t	          j        |p|           }t          j                            |           	                    d          \  }}}| d| fd|
                                D             }|st          d d|            t          |          d	k    sJ t          j                                        |                    |d
                             }nJt          |                               d          rt!          j        |p| d          }nt#          d          t%          ||du           S )a  
    Yield members from .conda's embedded {component}- tarball. "info" or "pkg".

    For .tar.bz2 packages, yield all members.

    Yields (tar, member) tuples. You must only use the current member to
    prevent tar seeks and scans.

    To extract to disk, it's possible to call ``tar.extractall(path)`` on the
    first result and then ignore the rest of this generator. ``extractall`` takes
    care of some directory permissions/mtime issues, compared to ``extract`` or
    writing out the file objects yourself.
    z.condaNz(Cannot unpack `.conda` without zstandard.-c                H    g | ]}|j                                       |S r   )r9   
startswith).0r	   component_names     r   
<listcomp>z*stream_conda_component.<locals>.<listcomp>   s>     
 
 
dm.F.F~.V.V

 
 
r   zdidn't find z component in    r   z.tar.bz2rb)r&   zunsupported file extension)r3   )strendswith	zstandardRuntimeErrorzipfileZipFiler$   pathbasename
rpartitioninfolistLookupErrorlenZstdDecompressorstream_readeropenbz2
ValueErrorr6   )	r9   r0   r:   zffile_id_component_filenamereaderrC   s	           @r   r8   r8   j   s     8}}h'' 7IJJJ_W011((22==cBBA%1111
 
 
 
[[]]
 
 
 " 	WU^UU8UUVVV%&&!+++++--;;GG&q)**
 
 
X		
	+	+ 7'-XD9995666D9999r   )r-   r.   r   )r:   r<   r-   r.   )__doc__
__future__r   rV   r$   os.pathr(   rK   enumr   typingr   r   r+   rI   ImportErrorwarningswarnr   TarFiler   rU   r6   r;   r   r8   r   r   r   <module>rf      s    # " " " " " 



 				                	    OOOHMTUUUIII    T   G G G G G G G G@ -15    $ @ @ @ @ @* n>P$: $: $: $: $: $: $:s   
A A-,A-