§
    dŠtj‘  ã                  ó¼  — d dl mZ d dlZd dlZd dlZ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mZmZ d dlmZ d dlmZ d dlmZ d d	lmZm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" d dl#m$Z$ d dl%m&Z& d dl'm(Z( erd dlm)Z)  ej*        d¦  «        Z+ G d„ de&¦  «        Z, G d„ de ¦  «        Z- G d„ de-¦  «        Z. G d„ de.¦  «        Z/ G d„ d¦  «        Z0dS )é    )ÚannotationsN)ÚCallable)Úrmtree)ÚTYPE_CHECKINGÚAnyÚClassVar)Ú
filesystem)ÚDEFAULT_CALLBACK)Úcompr)Ú	BaseCacheÚ	MMapCache)ÚBlocksizeMismatchError)Úcreate_cache_mapper)ÚCacheMetadata)ÚChainedFileSystem)ÚLocalFileSystem)ÚAbstractBufferedFile)ÚTransaction)Úinfer_compression)ÚAbstractCacheMapperzfsspec.cachedc                  ó   — e Zd Zdd„ZdS )ÚWriteCachedTransactionTc                óô   — d„ | j         D ¦   «         }d„ | j         D ¦   «         }|r| j                             ||¦  «         | j                              ¦   «          d| j        _        d | j        _        d | _        d S )Nc                ó   — g | ]	}|j         ‘Œ
S © ©Úpath©Ú.0Úfs     ú[/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/fsspec/implementations/cached.pyú
<listcomp>z3WriteCachedTransaction.complete.<locals>.<listcomp>"   s   € Ð-Ð-Ð-˜Q�!”&Ð-Ð-Ð-ó    c                ó   — g | ]	}|j         ‘Œ
S r   ©Úfnr   s     r!   r"   z3WriteCachedTransaction.complete.<locals>.<listcomp>#   s   € Ð+Ð+Ð+˜1�!”$Ð+Ð+Ð+r#   F)ÚfilesÚfsÚputÚclearÚ_intransÚ_transaction)ÚselfÚcommitÚrpathsÚlpathss       r!   ÚcompletezWriteCachedTransaction.complete!   s}   € Ø-Ð- $¤*Ð-Ñ-Ô-ˆØ+Ð+ ¤
Ð+Ñ+Ô+ˆØð 	(ØŒG�KŠK˜ Ñ'Ô'Ð'ØŒ
×ÒÑÔÐØ ˆŒÔØ#ˆŒÔØˆŒˆˆr#   N©T)Ú__name__Ú
__module__Ú__qualname__r1   r   r#   r!   r   r       s(   € € € € € ðð ð ð ð ð r#   r   c                  óæ   ‡ — e Zd ZU dZdZded<   dZ	 	 	 	 	 	 	 	 	 	 	 d*d+ˆ fd„Zed„ ¦   «         Z	d„ Z
d„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd,d„Zd„ Z	 	 	 	 d-d„Zd„ Zd.d$„Zd%„ Zd/d&„Zˆ fd'„Zd(„ Zd)„ Zˆ xZS )0ÚCachingFileSystemaS  Locally caching filesystem, layer over any other FS

    This class implements chunk-wise local storage of remote files, for quick
    access after the initial download. The files are stored in a given
    directory with hashes of URLs for the filenames. If no directory is given,
    a temporary one is used, which should be cleaned up by the OS after the
    process ends. The files themselves are sparse (as implemented in
    :class:`~fsspec.caching.MMapCache`), so only the data which is accessed
    takes up space.

    Restrictions:

    - the block-size must be the same for each access of a given file, unless
      all blocks of the file have already been read
    - caching can only be applied to file-systems which produce files
      derived from fsspec.spec.AbstractBufferedFile ; LocalFileSystem is also
      allowed, for testing
    )Ú
blockcacheÚcachedzClassVar[str | tuple[str, ...]]Úprotocol)ÚfoNÚTMPé
   Fé€:	 Ú
same_namesúbool | NoneÚcache_mapperúAbstractCacheMapper | Nonec                óˆ  •‡ —  t          ¦   «         j        d
i |¤Ž |€|€t          d¦  «        ‚|du |du z  st          d¦  «        ‚|dk    r2t          j        ¦   «         }|g}t          j        ‰ ‰ j        |¦  «         nt          |t          ¦  «        r|g}n|}|‰ _
        ‰                      |d         ¦  «         |‰ _        |pi ‰ _        |‰ _        |‰ _        |‰ _        |	‰ _        d‰ _        |�|
�t          d¦  «        ‚|
�|
‰ _        nt)          |�|nd¦  «        ‰ _        t          |t          ¦  «        r|n-t          |j        t          ¦  «        r|j        n|j        d         ‰ _        t/          ‰ j        ¦  «        ‰ _        ‰                      ¦   «          |�|nt5          |fi ‰ j        ¤Ž‰ _        ˆ fd	„}|‰ _        dS )aZ
  

        Parameters
        ----------
        target_protocol: str (optional)
            Target filesystem protocol. Provide either this or ``fs``.
        cache_storage: str or list(str)
            Location to store files. If "TMP", this is a temporary directory,
            and will be cleaned up by the OS when this process ends (or later).
            If a list, each location will be tried in the order given, but
            only the last will be considered writable.
        cache_check: int
            Number of seconds between reload of cache metadata
        check_files: bool
            Whether to explicitly see if the UID of the remote file matches
            the stored one before using. Warning: some file systems such as
            HTTP cannot reliably give a unique hash of the contents of some
            path, so be sure to set this option to False.
        expiry_time: int
            The time in seconds after which a local copy is considered useless.
            Set to falsy to prevent expiry. The default is equivalent to one
            week.
        target_options: dict or None
            Passed to the instantiation of the FS, if fs is None.
        fs: filesystem instance
            The target filesystem to run against. Provide this or ``protocol``.
        same_names: bool (optional)
            By default, target URLs are hashed using a ``HashCacheMapper`` so
            that files from different backends with the same basename do not
            conflict. If this argument is ``true``, a ``BasenameCacheMapper``
            is used instead. Other cache mapper options are available by using
            the ``cache_mapper`` keyword argument. Only one of this and
            ``cache_mapper`` should be specified.
        compression: str (optional)
            To decompress on download. Can be 'infer' (guess from the URL name),
            one of the entries in ``fsspec.compression.compr``, or None for no
            decompression.
        cache_mapper: AbstractCacheMapper (optional)
            The object use to map from original filenames to cached filenames.
            Only one of this and ``same_names`` should be specified.
        cache_storage_mode: int (optional)
            Permission mode used when creating the cache storage directory,
            e.g. ``0o700``. The default of ``None`` leaves the directory at
            the system default (governed by the umask), which is the existing
            behaviour. Pass an octal mode such as ``0o700`` to keep the cache
            directory, and so the cached data files within it, readable by the
            owner only.
        Nz9Please provide filesystem instance(fs) or target_protocolz@Both filesystems (fs) and target_protocol may not be both given.r<   éÿÿÿÿzMCannot specify both same_names and cache_mapper in CachingFileSystem.__init__Fr   c                óx   •— ‰j                              t          ‰¦  «                             | ¦  «        ¦  «        S ©N)r(   Ú_strip_protocolÚtype)r   r-   s    €r!   rG   z3CachingFileSystem.__init__.<locals>._strip_protocol·   s-   ø€ à”7×*Ò*­4°©:¬:×+EÒ+EÀdÑ+KÔ+KÑLÔLÐLr#   r   )ÚsuperÚ__init__Ú
