Ë
    ëÿæiž>  ã                   óÎ   — 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Zddlm	Z	 ddl
mZ ddlmZ  G d„ dej                  «      Z G d	„ d
e«      Z G d„ de«      Z G d„ d«      Zy)z
Post-processing hooks
é    N)ÚZipFile)ÚTarFileé   )Ú
get_loggerc                   ó”   — e Zd ZdZdd„Zeej                  d„ «       «       Zej                  d„ «       Z	ej                  d„ «       Z
d„ Zy)	ÚExtractorProcessoraà  
    Abstract base class for extractions from compressed archives.

    Subclasses can be used with :meth:`pooch.Pooch.fetch` and
    :func:`pooch.retrieve` to unzip a downloaded data file into a folder in the
    local data store. :meth:`~pooch.Pooch.fetch` will return a list with the
    names of the extracted files instead of the archive.

    Parameters
    ----------
    members : list or None
        If None, will unpack all files in the archive. Otherwise, *members*
        must be a list of file names to unpack from the archive. Only these
        files will be unpacked.
    extract_dir : str or None
        If None, files will be unpacked to the default location (a folder in
        the same location as the downloaded zip file, with a suffix added).
        Otherwise, files will be unpacked to ``extract_dir``, which is
        interpreted as a *relative path* (relative to the cache location
        provided by :func:`pooch.retrieve` or :meth:`pooch.Pooch.fetch`).

    Nc                 ó    — || _         || _        y ©N)ÚmembersÚextract_dir)Úselfr   r   s      úe/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/pooch/processors.pyÚ__init__zExtractorProcessor.__init__1   s   € ØˆŒØ&ˆÕó    c                  ó   — y)zš
        String appended to unpacked archive folder name.
        Only used if extract_dir is None.
        MUST BE IMPLEMENTED BY CHILD CLASSES.
        N© ©r   s    r   ÚsuffixzExtractorProcessor.suffix5   ó   � r   c                  ó   — y)zf
        Return all the members in the archive.
        MUST BE IMPLEMENTED BY CHILD CLASSES.
        Nr   )r   Úfnames     r   Ú_all_memberszExtractorProcessor._all_members>   r   r   c                  ó   — y)z�
        This method receives an argument for the archive to extract and the
        destination path.
        MUST BE IMPLEMENTED BY CHILD CLASSES.
        Nr   )r   r   r   s      r   Ú_extract_filez ExtractorProcessor._extract_fileE   r   r   c           
      óN  ‡ ‡— ‰ j                   €|‰ j                  z   ‰ _         n]|j                  t        j                  j
                  d¬«      d   }t        j                  j                  |‰ j                   «      ‰ _         ‰ j                  �‰ j                  s‰ j                  |«      }n‰ j                  }|dv s=t        j                  j                  ‰ j                   «      rt        ˆ fd„|D «       «      s=t        j                  ‰ j                   d¬«       ‰ j                  |‰ j                   «       g }t        j                  ‰ j                   «      D ]Ì  \  }}}	|	D ]Á  }
t        j                  j                  t        j                  j                  t        j                  j                  |‰ j                   «      |
«      «      Š‰ j                  �t!        ˆfd„‰ j                  D «       «      sŒ“|j#                  t        j                  j                  ||
«      «       ŒÃ ŒÎ |S )	a  
        Extract all files from the given archive.

        Parameters
        ----------
        fname : str
            Full path of the zipped file in local storage.
        action : str
            Indicates what action was taken by :meth:`pooch.Pooch.fetch` or
            :func:`pooch.retrieve`:

            * ``"download"``: File didn't exist locally and was downloaded
            * ``"update"``: Local file was outdated and was re-download
            * ``"fetch"``: File exists and is updated so it wasn't downloaded

        pooch : :class:`pooch.Pooch`
            The instance of :class:`pooch.Pooch` that is calling this.

        Returns
        -------
        fnames : list of str
            A list of the full path to all files in the extracted archive.

        r   )Úmaxsplitr   ©ÚupdateÚdownloadc              3   ó¬   •K  — | ]K  }t         j                  j                  t         j                  j                  ‰j                  |«      «      –— ŒM y ­wr
   )ÚosÚpathÚexistsÚjoinr   )Ú.0Úmr   s     €r   Ú	<genexpr>z.ExtractorProcessor.__call__.<locals>.<genexpr>u   s7   øè ø€ ð ÙKRÀa”—‘—‘œrŸw™wŸ|™|¨D×,<Ñ,<¸aÓ@×AÉ7ùs   ƒAAT)Úexist_okc              3   óz   •K  — | ]2  }‰j                  t        j                  j                  |«      «      –— Œ4 y ­wr
   )Ú
