
    çg                     2   d dl mZ d dlmZmZmZmZmZmZm	Z	 d dl
Z
d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ  eeeeee          Z ej        dej        egeej                  Z eed	          Zed
d
ej        fd            Z G d de          ZdS )    )contextmanager)	CFUNCTYPEPOINTERc_int
c_longlongc_void_pcastcreate_string_bufferN)
open_files)AbstractArchiveFileSystem)
MemoryFile)DEFAULT_BLOCK_SIZEread_set_seek_callback
NO_OPEN_CBallc              #      K   t          |          t          t                     fd} fd}t          j        |          }t          |          }t          rt          j        }t          j        }	nRt          j
                            t          j                  }t          j
                            t          j                  }	t          j
                            ||          5 }
t          |
|           t          j        |
d|||	           t          j
                            |
          V  ddd           dS # 1 swxY w Y   dS )zRead an archive from a seekable file-like object.

    The `file` object must support the standard `readinto` and 'seek' methods.
    c                                                    }t          |t          t                              }|d<   |S )Nr   )readintor	   r   r   )	archive_pcontextptrptrlengthbufbuf_pfiles       ]/var/www/html/ai-engine/env/lib/python3.11/site-packages/fsspec/implementations/libarchive.py	read_funcz custom_reader.<locals>.read_func*   s9    s##fgh//00q	    c                 X                         ||                                           S )N)seektell)r   r   offsetwhencer   s       r   	seek_funcz custom_reader.<locals>.seek_func3   s%    		&&!!!yy{{r   N)r
   r	   r   ffiREAD_CALLBACKSEEK_CALLBACKnew_apir   NO_CLOSE_CB
libarchivereadOPEN_CALLBACKVOID_CBCLOSE_CALLBACKnew_archive_readr   	read_openArchiveRead)r   format_namefilter_name
block_sizer   r$   read_cbseek_cbopen_cbclose_cbr   r   r   s   `          @@r   custom_readerr9   !   s      z
*
*ChE          
 	**GI&&G ?.?///<<?11#+>>		)	)+{	C	C 5yy'222iwBBBo)))444445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5s   +A
EE	Ec                        e Zd ZdZdZdZdZddddef fd	Ze	d             Z
e fd	            Zd
 Z	 	 	 	 ddZ xZS )LibArchiveFileSystemay  Compressed archives as a file-system (read-only)

    Supports the following formats:
    tar, pax , cpio, ISO9660, zip, mtree, shar, ar, raw, xar, lha/lzh, rar
    Microsoft CAB, 7-Zip, WARC

    See the libarchive documentation for further restrictions.
    https://www.libarchive.org/

    Keeps file object open while instance lives. It only works in seekable
    file-like objects. In case the filesystem does not support this kind of
    file object, it is recommended to cache locally.

    This class is pickleable, but not necessarily thread-safe (depends on the
    platform). See libarchive documentation for details.
     r*   FrNc                 p    t                      j        | fi | |dk    rt          d          t          |t                    rBt          |fd|i|pi }t          |          dk    rt          d| d| d          |d         }|| _        |                                | _	        || _
        d	| _        d	S )
aB  
        Parameters
        ----------
        fo: str or file-like
            Contains ZIP, and must exist. If a str, will fetch file using
            :meth:`~fsspec.open_files`, which must return one file exactly.
        mode: str
            Currently, only 'r' accepted
        target_protocol: str (optional)
            If ``fo`` is a string, this value can be used to override the
            FS protocol inferred from a URL
        target_options: dict (optional)
            Kwargs passed when instantiating the target FS, if ``fo`` is
            a string.
        r=   z%Only read from archive files acceptedprotocol   zPath "z(" did not resolve to exactly one file: ""r   N)super__init__
ValueError
isinstancestrr   lenof	__enter__for4   	dir_cache)	selfrJ   modetarget_protocoltarget_optionsr4   kwargsfiles	__class__s	           r   rC   zLibArchiveFileSystem.__init__^   s    0 	(((((3;;DEEEb# 	rVVOV@TRTVVE5zzQ QRQQQQQ   qB,,..$r   c              #      K   | j                             d           t          | j         | j                  5 }|V  d d d            d S # 1 swxY w Y   d S )Nr   )r4   )rJ   r    r9   r4   )rL   arcs     r   _open_archivez"LibArchiveFileSystem._open_archive   s      Q47t??? 	3III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A

AAc                 l    t                                          |                              d          S )N/)rB   _strip_protocollstrip)clspathrR   s     r   rX   z$LibArchiveFileSystem._strip_protocol   s+     ww&&t,,33C888r   c           
      R   dddddddd| j         d S i | _         g }|                                 5 }|D ]j        sj        s| j                             d	 |                     t          j                            D                        fd
D             }j        rdnd|d<   |                    j                   || j         |d         <   	 d d d            n# 1 swxY w Y   | j                             d |                     |          D                        d S )NpathnamesizectimerM   uidgidmtime)namer^   createdrM   r`   ra   rb   c                     i | ]	}||d dd
S r   	directory)rc   r^   type .0dirnames     r   
<dictcomp>z2LibArchiveFileSystem._get_dirs.<locals>.<dictcomp>   s4       #  '1k!R!R  r   c                 >    i | ]}|t          |                   S ri   )getattr)rk   keyentryfieldss     r   rm   z2LibArchiveFileSystem._get_dirs.<locals>.<dictcomp>   s)    HHH#S'%55HHHr   rg   r   rh   rc   c                     i | ]	}||d dd
S rf   ri   rj   s     r   rm   z2LibArchiveFileSystem._get_dirs.<locals>.<dictcomp>   s4        '1kJJ  r   )	rK   rU   isdirisfileupdate_all_dirnamessetrc   append)rL   
list_namesrT   frq   rr   s       @@r   	_get_dirszLibArchiveFileSystem._get_dirs   s   
 
 >%F