ValueErrorÚtempfileÚmkdtempÚweakrefÚfinalizeÚ_remove_tempdirÚ
isinstanceÚstrÚcache_storage_modeÚ	_makedirsÚstorageÚkwargsÚcache_checkÚcheck_filesÚexpiryÚcompressionÚ_cache_sizeÚ_mapperr   r:   Útarget_protocolr   Ú	_metadataÚ
load_cacher	   r(   rG   )r-   r]   Úcache_storagerW   rX   Úexpiry_timeÚtarget_optionsr(   r?   rZ   rA   rS   rV   ÚtempdirrU   rG   Ú	__class__s   `               €r!   rJ   zCachingFileSystem.__init__C   s*  øø€ ð~ 	�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"Øˆ:˜/Ð1ÝØKñô ð ð �d�
˜°$Ð6Ñ7ð 	ÝØRñô ð ð ˜EÒ!Ð!ÝÔ&Ñ(Ô(ˆGØ�iˆGÝÔ˜T 4Ô#7¸ÑAÔAÐAÐAå˜-­Ñ-Ô-ð (Ø(˜/��à'�Ø"4ˆÔØ�Š�w˜r”{Ñ#Ô#Ð#ØˆŒØ$Ð*¨ˆŒØ&ˆÔØ&ˆÔØ!ˆŒØ&ˆÔð
  ˆÔàÐ! lÐ&>Ýð-ñô ð ð Ð#Ø'ˆDŒLˆLå.Ø(Ð4�
�
¸%ñô ˆDŒLõ ˜/­3Ñ/Ô/ðSˆOˆOå!+¨B¬K½Ñ!=Ô!=ÐQ�"”+�+À2Ä;ÈqÄ>ð 	Ôõ
 ' t¤|Ñ4Ô4ˆŒØ�ŠÑÔÐØ˜�"�"­J°Ð,VÐ,VÈ$Ì+Ð,VÐ,VˆŒð	Mð 	Mð 	Mð 	Mð 	Mð *9ˆÔÐÐr#   c                óH   — 	 t          | ¦  «         d S # t          $ r Y d S w xY wrF   )r   Ú	Exception)rc   s    r!   rP   z!CachingFileSystem._remove_tempdir½   s8   € ð	Ý�7‰OŒOˆOˆOˆOøÝð 	ð 	ð 	ØˆDˆDð	øøøs   ‚ “
! !c                ó|   — | j         €t          j        |d¬¦  «         d S t          j        |d| j         ¬¦  «         d S )NT)Úexist_ok)rh   Úmode)rS   ÚosÚmakedirs©r-   r   s     r!   rT   zCachingFileSystem._makedirsÄ   sF   € ØÔ"Ð*ÝŒK˜ tÐ,Ñ,Ô,Ð,Ð,Ð,åŒK˜ t°$Ô2IÐJÑJÔJÐJÐJÐJr#   c                óF   — |                       | j        d         ¦  «         d S )NrD   )rT   rU   ©r-   s    r!   Ú_mkcachezCachingFileSystem._mkcacheÊ   s!   € Ø�Š�t”| BÔ'Ñ(Ô(Ð(Ð(Ð(r#   c                óŠ   — | j         €6| j        d         }t          d¦  «                             |d¬¦  «        | _         | j         S )z®Return size of cache in bytes.

        If more than one cache directory is in use, only the size of the last
        one (the writable cache directory) is returned.
        NrD   ÚfileT)Úwithdirs)r[   rU   r	   Údu)r-   Ú	cache_dirs     r!   Ú
cache_sizezCachingFileSystem.cache_sizeÍ   sE   € ð ÔÐ#Øœ RÔ(ˆIÝ)¨&Ñ1Ô1×4Ò4°YÈÐ4ÑNÔNˆDÔØÔÐr#   c                ó�   — | j                              ¦   «          |                      ¦   «          t          j        ¦   «         | _        dS )z#Read set of stored blocks from fileN)r^   Úloadro   ÚtimeÚ
last_cachern   s    r!   r_   zCachingFileSystem.load_cacheØ   s4   € àŒ×ÒÑÔÐØ�Š‰ŒˆÝœ)™+œ+ˆŒˆˆr#   c                óž   — |                       ¦   «          | j                             ¦   «          t          j        ¦   «         | _        d| _        dS )z#Save set of stored blocks from fileN)ro   r^   Úsaverx   ry   r[   rn   s    r!   Ú
save_cachezCachingFileSystem.save_cacheÞ   s>   € à�Š‰ŒˆØŒ×ÒÑÔÐÝœ)™+œ+ˆŒØˆÔÐÐr#   c                óø   — |                       ¦   «          | j        sdS t          j        ¦   «         | j        z
  | j        k    }t	          d„ | j        D ¦   «         ¦  «        }|s|s|                      ¦   «          dS dS )z0Reload caches if time elapsed or any disappearedNc              3  óT   K  — | ]#}t           j                             |¦  «        V — Œ$d S rF   )rj   r   Úexists)r   rU   s     r!   ú	<genexpr>z1CachingFileSystem._check_cache.<locals>.<genexpr>ì   s0   è è € ÐLÐL°G�œŸš wÑ/Ô/ÐLÐLÐLÐLÐLÐLr#   )ro   rW   rx   ry   ÚallrU   r_   )r-   ÚtimecondÚ	existconds      r!   Ú_check_cachezCachingFileSystem._check_cacheå   s†   € à�Š‰ŒˆØÔð 	àˆFÝ”9‘;”; ¤Ñ0°4Ô3CÒCˆÝÐLÐL¸t¼|ÐLÑLÔLÑLÔLˆ	Øð 	˜9ð 	Ø�OŠOÑÔÐÐÐð	ð 	r#   c                óŠ   — |                       |¦  «        }|                      ¦   «          | j                             || ¦  «        S )z Is path in cache and still valid)rG   r„   r^   Ú
check_filerl   s     r!   Ú_check_filezCachingFileSystem._check_fileð   s?   € à×#Ò# DÑ)Ô)ˆØ×ÒÑÔÐØŒ~×(Ò(¨¨tÑ4Ô4Ð4r#   c                óp   — t          | j        d         ¦  «         |                      ¦   «          d| _        dS )z¹Remove all files and metadata from the cache

        In the case of multiple cache locations, this clears only the last one,
        which is assumed to be the read/write one.
        rD   N)r   rU   r_   r[   rn   s    r!   Úclear_cachezCachingFileSystem.clear_cacheö   s7   € õ 	ˆtŒ|˜BÔÑ Ô Ð Ø�ŠÑÔÐØˆÔÐÐr#   c                óX  — |s| j         }|                      ¦   «          | j                             |¦  «        \  }}|D ]5}t          j                             |¦  «        rt	          j        |¦  «         Œ6|r.t          | j	        d         ¦  «         |  
                    ¦   «          d| _        dS )aÈ  Remove all expired files and metadata from the cache

        In the case of multiple cache locations, this clears only the last one,
        which is assumed to be the read/write one.

        Parameters
        ----------
        expiry_time: int
            The time in seconds after which a local copy is considered useless.
            If not defined the default is equivalent to the attribute from the
            file caching instantiation.
        rD   N)rY   r„   r^   Úclear_expiredrj   r   r   Úremover   rU   r_   r[   )r-   ra   Úexpired_filesÚwritable_cache_emptyr&   s        r!   Úclear_expired_cachez%CachingFileSystem.clear_expired_cache   s®   € ð ð 	&Øœ+ˆKà×ÒÑÔÐà.2¬n×.JÒ.JÈ;Ñ.WÔ.WÑ+ˆÐ+Øð 	ð 	ˆBÝŒw�~Š~˜bÑ!Ô!ð Ý”	˜"‘”�øàð 	Ý�4”< Ô#Ñ$Ô$Ð$Ø�OŠOÑÔÐàˆÔÐÐr#   c                óž   — |                       |¦  «        }| j                             |¦  «        }|�t          j        |¦  «         d| _        dS )zèRemove cached version of given file

        Deletes local copy of the given (remote) path. If it is found in a cache
        location which is not the last, it is assumed to be read-only, and
        raises PermissionError
        N)rG   r^   Úpop_filerj   rŒ   r[   )r-   r   r&   s      r!   Úpop_from_cachez CachingFileSystem.pop_from_cache  sL   € ð ×#Ò# DÑ)Ô)ˆØŒ^×$Ò$ TÑ*Ô*ˆØˆ>ÝŒI�b‰MŒMˆMØˆÔÐÐr#   ÚrbTc           
     ó–  ‡ ‡‡‡‡— ‰                       ‰¦  «        Š‰ j                              ‰¦  «        Šd|vr ‰ j        j        ‰f||||dœ‰¤ŽS ‰                      ‰¦  «        }|r`|\  }}|d         |d         }
}	|
du r+t                               d‰¦  «         t          ||¦  «        S t                               d‰¦  «         nµ‰                      ‰¦  «        }	t          j	         
                    ‰ j        d         |	¦  «        }t          ¦   «         }
‰|	|
t          j        ¦   «         ‰ j                             ‰¦  «        d	œ}‰ j                             ‰|¦  «         t                               d
‰¦  «         |                     d¦  «        }‰                      ¦   «           ‰ j        j        ‰f||||d|dœ‰¤ŽŠ|€%‰j        |d<   ‰ j                             ‰|¦  «         ‰ j        r8‰ j        dk    rt+          ‰¦  «        n‰ j        }t-          |         ‰d¬¦  «        Šd|v r3|d         ‰j        k    r!t1          d|d         › d‰j        › d�¦  «        ‚n
‰j        |d<   ˆˆˆ fd„}‰ j        rdn|}t3          ‰j        ‰j        ‰j        ||
|¬¦  «        ‰_        ‰j        Šˆˆˆ fd„‰_        ‰                      ¦   «          ‰S )a!  Wrap the target _open

        If the whole file exists in the cache, just open it locally and
        return that.

        Otherwise, open the file on the target FS, and make it have a mmap
        cache pointing to the location which we determine, in our cache.
        The ``blocks`` instance is shared, so as the mmap cache instance
        updates, so does the entry in our ``cached_files`` attribute.
        We monkey-patch this file, so that when it closes, we call
        ``close_and_update`` to save the state of the blocks.
        Úr)ri   Ú
