o
    dôj  ã                	   @   s²   d dl Z d dlmZ d dlZd dlZd dlZd dlmZ ed Z	de
de
defdd„Zdd	e
d
e
dB dee
 fdd„Zd	e
d
e
dee
 fdd„Zd	e
d
e
de	dee
 fdd„ZdS )é    N)ÚLiteral)Úrúr:gzúr:bz2Ú	directoryÚtargetÚreturnc                 C   s,   t  | ¡}t  |¡}| |tj ¡p||kS ©N)ÚospÚrealpathÚ
startswithÚosÚsep)r   r   Zabs_directoryZ
abs_target© r   úc/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/gdown/extractall.pyÚ_is_within_directory   s   

r   ÚpathÚtoc                 C   sŠ   |du r	t  | ¡}|  d¡rt| |d�S |  d¡rd}n"|  d¡s&|  d¡r)d}n|  d	¡s3|  d
¡r6d}ntd| › d�ƒ‚t| ||d�S )a¥  Extract archive file.

    Parameters
    ----------
    path:
        Path of archive file to be extracted.
    to:
        Directory to which the archive file will be extracted.
        If None, it will be set to the parent directory of the archive file.

    Raises
    ------
    ValueError
        If the archive format is unsupported, or if an archive member would
        extract outside the target directory.
    Nz.zip)r   r   z.tarr   z.tar.gzz.tgzr   z.tar.bz2z.tbzr   zCould not extract 'z&' as no appropriate extractor is found©r   r   Útar_mode)r
   ÚdirnameÚendswithÚ_extractall_zipÚ
ValueErrorÚ_extractall_tarr   r   r   r   Ú
extractall   s   



ÿr   c                    s’   t  | d¡�2}dd„ | ¡ D ƒ}|D ]}t ˆ |¡}tˆ |d�s*td|› dˆ › �ƒ‚q|jˆ d� W d   ƒ n1 s;w   Y  ‡ fdd„|D ƒS )	Nr   c                 S   s   g | ]}t  |¡‘qS r   )r
   Únormpath©Ú.0Únamer   r   r   Ú
<listcomp>8   s    z#_extractall_zip.<locals>.<listcomp>©r   r   úArchive member 'ú*' would extract outside target directory: ©r   c                    ó   g | ]}t  ˆ |¡‘qS r   ©r
   Újoinr   ©r   r   r   r    A   ó    )ÚzipfileÚZipFileÚnamelistr
   r'   r   r   r   )r   r   ÚfÚnamesÚmemberÚmember_pathr   r(   r   r   6   s   ÿÿÿ÷
r   r   c                    s  t j| |d��i}tjdkr|jˆ dd� nK| ¡ D ]@}| ¡ s#| ¡ r,td|j	› d�ƒ‚| 
¡ s8| ¡ s8| ¡ rAtd|j	› d�ƒ‚t ˆ |j	¡}tˆ |d�sYtd|j	› d	ˆ › �ƒ‚q|jˆ d
� dd„ | ¡ D ƒ}W d   ƒ n1 ssw   Y  ‡ fdd„|D ƒS )N)r   Úmode)é   é   Údata)r   Úfilterr"   z6' is a link, which is not allowed for security reasonsz>' is a special file, which is not allowed for security reasonsr!   r#   r$   c                 S   s   g | ]}t  |j¡‘qS r   )r
   r   r   )r   Úmr   r   r   r    [   r)   z#_extractall_tar.<locals>.<listcomp>c                    r%   r   r&   r   r(   r   r   r    ]   r)   )ÚtarfileÚopenÚsysÚversion_infor   Ú
getmembersÚissymÚislnkr   r   ÚischrÚisblkÚisfifor
   r'   r   )r   r   r   r-   r/   r0   r.   r   r(   r   r   D   s0   
ÿÿ
ÿÿÿêr   r	   )r   Úos.pathr   r
   r9   r7   r*   Útypingr   Z_TarReadModeÚstrÚboolr   Úlistr   r   r   r   r   r   r   Ú<module>   s     %"