startswithr!   r"   Únormpath)r%   r&   Úrelpaths     €r   r'   z.ExtractorProcessor.__call__.<locals>.<genexpr>…   s/   øè ø€ ð /ÙEQÀ�G×&Ñ&¤r§w¡w×'7Ñ'7¸Ó':×;Á\ùs   ƒ8;)r   r   Úrsplitr!   r"   Úsepr$   r   r   r#   ÚallÚmakedirsr   Úwalkr+   r,   ÚanyÚappend)r   r   ÚactionÚpoochÚarchive_dirr   Úfnamesr"   Ú_ÚfilesÚfilenamer,   s   `          @r   Ú__call__zExtractorProcessor.__call__M   sœ  ù€ ð2 ×ÑÐ#Ø$ t§{¡{Ñ2ˆDÕàŸ,™,¤r§w¡w§{¡{¸Q˜,Ó?ÀÑBˆKÜ!Ÿw™wŸ|™|¨K¸×9IÑ9IÓJˆDÔð �<‰<Ð t§|¢|Ø×'Ñ'¨Ó.‰Gà—l‘lˆGàÐ-Ñ-Ü—G‘G—N‘N 4×#3Ñ#3Ô4Üó ÙKRóô ô
 �K‰K˜×(Ñ(°4Õ8Ø×Ñ˜u d×&6Ñ&6Ô7ð ˆÜ Ÿg™g d×&6Ñ&6Ö7‰NˆD�!�UÛ!�ÜŸ'™'×*Ñ*Ü—G‘G—L‘L¤§¡§¡°°t×7GÑ7GÓ!HÈ(ÓSó�ð —<‘<Ð'¬3ó /ØEIÇ\Â\ó/õ ,ð —M‘M¤"§'¡'§,¡,¨t°XÓ">Õ?ñ "ð 8ð ˆr   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚpropertyÚabcÚabstractmethodr   r   r   r;   r   r   r   r   r      sg   „ ñó.'ð Ø×Ññó ó ðð 	×Ññó ðð 	×Ññó ðó=r   r   c                   ó,   — e Zd ZdZed„ «       Zd„ Zd„ Zy)ÚUnzipa  
    Processor that unpacks a zip archive and returns a list of all files.

    Use with :meth:`pooch.Pooch.fetch` or :func:`pooch.retrieve` to unzip a
    downloaded data file into a folder in the local data store. The
    method/function will return a list with the names of the unzipped files
    instead of the zip archive.

    The output folder is ``{fname}.unzip``.

    Parameters
    ----------
    members : list or None
        If None, will unpack all files in the zip archive. Otherwise, *members*
        must be a list of file names to unpack from the archive. Only these
        files will be unpacked.
    extract_dir : str or None
        If None, files will be unpacked to the default location (a folder in
        the same location as the downloaded zip file, with the suffix
        ``.unzip`` added). Otherwise, files will be unpacked to
        ``extract_dir``, which is interpreted as a *relative path* (relative to
        the cache location provided by :func:`pooch.retrieve` or
        :meth:`pooch.Pooch.fetch`).

    c                  ó   — y)úl
        String appended to unpacked archive folder name.
        Only used if extract_dir is None.
        z.unzipr   r   s    r   r   zUnzip.suffix¨   ó   € ð r   c                 óf   — t        |d«      5 }|j                  «       cddd«       S # 1 sw Y   yxY w©z(Return all members from a given archive.ÚrN)r   Únamelist)r   r   Úzip_files      r   r   zUnzip._all_members°   s&   € ä�U˜CÔ  HØ×$Ñ$Ó&÷ !× Ò ús   �'§0c           
      ó  — t        |d«      5 }| j                  €.t        «       j                  d||«       |j	                  |¬«       n¨| j                  D ]™  }t        «       j                  d|||«       |j                  «       D �cg c]O  }t        j                  j                  |«      j                  t        j                  j                  |«      «      r|‘ŒQ }}|j	                  ||¬«       Œ› ddd«       yc c}w # 1 sw Y   yxY w)úo
        This method receives an argument for the archive to extract and the
        destination path.
        rJ   Nz"Unzipping contents of '%s' to '%s')r"   ú!Extracting '%s' from '%s' to '%s'©r   r"   )