block_sizeÚ
autocommitÚcache_optionsr&   ÚblocksTúOpening local copy of %sz#Opening partially cached copy of %srD   ©Úoriginalr&   r™   rx   Úuidz!Creating local sparse file for %sÚsizeÚnone)ri   r–   r—   r˜   Ú
cache_typerž   NÚinferr“   ©ri   Ú	blocksizezDCached file must be reopened with same block size as original (old: z, new ú)c                óx   •—  ‰j         j        ‰gt          | ¦  «        z  d„ | D ¦   «         d„ | D ¦   «         fi ‰¤ŽS )Nc                ó   — g | ]
}|d          ‘ŒS )r   r   ©r   r•   s     r!   r"   zBCachingFileSystem._open.<locals>._fetch_ranges.<locals>.<listcomp>�  ó   € Ð&Ð&Ð&˜!��1”Ð&Ð&Ð&r#   c                ó   — g | ]
}|d          ‘ŒS )é   r   r§   s     r!   r"   zBCachingFileSystem._open.<locals>._fetch_ranges.<locals>.<listcomp>‘  r¨   r#   )r(   Ú
cat_rangesÚlen)ÚrangesrV   r   r-   s    €€€r!   Ú_fetch_rangesz.CachingFileSystem._open.<locals>._fetch_ranges�  s]   ø€ Ø%�4”7Ô%Ø��˜V™œÑ$Ø&Ð&˜vÐ&Ñ&Ô&Ø&Ð&˜vÐ&Ñ&Ô&ðð ð ð	ð ð r#   )Úmulti_fetcherc                 ó0   •— ‰                      ‰‰ ¦  «        S rF   )Úclose_and_update)Úcloser    r-   s   €€€r!   ú<lambda>z)CachingFileSystem._open.<locals>.<lambda>š  s   ø€ ˜$×/Ò/°°5Ñ9Ô9€ r#   )rG   r(   Ú_openr‡   ÚloggerÚdebugÚopenr\   rj   r   ÚjoinrU   Úsetrx   Úukeyr^   Úupdate_fileÚgetro   rž   rZ   r   r   r£   r   r   Ú_fetch_rangeÚcacher²   r|   )r-   r   ri   r–   r—   r˜   rV   Údetailr&   Úhashr™   rž   Úcompr®   r¯   r²   r    s   ``    `        @@r!   r´   zCachingFileSystem._open+  s^  øøøøø€ ð* ×#Ò# DÑ)Ô)ˆàŒw×&Ò& tÑ,Ô,ˆØ�dˆ?ˆ?Ø �4”7”=ØðàØ%Ø%Ø+ðð ð ðð ð ð ×!Ò! $Ñ'Ô'ˆØð 	Dà‰JˆF�BØ! $œ<¨°Ô)9�&ˆDØ˜ˆ~ˆ~å—’Ð7¸Ñ>Ô>Ð>Ý˜B ‘~”~Ð%å�LŠLÐ>ÀÑEÔEÐEÐEà—<’< Ñ%Ô%ˆDÝ”—’˜dœl¨2Ô.°Ñ5Ô5ˆBÝ‘U”UˆFà ØØ Ýœ	™œØ”w—|’| DÑ)Ô)ðð ˆFð ŒN×&Ò& t¨VÑ4Ô4Ð4Ý�LŠLÐ<¸dÑCÔCÐCð
 �zŠz˜&Ñ!Ô!ˆð 	�Š‰ŒˆØˆDŒGŒMØð	
àØ!Ø!Ø'ØØð	
ð 	
ð ð	
ð 	
ˆð ˆ<ØœVˆF�6‰NØŒN×&Ò& t¨VÑ4Ô4Ð4àÔð 	*ð Ô# wÒ.Ð.õ " $Ñ'Ô'Ð'àÔ%ð õ
 �d”˜A DÐ)Ñ)Ô)ˆAØ˜&Ð Ð Ø�kÔ" a¤kÒ1Ð1Ý,ð+Ø/5°kÔ/Bð+ð +àœKð+ð +ð +ñô ð ð 2ð #$¤+ˆF�;Ñð	ð 	ð 	ð 	ð 	ð 	ð 	ð !%Ô 0ÐC˜˜°mˆÝØŒK˜œ¨¬°°VÈ=ð
ñ 
ô 
ˆŒð ”ˆØ9Ð9Ð9Ð9Ð9Ð9ˆŒØ�ŠÑÔÐØˆr#   c                ó6   — | j                              |¦  «        S rF   )r(   Ú_parentrl   s     r!   rÃ   zCachingFileSystem._parentž  s   € ØŒw�Š˜tÑ$Ô$Ð$r#   r   rR   Úargsr   Úreturnc                ó,   — |                       |¦  «        S rF   )r\   )r-   r   rÄ   s      r!   Ú	hash_namezCachingFileSystem.hash_name¡  s   € ð �|Š|˜DÑ!Ô!Ð!r#   c                óÖ  — |j         rdS |                      |j        ¦  «        }| j                             ||¦  «         	 t
                               d¦  «         |                      ¦   «          t
                               d¦  «         nO# t          $ r t
                               d¦  «         Y n)t          $ r t
                               d¦  «         Y nw xY w |¦   «          d|_         dS )z9Called when a file is closing, so store the set of blocksNzgoing to saveÚsavedz&Cache saving failed while closing filez-Cache save failed due to interpreter shutdownT)
ÚclosedrG   r   r^   Úon_close_cached_filerµ   r¶   r|   ÚOSErrorÚ	NameError)r-   r    r²   r   s       r!   r±   z"CachingFileSystem.close_and_update¦  s÷   € àŒ8ð 	ØˆFØ×#Ò# A¤FÑ+Ô+ˆØŒ×+Ò+¨A¨tÑ4Ô4Ð4ð	JÝ�LŠL˜Ñ)Ô)Ð)Ø�OŠOÑÔÐÝ�LŠL˜Ñ!Ô!Ð!Ð!øÝð 	Cð 	Cð 	CÝ�LŠLÐAÑBÔBÐBÐBÐBÝð 	Jð 	Jð 	JÝ�LŠLÐHÑIÔIÐIÐIÐIð	Jøøøàˆ‰ŒˆØˆŒˆˆs   Á AB	 Â	$CÂ/#CÃCc                ó*   —  | j         j        ||fi |¤ŽS rF   )r(   Úls)r-   r   r¿   rV   s       r!   rÏ   zCachingFileSystem.ls·  s    € ØˆtŒwŒz˜$ Ð1Ð1¨&Ð1Ð1Ð1r#   c                ó  •‡ ‡— ‰dv r#t          t          ‰ ¦  «        ‰¦  «        rˆˆ fd„S ‰dv rt          ‚‰dv r't          ‰ ¦  «        j                             ‰ ¦  «        S ‰dv rt          t          ‰ ¦  «        ‰¦  «        S ‰dk    rt          ‰ ¦  «        S t                               ‰ d¦  «        }|                     dd ¦  «        }‰|v r|‰         S |�Œ‰|j	        v r|j	        ‰         S t          |¦  «        }t          |‰¦  «        }t          j        |¦  «        st          j        |¦  «        r-t          |d	¦  «        r|j        €|                     ||¦  «        S |S t          ¦   «                              ‰¦  «        S )
N>.   rÏ   Úcatr¼   ÚheadÚinfor·   ÚpipeÚtailr´   ÚisdirÚ__eq__r   ÚisfileÚto_dictÚto_jsonÚ__hash__rJ   ro   Úcat_fileÚ	_cat_filerT   rÇ   Ú	open_manyÚ	pipe_fileÚ
__reduce__ru   r«   Ú
get_mapperr_   Ú
local_fileÚ
read_blockr|   Ú_cat_rangesr‡   r‰   Úcommit_manyr„   r’   Úend_transactionÚ__getattribute__Ú_paths_from_pathr±   Ústart_transactionÚ_make_local_detailsr�   Ú_get_cached_file_before_openc                 óp   •—  t          t          ‰¦  «        ‰¦  «                             ‰¦  «        | i |¤ŽS rF   )ÚgetattrrH   Ú__get__)rÄ   ÚkwÚitemr-   s     €€r!   r³   z4CachingFileSystem.__getattribute__.<locals>.<lambda>î  s=   ø€ Ð+R­7µ4¸±:´:¸tÑ+DÔ+D×+LÒ+LÈTÑ+RÔ+RØð,Øð,ð ,€ r#   )Ú__reduce_ex__)Útransaction>   Ú_cacher:   Útransaction_typerd   Ú__dict__r(   Ú__self__)ÚhasattrrH   ÚAttributeErrorrò   rî   rí   Úobjectrç   r¼   rõ   ÚinspectÚ
isfunctionÚisdatadescriptorrö   rI   )r-   rð   Údr(   ÚclsÚmrd   s   ``    €r!   rç   z"CachingFileSystem.__getattribute__º  s¬  øøø€ Øð /
ð /
ð /
õd •t˜D‘z”z 4Ñ(Ô(ð ðð ð ð ð ð ð
 Ð$Ð$Ð$Ý Ð Ø�?Ð"Ð"å˜‘:”:Ô)×1Ò1°$Ñ7Ô7Ð7ØÐ=Ð=Ð=å�4 ™:œ: tÑ,Ô,Ð,Ø�;ÒÐÝ˜‘:”:ÐÝ×#Ò# D¨*Ñ5Ô5ˆØ�UŠU�4˜ÑÔˆØ�1ˆ9ˆ9Ø�T”7ˆNØˆ^Ø�r”{Ð"Ð"à”{ 4Ô(Ð(å�r‘(”(ˆCÝ˜˜TÑ"Ô"ˆAÝÔ" 1Ñ%Ô%ð *­Ô)AÀ!Ñ)DÔ)Dð *Ý˜A˜zÑ*Ô*ð*Ø./¬jÐ.@ð —y’y  SÑ)Ô)Ð)ØˆHõ ‘7”7×+Ò+¨DÑ1Ô1Ð1r#   c                óL  — | |u rdS t          |t          | ¦  «        ¦  «        sdS | j        |j        k    oo| j        |j        k    o_| j        |j        k    oO| j        |j        k    o?| j        |j        k    o/| j        |j        k    o| j        |j        k    o| j	        |j	        k    S )zTest for equality.TF)
rQ   rH   rU   rV   rW   rX   rY   rZ   r\   r]   )r-   Úothers     r!   r×   zCachingFileSystem.__eq__  sÇ   € à�5ˆ=ˆ=Ø�4Ý˜%¥ d¡¤Ñ,Ô,ð 	Ø�5àŒL˜EœMÒ)ð >Ø”˜uœ|Ò+ð>àÔ  EÔ$5Ò5ð>ð Ô  EÔ$5Ò5ð>ð ”˜uœ|Ò+ð	>ð
 Ô  EÔ$5Ò5ð>ð ” ¤Ò-ð>ð Ô$¨Ô(=Ò=ð		
r#   c                ó„  — t          t          | j        ¦  «        ¦  «        t          t          | j        ¦  «        ¦  «        z  t          | j        ¦  «        z  t          | j        ¦  «        z  t          | j        ¦  «        z  t          | j        ¦  «        z  t          | j	        ¦  «        z  t          | j
        ¦  «        z  S )zCalculate hash.)rÀ   ÚtuplerU   rR   rV   rW   rX   rY   rZ   r\   r]   rn   s    r!   rÛ   zCachingFileSystem.__hash__#  s²   € õ •�t”|Ñ$Ô$Ñ%Ô%Ý•3�t”{Ñ#Ô#Ñ$Ô$ñ%å�4Ô#Ñ$Ô$ñ%õ �4Ô#Ñ$Ô$ñ%õ �4”;ÑÔñ	 õ
 �4Ô#Ñ$Ô$ñ%õ �4”<Ñ Ô ñ!õ �4Ô'Ñ(Ô(ñ)ð		
