
    "h6                     6    d dl Z d dlZd dlmZ  G d de      Zy)    N)AbstractArchiveFileSystemc                        e Zd ZdZdZdZdZddddej                  ddf fd	Z	e
 fd	       Zd
 Zd Zd Zd Z	 	 	 	 ddZ xZS )ZipFileSystemzRead/Write contents of ZIP archive as a file-system

    Keeps file object open while instance lives.

    This class is pickleable, but not necessarily thread-safe
     zipFrNTc                 d   t        	|   | fi | |t        d      vrt        d| d      || _        t        |t              r t        j                  |f|dz   |d|xs i }|| _	        |j                         | _        t        j                  | j                  ||||      | _        d| _        y)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
            Accept: "r", "w", "a"
        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.
        compression, allowZip64, compresslevel: passed to ZipFile
            Only relevant when creating a ZIP
        rwazmode 'z' no understoodb)modeprotocol)r   compression
allowZip64compresslevelN)super__init__set
ValueErrorr   
isinstancestrfsspecopenof	__enter__fozipfileZipFiler   	dir_cache)
selfr   r   target_protocoltarget_optionsr   r   r   kwargs	__class__s
            W/var/www/html/sandstorm/venv/lib/python3.12/site-packages/fsspec/implementations/zip.pyr   zZipFileSystem.__init__   s    8 	((s5z!vdV?;<<	b#oBPBVTVB ,,.??GG#!'
     c                 @    t         |   |      j                  d      S )N/)r   _strip_protocollstrip)clspathr#   s     r$   r(   zZipFileSystem._strip_protocolB   s      w&t,33C88r%   c                 B    t        | d      r| j                          | `y y )Nr   )hasattrcloser   r   s    r$   __del__zZipFileSystem.__del__G   s    4JJL  r%   c                 8    | j                   j                          y)z;Commits any write changes to the file. Done on ``del`` too.N)r   r.   r/   s    r$   r.   zZipFileSystem.closeL   s    r%   c           
      0   | j                   | j                  t        d      v r| j                  j	                         }| j                  | j                  j                               D ci c]  }|dz   |dz   ddd c}| _         |D ]  }t        j                  j                  D ci c]  }|t        ||d        }}|j                  |j                  |j                  |j                         rdndd       || j                   |d   <    y y c c}w c c}w )Nwar'   r   	directory)namesizetypefiler5   )r   r   r   r   infolist_all_dirnamesnamelistr   ZipInfo	__slots__getattrupdatefilename	file_sizeis_dir)r   filesdirnamezsfs         r$   	_get_dirszZipFileSystem._get_dirsP   s   >>!TYY#d)%; HH%%'E  $11$((2C2C2EF ##q+VVDN  	.5<__5N5NOQ1d++OO !

 !01
 -.qy)	. &<
 Ps   )D&Dc                 @     | j                   j                  ||fi | y )N)r   writestr)r   r+   valuer"   s       r$   	pipe_filezZipFileSystem.pipe_filed   s    $00r%   c                    | j                  |      }d|v r>| j                  t        d      v r'| j                  |      rt	        d      t        |      d| j                  v rd|v rt	        d      | j                  j                  ||j                  d            }d|v r%| j                  |      }|d   |_
        |d   |_        |S )Nr   r3   z7ZipFS can only be open for reading or writing, not bothwr   r6   r5   )r(   r   r   existsOSErrorFileNotFoundErrorr   r   stripinfor6   r5   )	r   r+   r   
block_size
autocommitcache_optionsr"   outrS   s	            r$   _openzZipFileSystem._openh   s     ##D)$;499D	1{{4 WXX#D))$))tSTThhmmD$**S/2$;99T?DF|CHF|CH
r%   )rbNTN)__name__
__module____qualname____doc__root_markerr   cachabler   
ZIP_STOREDr   classmethodr(   r0   r.   rH   rL   rX   __classcell__)r#   s   @r$   r   r      sw     KHH &&-^ 9 9
.(1 r%   r   )r   r   fsspec.archiver   r    r%   r$   <module>re      s      4v- vr%   