r   r   r   ÚinfoÚ
extractallrK   r!   r"   r+   r*   )r   r   r   rL   ÚmemberÚnameÚsubdir_memberss          r   r   zUnzip._extract_fileµ   sí   € ô
 �U˜CÔ  HØ�|‰|Ð#Ü“×!Ñ!Ø8¸%Àôð ×#Ñ#¨Ð#Õ5à"Ÿlœl�FÜ“L×%Ñ%Ø;¸VÀUÈKôð %-×$5Ñ$5Ô$7ó&á$7˜DÜŸ7™7×+Ñ+¨DÓ1×<Ñ<¼R¿W¹W×=MÑ=MÈfÓ=UÔVò Ø$7ð #ð &ð ×'Ñ'°À[Ð'ÕQð! +÷ !Ð ùò$&÷% !Ð ús   �A8C>ÂAC9ÃC>Ã9C>Ã>DN©r<   r=   r>   r?   r@   r   r   r   r   r   r   rD   rD   �   s&   „ ñð4 ñó ðò'ó
Rr   rD   c                   ó,   — e Zd ZdZed„ «       Zd„ Zd„ Zy)ÚUntara  
    Processor that unpacks a tar archive and returns a list of all files.

    Use with :meth:`pooch.Pooch.fetch` or :func:`pooch.retrieve` to untar a
    downloaded data file into a folder in the local data store. The
    method/function will return a list with the names of the extracted files
    instead of the archive.

    The output folder is ``{fname}.untar``.


    Parameters
    ----------
    members : list or None
        If None, will unpack all files in the archive. Otherwise, *members*
        must be a list of file names to unpack from the archive. Only these
        files will be unpacked.
    extract_dir : str or None
        If None, files will be unpacked to the default location (a folder in
        the same location as the downloaded tar file, with the suffix
        ``.untar`` added). Otherwise, files will be unpacked to
        ``extract_dir``, which is interpreted as a *relative path* (relative to
        the cache location  provided by :func:`pooch.retrieve` or
        :meth:`pooch.Pooch.fetch`).
    c                  ó   — y)rF   z.untarr   r   s    r   r   zUntar.suffixð   rG   r   c                 ó´   — t        j                  |d«      5 }|j                  «       D �cg c]  }|j                  ‘Œ c}cddd«       S c c}w # 1 sw Y   yxY wrI   )r   ÚopenÚ
getmembersrT   )r   r   Útar_filerQ   s       r   r   zUntar._all_membersø   sG   € ä�\‰\˜% Ô%¨Ø*2×*=Ñ*=Ô*?Ó@Ñ*? $�D—I“IÐ*?Ñ@÷ &Ñ%ùÚ@÷ &Ð%ús   —AªA	½AÁ	AÁAc           
      óv  — t         j                  dk  ri nddi}t        j                  |d«      5 }| j                  €0t        «       j                  d||«        |j                  d