r#   )Nr<   r=   Fr>   NNNNNN)r?   r@   rA   rB   rF   )r“   NTN)r   rR   rÄ   r   rÅ   rR   r2   )r3   r4   r5   Ú__doc__r:   Ú__annotations__Ú_strip_tokenize_optionsrJ   ÚstaticmethodrP   rT   ro   ru   r_   r|   r„   r‡   r‰   r�   r’   r´   rÃ   rÇ   r±   rÏ   rç   r×   rÛ   Ú__classcell__©rd   s   @r!   r7   r7   ,   sö  ø€ € € € € € ðð ð& 1I€HÐHÐHÐHÑHØ%Ðð ØØØØØØØ"&ØØ37Øðx9ð x9ð x9ð x9ð x9ð x9ð x9ðt ðð ñ „\ððKð Kð Kð)ð )ð )ð	 ð 	 ð 	 ð&ð &ð &ð ð  ð  ð	ð 	ð 	ð5ð 5ð 5ð ð  ð  ð ð  ð  ð  ð< ð  ð  ð  ØØØðqð qð qð qðf%ð %ð %ð"ð "ð "ð "ð
ð ð ð"2ð 2ð 2ð 2ðV2ð V2ð V2ð V2ð V2ðp
ð 
ð 
ð"
ð 
ð 
ð 
ð 
ð 
ð 
r#   r7   c                  óZ   — e Zd ZdZdZdZd„ Zd„ Zd„ Zdde	fd	„Z
d
„ Zdd„Zdd„Z	 dd„ZdS )ÚWholeFileCacheFileSystema  Caches whole remote files on first access

    This class is intended as a layer over any other file system, and
    will make a local copy of each file accessed, so that all subsequent
    reads are local. This is similar to ``CachingFileSystem``, but without
    the block-wise functionality and so can work even when sparse files
    are not allowed. See its docstring for definition of the init
    arguments.

    The class still needs access to the remote store for listing files,
    and may refresh cached files.
    Ú	filecacheTc                óv  ‡ ‡‡‡— d„ ‰D ¦   «         }d‰j         v r‰                      ¦   «          nˆˆˆ fd„|D ¦   «         S ‰ j        rt          ‚ˆ fd„|D ¦   «         }d„ t	          ||¦  «        D ¦   «         }ˆ fd„t	          ||¦  «        D ¦   «         }d„ t	          ||¦  «        D ¦   «         }|rn‰ j                             ||¦  «         ˆ fd„|D ¦   «         }t	          ||¦  «        D ] \  }	}
‰ j                             |	|
¦  «         Œ!‰  	                    ¦   «          d	„ Šˆˆfd
„t	          ||¦  «        D ¦   «         S )Nc                ó   — g | ]	}|j         ‘Œ
S r   r   )r   Úofs     r!   r"   z6WholeFileCacheFileSystem.open_many.<locals>.<listcomp>C  s   € Ð.Ð.Ð.˜R�”Ð.Ð.Ð.r#   r•   c                ó¾   •— g | ]Y}t          ‰j        |f‰j        t          j                             ‰j        d          ‰                     |¦  «        ¦  «        dœ‰¤Ž‘ŒZS )rD   ©ri   r&   )ÚLocalTempFiler(   ri   rj   r   r¸   rU   r\   )r   r   rV   Ú
open_filesr-   s     €€€r!   r"   z6WholeFileCacheFileSystem.open_many.<locals>.<listcomp>G  s~   ø€ ð 	ð 	ð 	ð õ Ø”GØðð $œÝ”w—|’| D¤L°Ô$4°d·l²lÀ4Ñ6HÔ6HÑIÔIð	ð ð
 ðð ð	ð 	ð 	r#   c                ó:   •— g | ]}‰                      |¦  «        ‘ŒS r   ©r‡   )r   Úspr-   s     €r!   r"   z6WholeFileCacheFileSystem.open_many.<locals>.<listcomp>T  s'   ø€ Ð8Ð8Ð8¨B�4×#Ò# BÑ'Ô'Ð8Ð8Ð8r#   c                ó   — g | ]	\  }}|°|‘Œ
