
    yi              	           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Zdde
d	e
dz  dee
   fd
Zde
d	e
dee
   fdZde
d	e
de	dee
   fdZy)    N)Literal)rr:gzr:bz2	directorytargetreturnc                     t        j                  |       }t        j                  |      }|j                  |t        j                  z         xs ||k(  S N)osprealpath
startswithossep)r   r   abs_directory
abs_targets       D/home/ubuntu/.local/lib/python3.12/site-packages/gdown/extractall.py_is_within_directoryr      sB    LL+Mf%J  !78WJ-<WW    pathtoc                 b   |t        j                  |       }| j                  d      rt        | |      S | j                  d      rd}nY| j                  d      s| j                  d      rd}n4| j                  d      s| j                  d	      rd
}nt	        d|  d      t        | ||      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.
    z.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   s      r   
extractallr       s    " 
z[[}}VDR00}}V	y	!T]]6%:	z	"dmmF&;!$'MN
 	
 h??r   c                 d   t        j                  | d      5 }|j                         }|D ]6  }t        j                  ||      }t        ||      r't        d| d|        |j                  |       d d d        D cg c]  }t        j                  ||       c}S # 1 sw Y   -xY wc c}w )Nr   r   r   Archive member '*' would extract outside target directory: r   )zipfileZipFilenamelistr   joinr   r   r    )r   r   fnamesmembermember_pathnames          r   r   r   6   s    	s	# 	q

 	F((2v.K'"[I &vh /))+. 	 	
"	 ,114CHHR11	 	 2s   9B!$B!B-!B*r   c                 4   t        j                  | |      5 }t        j                  dk\  r|j	                  |d       n|j                         D ]  }|j                         s|j                         rt        d|j                   d      |j                         s |j                         s|j                         rt        d|j                   d      t        j                  ||j                        }t        ||      rt        d|j                   d	|        |j	                  |
       |j                         D cg c]  }|j                    }}d d d        D cg c]  }t        j                  ||       c}S c c}w # 1 sw Y   2xY wc c}w )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%   )tarfileopensysversion_infor    
getmembersissymislnkr   r.   ischrisblkisfifor   r)   r   r   )	r   r   r   r*   r,   r-   mr+   r.   s	            r   r   r   D   si   	4h	/ 11w&LLbL0,,. <<>V\\^$*6;;- 8D E  <<>V\\^v}}$*6;;- 8D E  "hhr6;;7+bM$*6;;- 8--/D2 " LLbL!!"0A00-10 ,114CHHR11 1-1 10 2s+   C*F	A F	FF	$FF		Fr   )r   os.pathr   r   r7   r5   r&   typingr   _TarReadModestrboolr   listr    r   r    r   r   <module>rG      s    	  
   +,XC X X X"@S "@cDj "@DI "@J2# 23 249 22# 23 2, 249 2r   