d|i|¤Ž n´| j                  D ]¥  }t        «       j                  d|||«       |j                  «       D �cg c]Y  }t        j                  j                  |j                  «      j                  t        j                  j                  |«      «      r|‘Œ[ }} |j                  d
||d	œ|¤Ž Œ§ ddd«       yc c}w # 1 sw Y   yxY w)rN   )é   é   ÚfilterÚdatarJ   Nz"Untarring contents of '%s' to '%s'r"   rO   rP   r   )ÚsysÚversion_infor   r[   r   r   rQ   rR   r\   r!   r"   r+   rT   r*   )r   r   r   Úfilter_kwargr]   rS   rQ   rU   s           r   r   zUntar._extract_fileý   s'  € ô
 !×-Ñ-°Ò7‘r¸hÈÐ=OˆÜ�\‰\˜% Ô%¨Ø�|‰|Ð#Ü“×!Ñ!Ø8¸%Àôð $�×#Ñ#ÑE¨ÐE¸ÓEà"Ÿlœl�FÜ“L×%Ñ%Ø;¸VÀUÈKôð %-×$7Ñ$7Ô$9ó&á$9˜DÜŸ7™7×+Ñ+¨D¯I©IÓ6×AÑAÜŸG™G×,Ñ,¨VÓ4ôò Ø$9ð #ð &ð (�H×'Ñ'ð Ø .°[ñØDPóð) +÷ &Ð%ùò(&÷) &Ð%ús   °A:D/Â*AD*ÄD/Ä*D/Ä/D8NrV   r   r   r   rX   rX   Õ   s&   „ ñð4 ñó ðòAó
$r   rX   c                   ó@   — e Zd ZdZdeeeedœZddddœZdd„Z	d	„ Z
d
„ Zy)Ú
Decompressa3  
    Processor that decompress a file and returns the decompressed version.

    Use with :meth:`pooch.Pooch.fetch` or :func:`pooch.retrieve` to decompress
    a downloaded data file so that it can be easily opened. Useful for data
    files that take a long time to decompress (exchanging disk space for
    speed).

    Supported decompression methods are LZMA (``.xz``), bzip2 (``.bz2``), and
    gzip (``.gz``).

    File names with the standard extensions (see above) can use
    ``method="auto"`` to automatically determine the compression method. This
    can be overwritten by setting the *method* argument.

    .. note::

        To unpack zip and tar archives with one or more files, use
        :class:`pooch.Unzip` and :class:`pooch.Untar` instead.

    The output file is ``{fname}.decomp`` by default but it can be changed by
    setting the ``name`` parameter.

    .. warning::

        Passing in ``name`` can cause existing data to be lost! For example, if
        a file already exists with the specified name it will be overwritten
        with the new decompressed file content. **Use this option with
        caution.**

    Parameters
    ----------
    method : str
        Name of the compression method. Can be "auto", "lzma", "xz", "bzip2",
        or "gzip".
    name : None or str
        Defines the decompressed file name. The file name will be
        ``{fname}.decomp`` if ``None`` (default) or the given name otherwise.
        Note that the name should **not** include the full (or relative) path,
        it should be just the file name itself.

    N)ÚautoÚlzmaÚxzÚgzipÚbzip2ri   rk   rl   )z.xzz.gzz.bz2c                 ó    — || _         || _        y r
   )ÚmethodrT   )r   rn   rT   s      r   r   zDecompress.__init__S  s   € ØˆŒØˆ�	r   c                 ó,  — | j                   €|dz   }nGt        j                  j                  t        j                  j	                  |«      | j                   «      }|dv st        j                  j                  |«      s~t        «       j                  d||| j                  «       | j                  |«      }t        |d«      5 }|j                  |«      5 }t        j                  ||«       ddd«       ddd«       |S |S # 1 sw Y   ŒxY w# 1 sw Y   |S xY w)aK  
        Decompress the given file.

        The output file will be either ``{fname}.decomp`` or the given *name*
        class attribute.

        Parameters
        ----------
        fname : str
            Full path of the compressed file in local storage.
        action : str
            Indicates what action was taken by :meth:`pooch.Pooch.fetch` or
            :func:`pooch.retrieve`:

            - ``"download"``: File didn't exist locally and was downloaded
            - ``"update"``: Local file was outdated and was re-download
            - ``"fetch"``: File exists and is updated so it wasn't downloaded

        pooch : :class:`pooch.Pooch`
            The instance of :class:`pooch.Pooch` that is calling this.

        Returns
        -------
        fname : str
            The full path to the decompressed file.
        Nz.decompr   z-Decompressing '%s' to '%s' using method '%s'.zw+b)rT   r!   r"   r$   Údirnamer#   r   rQ   rn   Ú_compression_moduler[   ÚshutilÚcopyfileobj)r   r   r4   r5   ÚdecompressedÚmoduleÚoutputÚ