S r   r   )r   Úprý   s      r!   r"   z6WholeFileCacheFileSystem.open_many.<locals>.<listcomp>U  s!   € Ð?Ð?Ð?™$˜!˜Q¸QÐ?�AÐ?Ð?Ð?r#   c                ó’   •— g | ]C\  }}t           j                             ‰j        d          ‰                     |¦  «        ¦  «        ‘ŒDS )rD   )rj   r   r¸   rU   r\   )r   r  rý   r-   s      €r!   r"   z6WholeFileCacheFileSystem.open_many.<locals>.<listcomp>V  sN   ø€ ð 
ð 
ð 
á��1õ ŒG�LŠL˜œ bÔ)¨4¯<ª<¸©?¬?Ñ;Ô;ð
ð 
ð 
r#   c                ó   — g | ]	\  }}|°|‘Œ
S r   r   )r   r&   rý   s      r!   r"   z6WholeFileCacheFileSystem.open_many.<locals>.<listcomp>Z  s!   € ÐAÐAÐA™˜˜Q¸qÐA�"ÐAÐAÐAr#   c           	     ó˜   •— g | ]F}|‰                      |¦  «        d t          j        ¦   «         ‰j                             |¦  «        dœ‘ŒGS )Tr›   )r\   rx   r(   rº   )r   r   r-   s     €r!   r"   z6WholeFileCacheFileSystem.open_many.<locals>.<listcomp>`  sa   ø€ ð 	ð 	ð 	ð ð !%ØŸ,š, tÑ,Ô,Ø"Ý œI™KœKØœ7Ÿ<š<¨Ñ-Ô-ðð ð	ð 	ð 	r#   c                ó@   — t          | t          ¦  «        r| d         n| S )Nrª   )rQ   r  r%   s    r!   Ú	firstpartz5WholeFileCacheFileSystem.open_many.<locals>.firstpartn  s   € å& r­5Ñ1Ô1Ð9�2�a”5�5°rÐ9r#   c                ó\   •— g | ](\  }}t          |r ‰|¦  «        n|‰j        ¬ ¦  «        ‘Œ)S )r¢   )r·   ri   )r   Úfn0Úfn1r  r  s      €€r!   r"   z6WholeFileCacheFileSystem.open_many.<locals>.<listcomp>r  sM   ø€ ð 
ð 
ð 
á��Sõ  3Ð/��˜3‘”�¨C°j´oÐFÑFÔFð
ð 
ð 
r#   )
ri   ro   rZ   ÚNotImplementedErrorÚzipr(   r¼   r^   r»   r|   )r-   r  rV   ÚpathsÚdetailsÚdownpathÚdownfn0ÚdownfnÚ	newdetailr   r¿   r  s   ```        @r!   rÞ   z"WholeFileCacheFileSystem.open_manyB  sâ  øøøø€ Ø.Ð. :Ð.Ñ.Ô.ˆØ�*”/Ð!Ð!Ø�MŠM‰OŒOˆOˆOð	ð 	ð 	ð 	ð 	ð 	ð "ð	ñ 	ô 	ð 	ð Ôð 	&Ý%Ð%Ø8Ð8Ð8Ð8°%Ð8Ñ8Ô8ˆØ?Ð?¥# e¨WÑ"5Ô"5Ð?Ñ?Ô?ˆð
ð 
ð 
ð 
å˜E 7Ñ+Ô+ð
ñ 
ô 
ˆð BÐA¥# g¨wÑ"7Ô"7ÐAÑAÔAˆØð 	àŒG�KŠK˜ &Ñ)Ô)Ð)ð	ð 	ð 	ð 	ð %ð	ñ 	ô 	ˆIõ !$ H¨iÑ 8Ô 8ð 9ð 9‘��fØ”×*Ò*¨4°Ñ8Ô8Ð8Ð8Ø�OŠOÑÔÐð	:ð 	:ð 	:ð
ð 
ð 
ð 
ð 
å ¨Ñ1Ô1ð
ñ 
ô 
ð 	
r#   c                óè   — | j                              d„ |D ¦   «         d„ |D ¦   «         ¦  «         d„ |D ¦   «          |D ],}	 t          j        |j        ¦  «         Œ# t
          $ r Y Œ)w xY wd | _        d S )Nc                ó   — g | ]	}|j         ‘Œ
S r   r%   r   s     r!   r"   z8WholeFileCacheFileSystem.commit_many.<locals>.<listcomp>x  s   € Ð.Ð.Ð.˜a�Q”TÐ.Ð.Ð.r#   c                ó   — g | ]	}|j         ‘Œ
S r   r   r   s     r!   r"   z8WholeFileCacheFileSystem.commit_many.<locals>.<listcomp>x  s   € Ð0LÐ0LÐ0L¸A°´Ð0LÐ0LÐ0Lr#   c                ó6   — g | ]}|                      ¦   «         ‘ŒS r   ©r²   r   s     r!   r"   z8WholeFileCacheFileSystem.commit_many.<locals>.<listcomp>y  s    € Ð'Ð'Ð'�qˆ�Š‰ŒÐ'Ð'Ð'r#   )r(   r)   rj   rŒ   ÚnameÚFileNotFoundErrorr[   )r-   r  r    s      r!   rå   z$WholeFileCacheFileSystem.commit_manyw  s¡   € ØŒ�ŠÐ.Ð. :Ð.Ñ.Ô.Ð0LÐ0LÀÐ0LÑ0LÔ0LÑMÔMÐMØ'Ð'˜JÐ'Ñ'Ô'Ð'Øð 	ð 	ˆAðÝ”	˜!œ&Ñ!Ô!Ð!Ð!øÝ$ð ð ð Ø�ðøøøàˆÔÐÐs   ÁAÁ
A(Á'A(c                óT  — |                       |¦  «        }t          j                             | j        d         |¦  «        }||dt          j        ¦   «         | j                             |¦  «        dœ}| j         	                    ||¦  «         t                               d|¦  «         |S )NrD   Tr›   úCopying %s to local cache)r\   rj   r   r¸   rU   rx   r(   rº   r^   r»   rµ   r¶   )r-   r   rÀ   r&   r¿   s        r!   rê   z,WholeFileCacheFileSystem._make_local_details‚  s’   € Ø�|Š|˜DÑ!Ô!ˆÝŒW�\Š\˜$œ, rÔ*¨DÑ1Ô1ˆàØØÝ”I‘K”KØ”7—<’< Ñ%Ô%ð
ð 
ˆð 	Œ×"Ò" 4¨Ñ0Ô0Ð0Ý�ŠÐ0°$Ñ7Ô7Ð7Øˆ	r#   FÚraisec                ó  — |                       |||                     d¦  «        ¬¦  «        }g }g }g }	i }
|                     ¦   «         D ]Ë}	 |                      |¦  «        }|s@|                      |¦  «        }|                     |¦  «         |                     |¦  «         nt          |t          ¦  «        r|nd |f\  }}|	                     |¦  «         ŒŽ# t          $ r1}|dk    r‚ |dk    r||
|<   | 	                    |¦  «         Y d }~ŒÄd }~ww xY w|r/| j
                             ||¦  «         |                      ¦   «          |                     t          |¦  «        ¦  «         t          ||	¦  «        D ]Y\  }}t          |d¦  «        5 }|                     ¦   «         |
|<   d d d ¦  «         n# 1 swxY w Y   |                     d¦  «         ŒZt          |t$          ¦  «        r%t          |¦  «        dk    r|du r|
|d                  }
|
S )	NÚmaxdepth)Ú	recursiver4  r2  rÅ   r“   rª   Fr   )Úexpand_pathr¼   Úcopyr‡   rê   ÚappendrQ   r  rf   rŒ   r(   r|   Úset_sizer¬   r"  r·   ÚreadÚrelative_updaterR   )r-   r   r5  Úon_errorÚcallbackrV   r#  ÚgetpathsÚ
storepathsÚfnsÚoutr  r¿   r&   Úer    s                   r!   rÑ   zWholeFileCacheFileSystem.cat�  sp  € ð × Ò Ø˜I°·
²
¸:Ñ0FÔ0Fð !ñ 
ô 
ˆð ˆØˆ
ØˆØˆØ—’‘”ð 	 ð 	 ˆAð Ø×)Ò)¨!Ñ,Ô,�Øð YØ×1Ò1°!Ñ4Ô4�BØ—O’O AÑ&Ô&Ð&Ø×%Ò% bÑ)Ô)Ð)Ð)å+5°f½eÑ+DÔ+DÐ!X  È4ÐQWÈ.‘J�F˜BØ—
’
˜2‘”��øÝð  ð  ð  Ø˜wÒ&Ð&ØØ˜xÒ'Ð'Ø�C˜‘FØ—’˜Q‘”������øøøøð øøøð ð 	ØŒG�KŠK˜ *Ñ-Ô-Ð-Ø�OŠOÑÔÐà×Ò�#˜e™*œ*Ñ%Ô%Ð%Ý˜ ‘_”_ð 	(ð 	(‰EˆAˆrÝ�b˜$‘”ð " 1ØŸš™œ��A‘ð"ð "ð "ñ "ô "ð "ð "ð "ð "ð "ð "øøøð "ð "ð "ð "à×$Ò$ QÑ'Ô'Ð'Ð'Ý�d�CÑ Ô ð 	 ¥S¨¡Z¤Z°1¢_ _¸ÀeÐ9KÐ9KØ�e˜A”h”-ˆCØˆ
s+   ÁB
CÃ
DÃ 'DÄDÆF0Æ0F4	Æ7F4	c                óØ  — |                       |¦  «        }|                      ¦   «          | j        �r	 | j        j        |fddi|¤Ž5 }t          |d¦  «        5 }t          |t          ¦  «        r%t          d|j	        j
        |j        ¦  «        |_	        | j        dk    rt          |¦  «        n| j        }t          |         |d¬¦  «        }d}|r=t          |dd	¦  «        }|                     |¦  «        }|                     |¦  «         |°=d d d ¦  «         n# 1 swxY w Y   d d d ¦  «         n# 1 swxY w Y   n| j                             ||¦  «         |                      ¦   «          d S )
Nri   r“   Úwbr   r¡   r¢   Tr£   é  P )rê   ro   rZ   r(   r´   r·   rQ   r   r   r¾   Úfetcherrž   r   r   rí   r:  ÚwriteÚget_filer|   )	r-   r   rV   r&   r    Úf2rÁ   ÚdataÚblocks	            r!   rë   z5WholeFileCacheFileSystem._get_cached_file_before_open½  sç  € Ø×%Ò% dÑ+Ô+ˆà�Š‰ŒˆØÔñ 	'Ø�””˜tÐ9Ð9¨$Ð9°&Ð9Ð9ð #¸QÅÀRÈÁÄð #ÐRTÝ˜aÕ!5Ñ6Ô6ð Då'¨¨1¬7¬?¸A¼FÑCÔC�A”Gð Ô'¨7Ò2Ð2õ & dÑ+Ô+Ð+àÔ)ð õ
 ˜$”K ¨Ð-Ñ-Ô-�Ø�Øð #Ý# A {°IÑ>Ô>�EØŸ6š6 %™=œ=�DØ—H’H˜T‘N”N�Nð ð #ð#ð #ð #ñ #ô #ð #ð #ð #ð #ð #ð #øøøð #ð #ð #ð #ð #ð #ð #ñ #ô #ð #ð #ð #ð #ð #ð #øøøð #ð #ð #ð #øð  ŒG×Ò˜T 2Ñ&Ô&Ð&Ø�ŠÑÔÐÐÐs7   ÁD/ÁB4DÄD/ÄD	ÄD/ÄD	Ä D/Ä/D3Ä6D3r“   c                óÚ  — |                       |¦  «        }d|v sd|v r¬|                      |¦  «        s<| j                             |¦  «        r | j        |fi |¤Ž nd|v rt          |¦  «        ‚|                      |¦  «        \  }}|d         |d         }}|du rt                               d|¦  «         nt          d|› d�¦  «        ‚d|v r0d	|vr,t          ||¦  «        }| 
                    d
¦  «        |_        |S |                      |¦  «        }	t          j                             | j        d         |	¦  «        }d„ |                     ¦   «         D ¦   «         }
t%          | |f||dœ|
¤ŽS )Nr•   Úar&   r™   Trš   z&Attempt to open partially cached file z as a wholly cached fileú+rœ   rD   c                ó"   — i | ]\  }}|d v¯	||“ŒS ©)r—   r–   r˜   r   ©r   ÚkÚvs      r!   ú
<dictcomp>z2WholeFileCacheFileSystem._open.<locals>.<dictcomp>ö  s7   € ð !
ð !
ð !
á��1àÐEÐEÐEð ˆqð FÐEÐEr#   r  )rG   r‡   r(   r   rë   r/  rµ   r¶   rK   r·   r¼   rœ   r\   rj   r   r¸   rU   Úitemsr  )r-   r   ri   rV   r¿   r&   Ú_r™   r    rÀ   Úuser_specified_kwargss              r!   r´   zWholeFileCacheFileSystem._openÕ  s©  € Ø×#Ò# DÑ)Ô)ˆà�$ˆ;ˆ;˜# ˜+˜+Ø×#Ò# DÑ)Ô)ð 2Ø”7—>’> $Ñ'Ô'ð 2Ø5�DÔ5°dÐEÐE¸fÐEÐEÐEÐEØ˜D�[�[Ý+¨DÑ1Ô1Ð1à×)Ò)¨$Ñ/Ô/‰JˆF�BØ˜tœ f¨XÔ&6ˆvˆAØ˜ˆ~ˆ~Ý—’Ð7¸Ñ>Ô>Ð>Ð>å ð0¸Tð 0ð 0ð 0ñô ð ð �$ˆ;ˆ;˜3 d˜?˜?õ �R˜‘”ˆAØŸš JÑ/Ô/ˆAŒJØˆHà�|Š|˜DÑ!Ô!ˆÝŒW�\Š\˜$œ, rÔ*¨DÑ1Ô1ˆð!
ð !
àŸš™œð!
ñ !
ô !
Ðõ ˜T 4ÐS¨d°rÐSÐSÐ=RÐSÐSÐSr#   Nc              ‹  ó*  K  — t                                d|¦  «         |                      |¦  «        }|                      |¦  «        }|                      |¦  «        }|sEt
          j                             | j        d         |¦  «        } | j	        j
        ||fi |¤Žƒ d {V —† t          |d¦  «        5 }|r|                     |¦  «         |€dn||                     ¦   «         z
  }|                     |¦  «        cd d d ¦  «         S # 1 swxY w Y   d S )Nzasync cat_file %srD   r“   )rµ   r¶   rG   r\   r‡   rj   r   r¸   rU   r(   Ú	_get_filer·   ÚseekÚtellr:  )	r-   r   ÚstartÚendrV   Úshar&   r    rž   s	            r!   rÝ   z"WholeFileCacheFileSystem._cat_fileþ  sS  è è € Ý�ŠÐ(¨$Ñ/Ô/Ð/Ø×#Ò# DÑ)Ô)ˆØ�lŠl˜4Ñ Ô ˆØ×Ò˜dÑ#Ô#ˆàð 	8Ý”—’˜dœl¨2Ô.°Ñ4Ô4ˆBØ#�$”'Ô# D¨"Ð7Ð7°Ð7Ð7Ð7Ð7Ð7Ð7Ð7Ð7Ð7å�"�d‰^Œ^ð 	 ˜qØð Ø—’�u‘”�Ø˜�2�2¨#°·²±´©.ˆDØ—6’6˜$‘<”<ð		 ð 	 ð 	 ð 	 ñ 	 ô 	 ð 	 ð 	 ð 	 ð 	 ð 	 ð 	 øøøð 	 ð 	 ð 	 ð 	 ð 	 ð 	 s   Â4ADÄDÄDrÅ   c              ‹  óT  K  — t                                d|¦  «         g }t          ¦   «         }g }	g }
|D ]±}|                      |¦  «        }|€ƒ||vr|                      |¦  «        }t
          j                             | j        d         |¦  «        }|	 	                    |¦  «         | 
                    |¦  «         |
 	                    |¦  «         | 	                    |¦  «         Œ²|	r#| j                             |
|	|¬¦  «        ƒ d {V —†  t          ¦   «         j        |||f||dœ|¤ŽS )Nzasync cat ranges %srD   )r<  ©Úmax_gapr<  )rµ   r¶   r¹   r‡   r\   rj   r   r¸   rU   r8  Úaddr(   Ú_getr   r«   )r-   r#  ÚstartsÚendsra  r<  rV   r0   ÚrsetÚdownloadr/   r  r&   r^  s                 r!   rä   z$WholeFileCacheFileSystem._cat_ranges  sG  è è € õ 	�ŠÐ*¨EÑ2Ô2Ð2ØˆÝ‰uŒuˆØˆØˆØð 	ð 	ˆAØ×!Ò! !Ñ$Ô$ˆBØˆz˜a t˜m˜mØ—l’l 1‘o”o�Ý”W—\’\ $¤,¨rÔ"2°CÑ8Ô8�Ø—’ Ñ#Ô#Ð#Ø—’˜‘”�Ø—’˜aÑ Ô Ð Ø�MŠM˜"ÑÔÐÐØð 	DØ”'—,’,˜v x¸(�,ÑCÔCÐCÐCÐCÐCÐCÐCÐCà+�Ñ Ô Ô+Ø�F˜Dð
Ø*1¸Hð
ð 
ØHNð
ð 
ð 	
r#   ©r“   )NN©NrÅ   )r3   r4   r5   r  r:   râ   rÞ   rå   rê   r
   rÑ   rë   r´   rÝ   rä   r   r#   r!   r  r  1  sÎ   € € € € € ðð ð €HØ€Jð3
ð 3
ð 3
ðj	 ð 	 ð 	 ðð ð ð" ØØ!ð+ð +ð +ð +ðZð ð ð0'Tð 'Tð 'Tð 'TðR ð  ð  ð  ð" ;Cð
ð 
ð 
ð 
ð 
ð 
r#   r  c                  óz   ‡ — e Zd ZdZdZdZeZˆ fd„Zd„ Z	d„ Z
d„ Zdˆ fd	„	Zdd
„Zd„ Zdd„Z	 dd„Zd„ Zdd„Zˆ xZS )ÚSimpleCacheFileSystemaž  Caches whole remote files on first access

    This class is intended as a layer over any other file system, and
    will make a local copy of each file accessed, so that all subsequent
    reads are local. This implementation only copies whole files, and
    does not keep any metadata about the download time or file details.
    It is therefore safer to use in multi-threaded/concurrent situations.

    This is the only of the caching filesystems that supports write: you will
    be given a real local open file, and upon close and commit, it will be
    uploaded to the target filesystem; the writability or the target URL is
    not checked until that time.

    ÚsimplecacheTc                óò   •— |                      ¦   «         }dD ]}d||<   Œ t          ¦   «         j        di |¤Ž | j        D ]6}t          j                             |¦  «        s|                      |¦  «         Œ7d S )N)rW   ra   rX   Fr   )r7  rI   rJ   rU   rj   r   r   rT   )r-   rV   rï   ÚkeyrU   rd   s        €r!   rJ   zSimpleCacheFileSystem.__init__;  s‹   ø€ Ø�[Š[‰]Œ]ˆØ@ð 	ð 	ˆCØˆBˆs‰GˆGØ�‰ŒÔÐÐ˜2ÐÐÐØ”|ð 	(ð 	(ˆGÝ”7—>’> 'Ñ*Ô*ð (Ø—’˜wÑ'Ô'Ð'øð	(ð 	(r#   c                óò   — |                       ¦   «          |                      |¦  «        }| j        D ]E}t          j                             ||¦  «        }t          j                             |¦  «        r|c S ŒFd S rF   )r„   r\   rU   rj   r   r¸   r   )r-   r   r^  rU   r&   s        r!   r‡   z!SimpleCacheFileSystem._check_fileD  sy   € Ø×ÒÑÔÐØ�lŠl˜4Ñ Ô ˆØ”|ð 	ð 	ˆGÝ”—’˜g sÑ+Ô+ˆBÝŒw�~Š~˜bÑ!Ô!ð Ø�	�	�	ðð	ð 	r#   c                ó   — d S rF   r   rn   s    r!   r|   z SimpleCacheFileSystem.save_cacheL  ó   € Øˆr#   c                ó   — d S rF   r   rn   s    r!   r_   z SimpleCacheFileSystem.load_cacheO  rq  r#   Nc                óæ   •— | j         rF|                      |d¦  «        5 }|                     |¦  «         d d d ¦  «         d S # 1 swxY w Y   d S t          ¦   «                              ||¦  «         d S )NrD  )r+   r·   rG  rI   rß   )r-   r   ÚvaluerV   r    rd   s        €r!   rß   zSimpleCacheFileSystem.pipe_fileR  s³   ø€ ØŒ=ð 	+Ø—’˜4 Ñ&Ô&ð ¨!Ø—’˜‘”�ðð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð õ ‰GŒG×Ò˜d EÑ*Ô*Ð*Ð*Ð*s   ŸAÁAÁ	Ac                óª  — |                       |¦  «        }g }	  | j        j        |fddi|¤Ž                     ¦   «         }d }n# t          $ r}|}Y d }~nd }~ww xY w| j        �rN|                     d¦  «        dz   }| j        j        D �](}|j	        |k    r3| 
                    ||j        p|                     ¦   «         ddœ¦  «         ŒA|j	                             |¦  «        rÍ|j	                             d¦  «        |                     d¦  «        k    r8| 
                    |j	        |j        p|                     ¦   «         ddœ¦  «         ŒÄd                     |j	                             d¦  «        d |                     d¦  «        dz   …         ¦  «        }	| 
                    |	dddœ¦  «         �Œ*|�|s|‚|r|S t#          d	„ |D ¦   «         ¦  «        S )
Nr¿   Tú/rq   ©r.  rž   rH   rª   r   Ú	directoryc              3  ó&   K  — | ]}|d          V — ŒdS )r.  Nr   )r   rV  s     r!   r€   z+SimpleCacheFileSystem.ls.<locals>.<genexpr>w  s&   è è € Ð1Ð1 A�a˜”iÐ1Ð1Ð1Ð1Ð1Ð1r#   )rG   r(   rÏ   r7  r/  r+   Úrstriprò   r'   r   r8  rž   r[  Ú
startswithÚcountr¸   ÚsplitÚsorted)
r-   r   r¿   rV   r$  ÚexrB  Úpath1r    Údnames
             r!   rÏ   zSimpleCacheFileSystem.lsY  s  € Ø×#Ò# DÑ)Ô)ˆØˆð	Ø �d”g”jØðð Ø!ðØ%+ðð çŠd‰fŒfð ð ˆBˆBøõ !ð 	ð 	ð 	ØˆBˆBˆBˆBˆBˆBøøøøð	øøøð Œ=ñ 	XØ—K’K Ñ$Ô$ sÑ*ˆEØÔ%Ô+ð Xñ X�Ø”6˜T’>�>Ø—N’NØ!%¨q¬vÐ/A¸¿º¹¼È6ÐRÐRñô ð ð ð ”V×&Ò& uÑ-Ô-ð XØ”v—|’| CÑ(Ô(¨E¯KªK¸Ñ,<Ô,<Ò<Ð<ØŸšØ%&¤V°Q´VÐ5G¸q¿vºv¹x¼xÐQWÐXÐXñô ð ð ð !$§¢¨¬¯ª°cÑ):Ô):Ð;Q¸U¿[º[ÈÑ=MÔ=MÐPQÑ=QÐ;QÔ)RÑ SÔ S˜ØŸš°¸qÈ+Ð'VÐ'VÑWÔWÐWùØˆ> 'ˆ>ØˆHØð 	ØˆNÝÐ1Ð1¨Ð1Ñ1Ô1Ñ1Ô1Ð1s   ™'A Á
AÁAÁAc                óž  ‡— |                       ‰¦  «        Š| j        ržˆfd„| j        j        D ¦   «         }|rW|d         j        r*t
          j                             |d         j        ¦  «        n|d          	                    ¦   «         }‰|ddœS t          ˆfd„| j        j        D ¦   «         ¦  «        }|r‰dddœS  | j        j        ‰fi |¤ŽS )Nc                ó*   •— g | ]}|j         ‰k    ¯|‘ŒS r   r   ©r   rV  r   s     €r!   r"   z.SimpleCacheFileSystem.info.<locals>.<listcomp>|  s    ø€ ÐEÐEÐE�q°a´fÀ²n°n�°n°n°nr#   r   rq   rw  c              3  óR   •K  — | ]!}|j                              ‰d z   ¦  «        V — Œ"dS )rv  N)r   r{  r„  s     €r!   r€   z-SimpleCacheFileSystem.info.<locals>.<genexpr>€  s7   øè è € ÐRÐR°a�A”F×%Ò% d¨S¡jÑ1Ô1ÐRÐRÐRÐRÐRÐRr#   rx  )rG   r+   rò   r'   rÊ   rj   r   Úgetsizer&   r[  Úanyr(   rÓ   )r-   r   rV   r    rž   s    `   r!   rÓ   zSimpleCacheFileSystem.infoy  së   ø€ Ø×#Ò# DÑ)Ô)ˆØŒ=ð 	FØEÐEÐEÐE˜DÔ,Ô2ÐEÑEÔEˆAØð DØ34°Q´4´;ÐO•r”w—’ q¨¤t¤wÑ/Ô/Ð/ÀAÀaÄDÇIÂIÁKÄK�Ø $¨d¸FÐCÐCÐCÝÐRÐRÐRÐR¸4Ô;KÔ;QÐRÑRÔRÑRÔRˆAØð FØ $¨a¸ÐEÐEÐEØˆtŒwŒ|˜DÐ+Ð+ FÐ+Ð+Ð+r#   c                ó8  — t          |t          ¦  «        r$ | j        |                      |¦  «        |fi |¤Ž d S t          |t          ¦  «        r>|                     ¦   «         D ]'\  }} | j        |                      |¦  «        |fi |¤Ž Œ(d S t          d¦  «        ‚)Nzpath must be str or dict)rQ   rR   rß   rG   ÚdictrU  rK   )r-   r   rt  rV   rR  rS  s         r!   rÔ   zSimpleCacheFileSystem.pipe…  s½   € Ý�d�CÑ Ô ð 	9ØˆDŒN˜4×/Ò/°Ñ5Ô5°uÐGÐGÀÐGÐGÐGÐGÐGÝ˜�dÑ#Ô#ð 	9ØŸ
