o
    "jc                     @   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                       sb   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
dd Z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           	   
      sL  t  jd
i | |pi }t|tr#tj|fd|i|| _| j }|d u rd }z(t|dr3|j}nt|dr<|j	}nt|drE|j
}nt|drP| d }W n tyk } ztd|  W Y d }~nd }~ww |d urt|}td| d|  |d urt| |}|| _|| _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open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__r   [/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/fsspec/implementations/tar.pyr      sF   	





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   sz   | j d urd S dd | | j D | _ | j D ] }| }|d d|d< t|d d|d< || j |d < qd S )Nc                 S   s   i | ]	}||d ddqS )r   r   )r   sizer,   r   ).0dirnamer   r   r+   
<dictcomp>l   s    z+TarFileSystem._get_dirs.<locals>.<dictcomp>r   r-   r,   r   )	r!   Z_all_dirnamesr	   getnames
getmembersr.   r1   r/   r0   )r%   memberr   r   r   r+   	_get_dirsg   s   
zTarFileSystem._get_dirsrbc                 K   s>   |dkrt d| j| \}}|d dkrt 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+   _openv   s   zTarFileSystem._openc                 C   s   | j   dS )z;Commits any write changes to the file. Done on ``del`` too.N)r	   closer%   r   r   r+   rD   ~   s   zTarFileSystem.closec                 C   sH   t | dr|   | `t | dr t | jdr"| jd d d  d S d S d S )Nr	   r   __exit__)r   rD   r	   r   rF   rE   r   r   r+   __del__   s   
zTarFileSystem.__del__)r   NNNN)r=   )__name__
__module____qualname____doc__Zroot_markerr   Zcachabler   r$   r<   rC   rD   rG   __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    

