U
    9%e                     @   sd   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 dddZ	e 
dZG d	d
 d
eZdS )    N)AbstractArchiveFileSystem)compr)infer_compressionfile	directory)   0   5tarc                       sH   e Zd ZdZdZdZdZd fdd	Zdd	 Zd
d Z	dddZ
  ZS )TarFileSystemzzCompressed Tar archives as a file-system (read-only)

    Supports the following formats:
    tar.gz, tar.bz2, tar.xz
     r	   FNc           	   
      sH  t  jf | |pi }t|trBtj|fd|i|| _| j }|d krd }zPt|drb|j}n:t|drt|j	}n(t|dr|j
}nt|dr| d }W n2 tk
r } ztd|  W 5 d }~X Y nX |d k	rt|}td| d|  |d k	rt| |}|| _|| _tj| jd	| _d | _|| _d | _|   d S )
Nprotocoloriginalpathnameinfoz:Unable to determine file name, not inferring compression: zInferred compression z from file name )fileobj)super__init__
isinstancestrfsspecopenZofhasattrr   r   r   r   	Exceptionloggerwarningr   r   Z_fo_reffotarfileTarFiler	   	dir_cacheindex_storeindex_index)	selfr   r    Ztarget_optionsZtarget_protocolcompressionkwargsr   ex	__class__ Y/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/fsspec/implementations/tar.pyr      s@    	






zTarFileSystem.__init__c                 C   sV   i }| j D ]@}| }t|d d|d< | d d}||jf||< q
|| _d S )Ntyper   r   /)r	   get_infotypemapgetrstripoffset_datar!   )r#   outtir   r   r)   r)   r*   r"   [   s    
zTarFileSystem._indexc                 C   sh   | j d k	rd S dd | | j D | _ | j D ].}| }t|d d|d< || j |d < q4d S )Nc                 S   s"   i | ]}|d  |d  dddqS )r,   r   r   )r   sizer+   r)   ).0dirnamer)   r)   r*   
<dictcomp>l   s    z+TarFileSystem._get_dirs.<locals>.<dictcomp>r+   r   r   )r   Z_all_dirnamesr	   getnames
getmembersr-   r.   r/   )r#   memberr   r)   r)   r*   	_get_dirsg   s    
zTarFileSystem._get_dirsrbc                 K   s>   |dkrt d| j| \}}|d dkr2t d| j|S )Nr<   z#Read-only filesystem implementationr+   r   zCan only handle regular files)
ValueErrorr!   r	   extractfile)r#   r   moder%   detailsoffsetr)   r)   r*   _openu   s    zTarFileSystem._open)r   NNNN)r<   )__name__
__module____qualname____doc__Zroot_markerr   Zcachabler   r"   r;   rB   __classcell__r)   r)   r'   r*   r
      s        Br
   )loggingr   r   Zfsspec.archiver   Zfsspec.compressionr   Zfsspec.utilsr   r.   	getLoggerr   r
   r)   r)   r)   r*   <module>   s   