š
™œð Eð E‘��1Ø�”˜t×3Ò3°AÑ6Ô6¸ÐDÐD¸VÐDÐDÐDÐDðEð Eõ Ð7Ñ8Ô8Ð8r#   rÅ   c                óN  ‡ — t                                d|¦  «         ˆ fd„|D ¦   «         }d„ t          ||¦  «        D ¦   «         }d„ t          ||¦  «        D ¦   «         }‰ j                             ||¦  «         ˆ fd„|D ¦   «         } t          ¦   «         j        |||f||dœ|¤ŽS )Nzcat ranges %sc                ó:   •— g | ]}‰                      |¦  «        ‘ŒS r   r  ©r   r  r-   s     €r!   r"   z4SimpleCacheFileSystem.cat_ranges.<locals>.<listcomp>’  s'   ø€ Ð5Ð5Ð5¨!�$×"Ò" 1Ñ%Ô%Ð5Ð5Ð5r#   c                ó    — g | ]\  }}|d u ¯	|‘ŒS ©Fr   ©r   Úlr  s      r!   r"   z4SimpleCacheFileSystem.cat_ranges.<locals>.<listcomp>“  ó!   € ÐAÐAÐA™˜˜1°a¸5°j°j�!°j°j°jr#   c                ó    — g | ]\  }}|d u ¯	|‘ŒS rŽ  r   r�  s      r!   r"   z4SimpleCacheFileSystem.cat_ranges.<locals>.<listcomp>”  r‘  r#   c                ó:   •— g | ]}‰                      |¦  «        ‘ŒS r   r  rŒ  s     €r!   r"   z4SimpleCacheFileSystem.cat_ranges.<locals>.<listcomp>–  s'   ø€ Ð4Ð4Ð4¨�×!Ò! !Ñ$Ô$Ð4Ð4Ð4r#   r`  )rµ   r¶   r"  r(   r¼   r   r«   )	r-   r#  rd  re  ra  r<  rV   r0   r/   s	   `        r!   r«   z SimpleCacheFileSystem.cat_rangesŽ  sÖ   ø€ õ 	�Š�_ eÑ,Ô,Ð,Ø5Ð5Ð5Ð5¨uÐ5Ñ5Ô5ˆØAÐA¥ F¨EÑ 2Ô 2ÐAÑAÔAˆØAÐA¥ F¨EÑ 2Ô 2ÐAÑAÔAˆØŒ�Š�F˜FÑ#Ô#Ð#Ø4Ð4Ð4Ð4¨eÐ4Ñ4Ô4ˆØ+�Ñ Ô Ô+Ø�6˜4ð
Ø)0¸8ð
ð 
ØGMð
ð 
ð 	
r#   c                óN  — |                       |¦  «        }t          j                             | j        d         |¦  «        }t
                               d|¦  «         |                      ¦   «          d | _        | j	        �r | j
        j        |fddi|¤Ž5 }t          |d¦  «        5 }t          |t          ¦  «        r%t          d|j        j        |j        ¦  «        |_        | j	        dk    rt'          |¦  «        n| j	        }t)          |         |d¬¦  «        }d	}|r=t+          |d
