Ë
    #täi  ã                   ó>   — d dl Z 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dd„Zˆ xZS )ÚZipFileSystemz©Read/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                 ó¦  •— t        ‰
| �  | fi |¤Ž |t        d«      vrt        d|› d�«      ‚|| _        t        |t        t        j                  f«      r*|dk(  rd}	n|dz   }	t        j                  |f|	|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Úazr+bÚb)ÚmodeÚprotocol)r   ÚcompressionÚ
allowZip64ÚcompresslevelN)ÚsuperÚ__init__ÚsetÚ
ValueErrorr   Ú
isinstanceÚstrÚosÚPathLikeÚfsspecÚopenÚforce_zip_64ÚofÚ	__enter__ÚfoÚzipfileÚZipFiler   Ú	dir_cache)Úselfr   r   Útarget_protocolÚtarget_optionsr   r   r   ÚkwargsÚmÚ	__class__s             €úi/Volumes/fast/ai/experiments/MLX_z-image/.venv/lib/python3.12/site-packages/fsspec/implementations/zip.pyr   zZipFileSystem.__init__   sØ   ø€ ô8 	‰Ñ˜Ñ( Ò(Ø”s˜5“zÑ!Ü˜v d V¨?Ð;Ó<Ð<ØˆŒ	Ü�bœ3¤§¡Ð,Ô-Ø�sŠ{Ø‘à˜3‘J�Ü—‘ØðØ _ñØ9GÒ9MÈ2ñˆBð 'ˆÔØˆŒØ—,‘,“.ˆŒÜ—?‘?Ø�G‰GØØ#Ø!Ø'ô
ˆŒð ˆ�ó    c                 ó@   •— t         ‰| �  |«      j                  d«      S )NÚ/)r   Ú_strip_protocolÚlstrip)ÚclsÚpathr(   s     €r)   r-   zZipFileSystem._strip_protocolH   s    ø€ ô ‰wÑ& tÓ,×3Ñ3°CÓ8Ð8r*   c                 óB   — t        | d«      r| j                  «        | `y y )Nr   )ÚhasattrÚcloser   ©r#   s    r)   Ú__del__zZipFileSystem.__del__M   s   € Ü�4˜ÔØ�J‰JŒLØ‘ð  r*   c                 ó8   — | j                   j                  «        y)z;Commits any write changes to the file. Done on ``del`` too.N)r   r3   r4   s    r)   r3   zZipFileSystem.closeR   s   € à�‰�‰Õr*   c           
      ó€  — | j                   �| j                  t        d«      v �r| j                  j	                  «       }| j                  | j                  j                  «       «      D �ci c]'  }|j                  d«      |j                  d«      dddœ“Œ) c}| _         |D ]‘  }t        j                  j                  D �ci c]  }|t        ||d «      “Œ }}|j                  |j                  j                  d«      |j                  |j                  «       rdnddœ«       || j                   |d   <   Œ“ y y c c}w c c}w )NÚwar,   r   Ú	directory)ÚnameÚsizeÚtypeÚfiler:   )r"   r   r   r   ÚinfolistÚ_all_dirnamesÚnamelistÚrstripr    ÚZipInfoÚ	__slots__ÚgetattrÚupdateÚfilenameÚ	file_sizeÚis_dir)r#   ÚfilesÚdirnameÚzÚsÚfs         r)   Ú	_get_dirszZipFileSystem._get_dirsV   s(  € Ø�>‰>Ð! T§Y¡Y´#°d³)Ò%;ð —H‘H×%Ñ%Ó'ˆEð  $×1Ñ1°$·(±(×2CÑ2CÓ2EÔFóñ  G�Gð —‘˜sÓ#Ø#ŸN™N¨3Ó/ØØ'ñ&ñ ð
  GñˆDŒNó �Ü5<·_±_×5NÒ5NÓOÑ5N°�Qœ  1 dÓ+Ñ+Ð5N�ÐOØ—‘à !§
¡
× 1Ñ 1°#Ó 6Ø !§¡Ø01·±´
¡Àñôð -.�—‘˜q ™yÒ)ñ ð &<ùòùò Ps   Á*,D6Â?D;c                 ó@   —  | j                   j                  ||fi |¤Ž y ©N)r   Úwritestr)r#   r0   Úvaluer&   s       r)   Ú	pipe_filezZipFileSystem.pipe_filen   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«      | j                  ¬«      }d|v r%| j                  |«      }|d   |_        |d   |_        |S )	Nr   r8   z7ZipFS can only be open for reading or writing, not bothÚwr   )Úforce_zip64r;   r:   )r-   r   r   ÚexistsÚOSErrorÚFileNotFoundErrorr   r   Ústripr   Úinfor;   r:   )	r#   r0   r   Ú
block_sizeÚ
autocommitÚcache_optionsr&   Úoutr[   s	            r)   Ú_openzZipFileSystem._openr   sÀ   € ð ×#Ñ# DÓ)ˆØ�$‰;˜4Ÿ9™9¬¨D«	Ñ1Ø�{‰{˜4Ô ÜÐWÓXÐXÜ# DÓ)Ð)Ø�$—)‘)Ñ  t¡ÜÐSÓTÐTØ�h‰h�m‰m˜D $§*¡*¨S£/¸t×?PÑ?PˆmÓQˆØ�$‰;Ø—9‘9˜T“?ˆDØ˜F‘|ˆCŒHØ˜F‘|ˆCŒHØˆ
r*   c                 ó  — |�|dk  rt        d«      ‚dt        fd„}t        |t        «      st        |«      }|j                  d«      } ||«      }t	        |«      }| j                  «        i }	|| j                  v r.| j                  |   d   dk(  r| j                  |   |	|<   |r|	S |gS | j                  j                  «       D ]i  \  }
}t	         ||
«      x}«      |k  st        d„ t        ||«      D «       «      rŒ9|d   d	k(  r|r|
|	vr||	|
j                  d«      <   Œ\|
|	vsŒa|r|nd |	|
<   Œk |r;|	j                  «       D ��ci c]   \  }}|j                  d«      ||z   k  sŒ||“Œ" }	}}|r|	S t        |	«      S c c}}w )
Né   zmaxdepth must be at least 1Ú_pathc           	      ój   — t        t        d | j                  dd«      j                  d«      «      «      S )NÚ\r,   )ÚlistÚfilterÚreplaceÚsplit)rc   s    r)   Úto_partsz$ZipFileSystem.find.<locals>.to_parts�   s*   € Üœ˜t U§]¡]°4¸Ó%=×%CÑ%CÀCÓ%HÓIÓJÐJr*   r,   r<   r=   c              3   ó,   K  — | ]  \  }}||k7  –— Œ y ­wrP   © )Ú.0r   r   s      r)   Ú	<genexpr>z%ZipFileSystem.find.<locals>.<genexpr>£   s   è ø€ ð JÙ#>™4˜1˜a��Q•Ñ#>ùs   ‚r9   )r   r   r   r.   ÚlenrN   r"   ÚitemsÚanyr   rZ   ÚcountÚsorted)r#   r0   ÚmaxdepthÚwithdirsÚdetailr&   rj   Ú
path_partsÚ
path_depthÚresultÚ	file_pathÚ	file_infoÚ
file_partsÚkÚvs                  r)   ÚfindzZipFileSystem.find‰   s¦  € ØÐ H¨q¢LÜÐ:Ó;Ð;ð	KœCó 	Kô ˜$¤Ô$Ü�t“9ˆDð �{‰{˜3ÓˆÙ˜d“^ˆ
Ü˜“_ˆ
à�‰Ôàˆð �4—>‘>Ñ! d§n¡n°TÑ&:¸6Ñ&BÀfÒ&LØŸ>™>¨$Ñ/ˆF�4‰LÙ#�6Ð/¨$¨Ð/à$(§N¡N×$8Ñ$8Ö$:Ñ ˆI�yÜ¡¨)Ó!4Ð4�:Ó5¸
ÒBÄcñ JÜ#& z°:Ô#>óJô Gð à˜Ñ  KÒ/Ù 	°Ñ 7Ø3<�F˜9Ÿ?™?¨3Ó/Ñ0Øà Ò&Ù17¡I¸T��yÒ!ð %;ñ à!'§¡¤ôÙ!/™˜˜A°1·7±7¸3³<À(ÈZÑBWÓ3W��1‘ ð ñ ñ  ˆvÐ3¤V¨F£^Ð3ùós   ÅE<Å%E<)ÚrbNTN)NFF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úroot_markerr   Úcachabler    Ú
ZIP_STOREDr   Úclassmethodr-   r5   r3   rN   rS   r`   r   Ú__classcell__)r(   s   @r)   r   r      s|   ø„ ñð €KØ€HØ€Hð ØØØØ×&Ñ&ØØõ2ðh ó9ó ð9òò
ò.ò01ð ØØØó÷.,4r*   r   )r   r    r   Úfsspec.archiver   r   rl   r*   r)   Ú<module>r‹      s    ðÛ 	Û ã Ý 4ôm4Ð-õ m4r*   