
    3i                       S r SSKJr  SSKrSSKrSSK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  SSKrSrS	rS
r\R(                  S-
  S	-
  rSS jr " S S\R.                  5      r\S S SS.     SS jj5       rg)a  
Tools for creating ``.conda``-format archives.

Uses ``tempfile.SpooledTemporaryFile`` to buffer ``pkg-*.tar`` and
``info-*.tar``, then compress directly into an open `ZipFile` at the end.
`SpooledTemporaryFile` buffers the first 10MB of the package and its metadata in
memory, but writes out to disk for larger packages.

Uses more disk space than ``conda-package-handling`` (temporary uncompressed
tarballs of the package contents) but accepts streams instead of just
files-on-the-filesystem.
    )annotationsN)Iterator)contextmanager)Path)Callable         i   c                >    S=U l         U l        S=U l        U l        U $ )zt
Pass to ``tarfile.add(..., filter=anonymize)`` to anonymize uid/gid.

Does not anonymize mtime or any other field.
r    )uidgidunamegname)tarinfos    >lib/python3.13/site-packages/conda_package_streaming/create.py	anonymizer   )   s%     !"!GK'+$&&GMGMN    c                  b   ^  \ rS rSr% SrS\S'   S\S'   S S. SU 4S	 jjjrSU 4S
 jjrSrU =r	$ )CondaTarFile4   a5  
Subclass of :external+python:py:class:`tarfile.TarFile` that adds members to
a second ``info`` tar if they match ``is_info(name)``.

Create this with ``conda_builder(...)`` which sets up the component
archives, then wraps them into a ``.conda`` on exit.

Only useful for creating, not extracting ``.conda``.
tarfile.TarFileinfo_tarr   is_infoc                $    U R                  S5      $ Nzinfo/
startswith)names    r   <lambda>CondaTarFile.<lambda>F   s    T__W5r   )r   c               >   > [         TU ]  " U0 UD6  Xl        X l        g N)super__init__r   r   )selfr   r   argskwargs	__class__s        r   r%   CondaTarFile.__init__B   s!     	$)&) r   c                   > U R                  UR                  5      (       a  U R                  R                  XS9$ [        TU ]  X5      $ )aU  
Add the TarInfo object ``tarinfo`` to the archive. If ``fileobj`` is
given, it should be a binary file, and tarinfo.size bytes are read from
it and added to the archive. You can create TarInfo objects directly, or
by using ``gettarinfo()``.

If ``self.is_info(tarinfo.name)`` returns ``True``, add ``tarinfo`` to
``self.info_tar`` instead.
)fileobj)r   r   r   addfiler$   )r&   r   r,   r)   s      r   r-   CondaTarFile.addfileM   s?     <<%%==(((BB7?744r   )r   r   )r   r   r#   )
__name__
__module____qualname____firstlineno____doc____annotations__r%   r-   __static_attributes____classcell__)r)   s   @r   r   r   4   s9      6		 "	 	5 5r   r   c                 <    [         R                  " [        [        S9$ )N)levelthreads)	zstandardZstdCompressorZSTD_COMPRESS_LEVELZSTD_COMPRESS_THREADS r   r   r    r    d   s    	((!+@r   c                $    U R                  S5      $ r   r   )filenames    r   r    r    g   s    h6I6I'6Rr   zutf-8)
compressorr   encodingc             #  N  #    [        X S35      n[        R                  " 5        n[        R                  " 5        n[        R                  " USUS9 n[        USUUUS9 n	U	v   UR                  5         U	R                  5         UR                  5       n
UR                  5       nUR                  S5        UR                  S5        SSS5        SSS5        [        R                  " US[        R                  S9 nU" 5       nS	[        0nUR                  S
[        R                  " U5      5        UR!                  SU  S3SW["        :  S9 nUR%                  XSS9 n[&        R(                  " UR*                  U5        SSS5        SSS5        UR!                  SU  S3SW
["        :  S9 nUR%                  UU
SS9 n[&        R(                  " UR*                  U5        SSS5        SSS5        SSS5        SSS5        SSS5        g! , (       d  f       GNI= f! , (       d  f       GNS= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       Nu= f! , (       d  f       N~= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       g= f7f)aI  
Produce a ``TarFile`` subclass used to build a ``.conda`` package. The
subclass delegates ``addfile()`` to the ``info-`` component when ``is_info``
returns True.

When the context manager exits, ``{path}/{stem}.conda`` is written with
the component tar archives.

Args:
    stem: output filename without extension

    path: destination path for transmuted .conda package compressor: A
        function that creates instances of ``zstandard.ZstdCompressor()``.

    encoding: passed to TarFile constructor. Keep default "utf-8" for valid
        .conda.

Yields:
    ``CondaTarFile``
z.condaw)r,   moderB   )r,   rE   r   r   rB   r   Nx)compresslevelconda_pkg_format_versionzmetadata.jsonzpkg-z.tar.zst)force_zip64F)sizeclosefdzinfo-)r   tempfileSpooledTemporaryFiletarfileTarFiler   closetellseekzipfileZipFile
ZIP_STOREDCONDA_PACKAGE_FORMAT_VERSIONwritestrjsondumpsopenCONDA_ZIP64_LIMITstream_writershutilcopyfileobj_file)stempathrA   r   rB   output_path	info_filepkg_filer   pkg_tar	info_sizepkg_size
conda_filedata_compresspkg_metadatapkg_file_zip
pkg_streaminfo_file_zipinfo_streams                      r   conda_builderro   ]   sO    B tvV_-K%%'9%%'8 OOIC(Kx !! 
 MNNMMO!(I}}HNN1MM!) L. __!,,
  'LM68TULL1IJ 4&)!),=!=    "++  , ""8>>:>	 D6*!*->!>    #++!"! ,  !""9??K@3
5 	( 	('
  LKR  "  3
 
5 	(' 	('s   $J%JJH!A'H
	H,J<AI2H?	"H.H?		$I2-I!	?"I!I!	)I21J9J	J%

HH
H+&J.
H<8H?	?
I	I2
II!	!
I/+I22
J <J
J	J
J"J%)r   ztarfile.TarInfo)rA   z&Callable[[], zstandard.ZstdCompressor]r   zCallable[[str], bool]returnzIterator[CondaTarFile])r3   
__future__r   rX   r]   rN   rL   rS   collections.abcr   
contextlibr   pathlibr   typingr   r:   r<   r=   rV   ZIP64_LIMITr[   r   rO   r   ro   r>   r   r   <module>rw      s    #      $ %         ''73a7 &57?? &5R 	 &SaA	aA #aA aA aAr   