d¦  «        }	|                     |	¦  «        }|                     |¦  «         |°=d d d ¦  «         n# 1 swxY w Y   d d d ¦  «         d S # 1 swxY w Y   d S | j
                             ||¦  «         d S )NrD   r1  ri   r“   rD  r   r¡   r¢   Tr£   rE  )r\   rj   r   r¸   rU   rµ   r¶   ro   r[   rZ   r(   r´   r·   rQ   r   r   r¾   rF  rž   r   r   rí   r:  rG  rH  )
r-   r   rV   r^  r&   r    rI  rÁ   rJ  rK  s
             r!   rë   z2SimpleCacheFileSystem._get_cached_file_before_open›  s  € Ø�lŠl˜4Ñ Ô ˆÝŒW�\Š\˜$œ, rÔ*¨CÑ0Ô0ˆÝ�ŠÐ0°$Ñ7Ô7Ð7à�Š‰ŒˆØˆÔàÔñ 	'Ø�””˜tÐ9Ð9¨$Ð9°&Ð9Ð9ð #¸QÅÀRÈÁÄð #ÐRTÝ˜aÕ!5Ñ6Ô6ð Då'¨¨1¬7¬?¸A¼FÑCÔC�A”Gð Ô'¨7Ò2Ð2õ & dÑ+Ô+Ð+àÔ)ð õ
 ˜$”K ¨Ð-Ñ-Ô-�Ø�Øð #Ý# A {°IÑ>Ô>�EØŸ6š6 %™=œ=�DØ—H’H˜T‘N”N�Nð ð #ð#ð #ð #ñ #ô #ð #ð #ð #ð #ð #ð #øøøð #ð #ð #ð #ð #ð #ð #ñ #ô #ð #ð #ð #ð #ð #ð #ð #øøøð #ð #ð #ð #ð #ð #ð  ŒG×Ò˜T 2Ñ&Ô&Ð&Ð&Ð&s7   ÂE=Â%B4E%ÅE=Å%E)	Å)E=Å,E)	Å-E=Å=FÆFr“   c                ó$  — |                       |¦  «        }|                      |¦  «        }d|v sd|v rQ|                      |¦  «        s<| j                             |¦  «        r | j        |fi |¤Ž nd|v rt          |¦  «        ‚|                      |¦  «        }d|v rd|vrt          ||¦  «        S t          j	         
                    | j        d         |¦  «        }d„ |                     ¦   «         D ¦   «         }t          | |f|| j         |dœ|¤ŽS )Nr•   rM  rN  rD   c                ó"   — i | ]\  }}|d v¯	||“ŒS rP  r   rQ  s      r!   rT  z/SimpleCacheFileSystem._open.<locals>.<dictcomp>É  s4   € ð !