compresseds           r   r;   zDecompress.__call__W  sß   € ð6 �9‰9ÐØ  9Ñ,‰LäŸ7™7Ÿ<™<¬¯©¯©¸Ó(>ÀÇ	Á	ÓJˆLØÐ+Ñ+´2·7±7·>±>À,Ô3OÜ‹L×ÑØ?ØØØ—‘ô	ð ×-Ñ-¨eÓ4ˆFÜ�l EÔ*¨fØ—[‘[ Ô'¨:Ü×&Ñ& z°6Ô:÷ (÷ +ð Ðˆ|Ð÷ (Ð'ú÷ +ð Ðús$   Ã D	ÃC=Ã)D	Ã=D	ÄD	Ä	Dc                 óv  — d}| j                   | j                  vr`d| j                   › dt        | j                  j                  «       «      › d�}| j                   dv rdj	                  ||g«      }t        |«      ‚| j                   dk(  r˜t        j                  j                  |«      d   }|| j                  vrLd	|› dt        | j                  j                  «       «      › d�}|d
v rdj	                  ||g«      }t        |«      ‚| j                  | j                  |      S | j                  | j                      S )a  
        Get the Python module compatible with fname and the chosen method.

        If the *method* attribute is "auto", will select a method based on the
        extension. If no recognized extension is in the file name, will raise a
        ValueError.
        z:To unpack zip/tar archives, use pooch.Unzip/Untar instead.zInvalid compression method 'z'. Must be one of 'z'.>   ÚtarÚzipÚ rh   éÿÿÿÿzUnrecognized file extension '>   ú.tarú.zip)
rn   ÚmodulesÚlistÚkeysr$   Ú
ValueErrorr!   r"   ÚsplitextÚ
extensions)r   r   Úerror_archivesÚmessageÚexts        r   rq   zDecompress._compression_moduleƒ  s1  € ð VˆØ�;‰;˜dŸl™lÑ*à.¨t¯{©{¨mð <#Ü#'¨¯©×(9Ñ(9Ó(;Ó#<Ð"=¸RðAð ð �{‰{˜nÑ,ØŸ(™( G¨^Ð#<Ó=�Ü˜WÓ%Ð%Ø�;‰;˜&Ò Ü—'‘'×"Ñ" 5Ó)¨"Ñ-ˆCØ˜$Ÿ/™/Ñ)à3°C°5ð 9'Ü'+¨D¯O©O×,@Ñ,@Ó,BÓ'CÐ&DÀBðHð ð Ð*Ñ*Ø!Ÿh™h¨°Ð'@ÓA�GÜ  Ó)Ð)Ø—<‘< §¡°Ñ 4Ñ5Ð5Ø�|‰|˜DŸK™KÑ(Ð(r   )rh   N)r<   r=   r>   r?   ri   rk   Úbz2r   r„   r   r;   rq   r   r   r   rg   rg   $  s6   „ ñ)ðV  T°¸tÈcÑR€GØ¨¸Ñ@€Jóò*óX)r   rg   )r?   rA   r!   rˆ   rk   ri   rr   rc   Úzipfiler   Útarfiler   Úutilsr   ÚABCr   rD   rX   rg   r   r   r   Ú<module>r�      sk   ðñó Û 	Û 
Û Û Û Û 
Ý Ý å ôq˜Ÿ™ô qôhERÐô ERôPLÐô L÷^{)ò {)r   