!! 	.S . .{ 5< %% '+'9'9#ej//'J'J     IHHHHHHH+0;BKKF&	!!%*---,-qy)).	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.$ 	 #11*==  	
 	
 	
 	
 	
s   B%C%%C),C)rbTc                 h   |                      |          }|dk    rt          t                      }|                                 5 }|D ]B}	|	j        |k    r|	j        dk    r n(|	                    |	j                  D ]}
|
} nt          Cd d d            n# 1 swxY w Y   t          | ||          S )Nr}   r   )fsr[   data)	rX   NotImplementedErrorbytesrU   r]   r^   
get_blocksrD   r   )rL   r[   rM   r4   
autocommitcache_optionsrP   r   rT   rq   blocks              r   _openzLibArchiveFileSystem._open   s    ##D))4<<%%ww!! 	%S % %>T)):??E"--ej99 % %E DE$$ 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% T48888s   ABBB)r}   NTN)__name__
__module____qualname____doc__root_markerr?   cachabler   rC   r   rU   classmethodrX   r|   r   __classcell__)rR   s   @r   r;   r;   H   s         " KHH %% % % % % %N   ^
 9 9 9 9 [9'
 '
 '
X 9 9 9 9 9 9 9 9r   r;   )
contextlibr   ctypesr   r   r   r   r   r	   r
   r*   libarchive.ffir%   fsspecr   fsspec.archiver   fsspec.implementations.memoryr   fsspec.utilsr   r'   c_archive_p	check_intr   hasattrr(   	page_sizer9   r;   ri   r   r   <module>r      s   % % % % % %                                  4 4 4 4 4 4 4 4 4 4 4 4 + + + + + + 	*eXz5II s>s}   '#|
$
$ $)u #5 #5 #5 #5LM9 M9 M9 M9 M94 M9 M9 M9 M9 M9r   