ð !
ð !
á��1ØÐEÐEÐEð ˆqàEÐEÐEr#   )ri   r—   r&   )rG   r\   r‡   r(   r   rë   r/  r·   rj   r   r¸   rU   rU  r  r+   )r-   r   ri   rV   r^  r&   rW  s          r!   r´   zSimpleCacheFileSystem._open¶  sM  € Ø×#Ò# DÑ)Ô)ˆØ�lŠl˜4Ñ Ô ˆð �$ˆ;ˆ;˜# ˜+˜+Ø×#Ò# DÑ)Ô)ð 2à”7—>’> $Ñ'Ô'ð 2Ø5�DÔ5°dÐEÐE¸fÐEÐEÐEÐEØ˜D�[�[Ý+¨DÑ1Ô1Ð1à×Ò˜dÑ#Ô#ˆà�$ˆ;ˆ;˜3 d˜?˜?Ý˜˜D‘>”>Ð!åŒW�\Š\˜$œ, rÔ*¨CÑ0Ô0ˆð!
ð !
àŸš™œð!
ñ !
ô !
Ðõ
 ØØð
ð Øœ=Ð(Øð
ð 
ð $ð
ð 
ð 	
r#   rF   r2   ri  rh  )r3   r4   r5   r  r:   râ   r   rô   rJ   r‡   r|   r_   rß   rÏ   rÓ   rÔ   r«   rë   r´   r  r	  s   @r!   rk  rk  '  s  ø€ € € € € ðð ð €HØ€JØ-Ðð(ð (ð (ð (ð (ðð ð ðð ð ðð ð ð+ð +ð +ð +ð +ð +ð2ð 2ð 2ð 2ð@
,ð 
,ð 
,ð9ð 9ð 9ð 9ð ;Cð
ð 
ð 
ð 
ð'ð 'ð 'ð6
ð 
ð 
ð 
ð 
ð 
ð 
ð 
r#   rk  c                  ób   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd	„ Zd
„ Z	d„ Z
ed„ ¦   «         Zdd„Zd„ ZdS )r  z8A temporary local file, which will be uploaded on commitrD  Tr   c                óØ   — || _         t          ||¦  «        | _        || _        |r| j                             |¦  «         || _        d | _        || _        d| _        || _	        || _
        d S )NF)r&   r·   Úfhri   rZ  r   rž   r(   rÊ   r—   rV   )r-   r(   r   r&   ri   r—   rZ  rV   s           r!   rJ   zLocalTempFile.__init__Û  si   € ØˆŒÝ�r˜4‘.”.ˆŒØˆŒ	Øð 	ØŒG�LŠL˜ÑÔÐØˆŒ	ØˆŒ	ØˆŒØˆŒØ$ˆŒØˆŒˆˆr#   c                ól   — t           | j        | j        | j        d| j        |                      ¦   «         ffS )Nzr+b)r  r(   r   r&   r—   r[  rn   s    r!   rà   zLocalTempFile.__reduce__è  s1   € õ ØŒW�d”i ¤¨%°´À$Ç)Â)Á+Ä+ÐNð
ð 	
r#   c                ó   — | j         S rF   )r™  rn   s    r!   Ú	__enter__zLocalTempFile.__enter__ï  s	   € ØŒwˆr#   c                ó.   — |                       ¦   «          d S rF   r-  )r-   Úexc_typeÚexc_valÚexc_tbs       r!   Ú__exit__zLocalTempFile.__exit__ò  s   € Ø�
Š
‰Œˆˆˆr#   c                ó’   — | j         rd S | j                             ¦   «          d| _         | j        r|                      ¦   «          d S d S )NT)rÊ   r™  r²   r—   r.   rn   s    r!   r²   zLocalTempFile.closeõ  sL   € àŒ;ð 	ØˆFØŒ�Š‰ŒˆØˆŒØŒ?ð 	Ø�KŠK‰MŒMˆMˆMˆMð	ð 	r#   c                ój   — | j                              ¦   «          t          j        | j        ¦  «         d S rF   )r™  r²   rj   rŒ   r&   rn   s    r!   ÚdiscardzLocalTempFile.discardþ  s)   € ØŒ�Š‰ŒˆÝ
Œ	�$”'ÑÔÐÐÐr#   c                óP   —  | j         j        | j        g| j        gfi | j        ¤Ž d S rF   )r(   r)   r&   r   rV   rn   s    r!   r.   zLocalTempFile.commit  s2   € ð 	ˆŒŒ�T”W�I ¤	˜{Ð:Ð:¨d¬kÐ:Ð:Ð:Ð:Ð:r#   c                ó   — | j         S rF   r%   rn   s    r!   r.  zLocalTempFile.name  s	   € àŒwˆr#   rÅ   rR   c                ó   — d| j         › �S )NzLocalTempFile: r   rn   s    r!   Ú__repr__zLocalTempFile.__repr__  s   € Ø, ¤Ð,Ð,Ð,r#   c                ó,   — t          | j        |¦  «        S rF   )rí   r™  )r-   rð   s     r!   Ú__getattr__zLocalTempFile.__getattr__  s   € Ý�t”w Ñ%Ô%Ð%r#   N)rD  Tr   )rÅ   rR   )r3   r4   r5   r  rJ   rà   rœ  r¡  r²   r¤  r.   Úpropertyr.  r¨  rª  r   r#   r!   r  r  Ø  sÆ   € € € € € ØBÐBðð ð ð ð
ð 
ð 
ðð ð ðð ð ðð ð ðð ð ð;ð ;ð ;ð ðð ñ „Xðð-ð -ð -ð -ð&ð &ð &ð &ð &r#   r  )1Ú
__future__r   rú   Úloggingrj   rL   rx   rN   Úcollections.abcr   Úshutilr   Útypingr   r   r   Úfsspecr	   Úfsspec.callbacksr
   Úfsspec.compressionr   Úfsspec.corer   r   Úfsspec.exceptionsr   Ú#fsspec.implementations.cache_mapperr   Ú%fsspec.implementations.cache_metadatar   Úfsspec.implementations.chainedr   Úfsspec.implementations.localr   Úfsspec.specr   Úfsspec.transactionr   Úfsspec.utilsr   r   Ú	getLoggerrµ   r   r7   r  rk  r  r   r#   r!   ú<module>r¾     s’  ðØ "Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø 	€	€	€	Ø €€€Ø €€€Ø €€€Ø $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð Ø /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ð /à Ð Ð Ð Ð Ð Ø -Ð -Ð -Ð -Ð -Ð -Ø $Ð $Ð $Ð $Ð $Ð $Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø CÐ CÐ CÐ CÐ CÐ CØ ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø <Ð <Ð <Ð <Ð <Ð <Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø *Ð *Ð *Ð *Ð *Ð *Ø *Ð *Ð *Ð *Ð *Ð *àð HØGÐGÐGÐGÐGÐGà	ˆÔ	˜?Ñ	+Ô	+€ð	ð 	ð 	ð 	ð 	˜[ñ 	ô 	ð 	ðB
ð B
ð B
ð B
ð B
Ð)ñ B
ô B
ð B
ðJs
ð s
ð s
ð s
ð s
Ð0ñ s
ô s
ð s
ðln
ð n
ð n
ð n
ð n
Ð4ñ n
ô n
ð n
ðb8&ð 8&ð 8&ð 8&ð 8&ñ 8&ô 8&ð 8&ð 8&ð 8&r#   