
    7Th                     <   S SK Jr  S SKJrJrJrJrJrJrJ	r	  S SK
r
S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  \" \\\\\5      r\R                  " S\R,                  \/\\R.                  5      r\" \S	5      r\S
S
\R6                  4S j5       r " S S\5      rg)    )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              #     ^ ^^#    [        U5      m[        T[        5      mUUU 4S jnU 4S jn[        R                  " U5      n[        U5      n[        (       a!  [        R                  n[        R                  n	OZ[        R                  R                  [        R                  5      n[        R                  R                  [        R                  5      n	[        R                  R                  X5       n
[        X5        [        R                   " U
SXU	5        [        R                  R#                  U
5      v   SSS5        g! , (       d  f       g= f7f)z~Read an archive from a seekable file-like object.

The `file` object must support the standard `readinto` and 'seek' methods.
c                 f   > TR                  T5      n[        U[        [        5      5      nTUS'   U$ )Nr   )readintor	   r   r   )	archive_pcontextptrptrlengthbufbuf_pfiles       Y/var/www/auris/envauris/lib/python3.13/site-packages/fsspec/implementations/libarchive.py	read_func custom_reader.<locals>.read_func*   s0    s#fgh/0q	    c                 F   > TR                  X#5        TR                  5       $ )N)seektell)r   r   offsetwhencer   s       r   	seek_func 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_readerr;   !   s      z
*ChE
 	*GI&Gw..??////<??11#++>		)	)+	Cyy2iwBoo)))44 
D	C	Cs   C0E5AE;	E
EEc                      ^  \ rS rSrSrSrSrSrSSSS\4U 4S jjr	\
S	 5       r\U 4S
 j5       rS r    SS jrSrU =r$ )LibArchiveFileSystemH   aM  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                 >  > [         TU ]  " U 40 UD6  US:w  a  [        S5      e[        U[        5      (       a=  [        U4SU0U=(       d    0 D6n[        U5      S:w  a  [        SU SU S35      eUS   nXl        UR                  5       U l	        XPl
        S	U l        g	)
a  
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__for6   	dir_cache)	selfrM   modetarget_protocoltarget_optionsr6   kwargsfiles	__class__s	           r   rF   LibArchiveFileSystem.__init__^   s    0 	((3;DEEb#rVOV@TRTVE5zQ RD HqQ  qB,,.$r   c              #      #    U R                   R                  S5        [        U R                   U R                  S9 nUv   S S S 5        g ! , (       d  f       g = f7f)Nr   )r6   )rM   r!   r;   r6   )rO   arcs     r   _open_archive"LibArchiveFileSystem._open_archive   s9     Q477t?3I @??s   :AA
	A

AAc                 @   > [         TU ]  U5      R                  S5      $ )N/)rE   _strip_protocollstrip)clspathrU   s     r   r]   $LibArchiveFileSystem._strip_protocol   s      w&t,33C88r   c                    SSSSSSSS.nU R                   b  g 0 U l         / nU R                  5        nU H  nUR                  (       d  UR                  (       d  M'  U R                   R	                  U R                  [        UR                  5      5       Vs0 s H	  nXUS	S
S._M     sn5        U Vs0 s H  of[        XAU   5      _M     nnUR                  (       a  S
OSUS'   UR                  UR                  5        XpR                   US   '   M     S S S 5        U R                   R	                  U R                  U5       Vs0 s H	  nXUS	S
S._M     sn5        g s  snf s  snf ! , (       d  f       NX= fs  snf )NpathnamesizectimerP   uidgidmtime)namerd   createdrP   rf   rg   rh   r   	directory)ri   rd   typer   rl   ri   )
rN   rY   isdirisfileupdate_all_dirnamessetri   getattrappend)rO   fields
list_namesrX   entrydirnamekeyfs           r   	_get_dirsLibArchiveFileSystem._get_dirs   sg   
 >>%
!S{{5<<%% (,'9'9#ejj/'J'JG  1k!RR'J BHH#'%55H+0;;KF&	!!%**-,-qy)  "$ 	  $11*==G 1kJJ=	

 I "!&s1   A%E&E'E&2E!
A
E&E7
E&&
E4c                 d   U R                  U5      nUS:w  a  [        e[        5       nU R                  5        nU HP  n	U	R                  U:w  a  M  U	R
                  S:X  a    O-U	R                  U	R
                  5       H  n
U
n  MJ     [        e   S S S 5        [        XUS9$ ! , (       d  f       N= f)Nrbr   )fsr`   data)	r]   NotImplementedErrorbytesrY   rc   rd   
get_blocksrG   r   )rO   r`   rP   r6   
autocommitcache_optionsrS   r   rX   rv   blocks              r   _openLibArchiveFileSystem._open   s     ##D)4<%%w!S>>T)::?"--ejj9E D : %$  " T488 "!s   AB!!
B/)r6   rN   rM   rK   )r}   NTN)__name__
__module____qualname____firstlineno____doc__root_markerrB   cachabler   rF   r   rY   classmethodr]   rz   r   __static_attributes____classcell__)rU   s   @r   r=   r=   H   sv    " KHH %%N  
 9 9'
X 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_sizer;   r=    r   r   <module>r      s    %      4 4 + *eXz5Is>s}}  #|
$ $)u #5 #5LM94 M9r   