§
    dŠtj  ã                  óÒ   — U d dl mZ d dlZd dlZd dlmZ d dlmZ 	 d dlZ	n# e
$ r	 esd dl	Z	Y nw xY wer%d dlmZ d dlmZmZmZ ddlmZ eeef         Zd	ed
<    G d„ d¦  «        ZdS )é    )ÚannotationsN)ÚTYPE_CHECKING)Úatomic_write)ÚIterator)ÚAnyÚLiteralÚ	TypeAliasé   )ÚCachingFileSystemr	   ÚDetailc                  ón   — e Zd ZdZd%d„Zd&d	„Zd'd„Z	 d(d)d„Zd*d„Zd+d„Z	d,d„Z
d-d„Zd.d „Zd,d!„Zd/d#„Zd$S )0ÚCacheMetadataa  Cache metadata.

    All reading and writing of cache metadata is performed by this class,
    accessing the cached files and blocks is not.

    Metadata is stored in a single file per storage directory in JSON format.
    For backward compatibility. No longer supports pickle.
    Ústorageú	list[str]c                óF   — |st          d¦  «        ‚|| _        i g| _        dS )zá

        Parameters
        ----------
        storage: list[str]
            Directories containing cached files, must be at least one. Metadata
            is stored in the last of these directories by convention.
        z3CacheMetadata expects at least one storage locationN)Ú
ValueErrorÚ_storageÚcached_files)Úselfr   s     úc/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/fsspec/implementations/cache_metadata.pyÚ__init__zCacheMetadata.__init__"   s3   € ð ð 	TÝÐRÑSÔSÐSàˆŒØ+-¨$ˆÔÐÐó    ÚfnÚstrÚreturnr   c                ó,  — t          |d¦  «        5 }t          j        |¦  «        }ddd¦  «         n# 1 swxY w Y   |                     ¦   «         D ]B}t	          |                     d¦  «        t          ¦  «        rt          |d         ¦  «        |d<   ŒC|S )z6Low-level function to load metadata from specific fileÚrNÚblocks)ÚopenÚjsonÚloadÚvaluesÚ
isinstanceÚgetÚlistÚset)r   r   ÚfÚloadedÚcs        r   Ú_loadzCacheMetadata._load1   s½   € å�"�c‰]Œ]ð 	"˜aÝ”Y˜q‘\”\ˆFð	"ð 	"ð 	"ñ 	"ô 	"ð 	"ð 	"ð 	"ð 	"ð 	"ð 	"øøøð 	"ð 	"ð 	"ð 	"à—’‘”ð 	/ð 	/ˆAÝ˜!Ÿ%š% ™/œ/­4Ñ0Ô0ð /Ý! ! H¤+Ñ.Ô.��(‘øØˆs   ‘2²6¹6Úmetadata_to_saveÚNonec                ó„   — t          |d¬¦  «        5 }t          j        ||¦  «         ddd¦  «         dS # 1 swxY w Y   dS )z4Low-level function to save metadata to specific fileÚw)ÚmodeN)r   r    Údump)r   r+   r   r'   s       r   Ú_savezCacheMetadata._save:   s‰   € å˜" 3Ð'Ñ'Ô'ð 	+¨1ÝŒIÐ&¨Ñ*Ô*Ð*ð	+ð 	+ð 	+ñ 	+ô 	+ð 	+ð 	+ð 	+ð 	+ð 	+ð 	+ð 	+øøøð 	+ð 	+ð 	+ð 	+ð 	+ð 	+s   ’5µ9¼9FÚwritable_onlyÚboolúIterator[tuple[str, str, bool]]c              #  óÌ   K  — t          | j        ¦  «        }t          | j        ¦  «        D ]8\  }}||dz
  k    }|r|sŒt          j                             |d¦  «        ||fV — Œ9dS )a  Yield locations (filenames) where metadata is stored, and whether
        writable or not.

        Parameters
        ----------
        writable: bool
            Set to True to only yield writable locations.

        Returns
        -------
        Yields (str, str, bool)
        r
   ÚcacheN)Úlenr   Ú	enumerateÚosÚpathÚjoin)r   r2   ÚnÚir   Úwritables         r   Ú_scan_locationszCacheMetadata._scan_locations?   s‡   è è € õ �”ÑÔˆÝ# D¤MÑ2Ô2ð 	Dð 	D‰JˆAˆwØ˜A ™E’zˆHØð  Xð ØÝ”'—,’,˜w¨Ñ0Ô0°'¸8ÐCÐCÐCÐCÐCð		Dð 	Dr   r:   ÚcfsúCachingFileSystem | Noneú#Literal[False] | tuple[Detail, str]c                óò  — t          |                      ¦   «         | j        ¦  «        D ]Î\  \  }}}}||vrŒ||                              ¦   «         }|�Y|j        r%|d         |j                             |¦  «        k    rŒV|j        r&t          j        ¦   «         |d         z
  |j        k    rŒƒt          j
                             ||d         ¦  «        }t          j
                             |¦  «        r||fc S ŒÏdS )zõIf path is in cache return its details, otherwise return ``False``.

        If the optional CachingFileSystem is specified then it is used to
        perform extra checks to reject possible matches, such as if they are
        too old.
        NÚuidÚtimer   F)Úzipr?   r   ÚcopyÚcheck_filesÚfsÚukeyÚexpiryrE   r9   r:   r;   Úexists)r   r:   r@   r   ÚbaseÚ_r6   Údetails           r   Ú
check_filezCacheMetadata.check_fileU   sù   € õ %(¨×(<Ò(<Ñ(>Ô(>ÀÔ@QÑ$RÔ$Rð 	"ð 	"Ñ ‰MˆR��q˜5Ø˜5Ð Ð ØØ˜4”[×%Ò%Ñ'Ô'ˆFàˆØ”?ð  v¨e¤}¸¼¿ºÀDÑ8IÔ8IÒ'IÐ'IàØ”:ð ¥$¤)¡+¤+°°v´Ñ">ÀÄÒ"KÐ"Kàå”—’˜d F¨4¤LÑ1Ô1ˆBÝŒw�~Š~˜bÑ!Ô!ð "Ø˜r�zÐ!Ð!Ð!ð"àˆur   Úexpiry_timeÚintútuple[list[str], bool]c                óž  — g }| j         d                              ¦   «                              ¦   «         D ]¯\  }}t          j        ¦   «         |d         z
  |k    rŠ|                     dd¦  «        }|st          d|› �¦  «        ‚t          j                             | j	        d         |¦  «        }| 
                    |¦  «         | j         d                              |¦  «         Œ°| j         d         rLt          j                             | j	        d         d¦  «        }|                      | j         d         |¦  «         | j         d          }||fS )zûRemove expired metadata from the cache.

        Returns names of files corresponding to expired metadata and a boolean
        flag indicating whether the writable cache is empty. Caller is
        responsible for deleting the expired files.
        éÿÿÿÿrE   r   Ú z)Cache metadata does not contain 'fn' for r6   )r   rG   ÚitemsrE   r$   ÚRuntimeErrorr9   r:   r;   r   ÚappendÚpopr1   )r   rQ   Úexpired_filesr:   rO   r   Ú
cache_pathÚwritable_cache_emptys           r   Úclear_expiredzCacheMetadata.clear_expiredp   sB  € ð ˆØ Ô-¨bÔ1×6Ò6Ñ8Ô8×>Ò>Ñ@Ô@ð 		0ð 		0‰LˆD�&ÝŒy‰{Œ{˜V Fœ^Ñ+¨kÒ9Ð9Ø—Z’Z  bÑ)Ô)�Øð Ý&ØJÀDÐJÐJñô ð õ ”W—\’\ $¤-°Ô"3°RÑ8Ô8�Ø×$Ò$ RÑ(Ô(Ð(ØÔ! "Ô%×)Ò)¨$Ñ/Ô/Ð/øàÔ˜RÔ ð 	:ÝœŸš d¤m°BÔ&7¸ÑAÔAˆJØ�JŠJ�tÔ(¨Ô,¨jÑ9Ô9Ð9à#'Ô#4°RÔ#8Ð8ÐØÐ2Ð2Ð2r   c                ó  — g }|                       ¦   «         D ]c\  }}}t          j                             |¦  «        r)|                     |                      |¦  «        ¦  «         ŒN|                     i ¦  «         Œd|pi g| _        dS )z>Load all metadata from disk and store in ``self.cached_files``N)r?   r9   r:   rL   rY   r*   r   )r   r   r   rN   s       r   r!   zCacheMetadata.loadŠ   s‹   € àˆØ×,Ò,Ñ.Ô.ð 	(ð 	(‰HˆB��1ÝŒw�~Š~˜bÑ!Ô!ð (à×#Ò# D§J¢J¨r¡N¤NÑ3Ô3Ð3Ð3à×#Ò# BÑ'Ô'Ð'Ð'Ø(Ð0¨R¨DˆÔÐÐr   r'   r   c                óž   — | j         d         |         }|d         dur-t          |d         ¦  «        |j        z  |j        k    r	d|d<   dS dS dS )z‹Perform side-effect actions on closing a cached file.

        The actual closing of the file is the responsibility of the caller.
        rU   r   TN)r   r7   Ú	blocksizeÚsize)r   r'   r:   r)   s       r   Úon_close_cached_filez"CacheMetadata.on_close_cached_file•   s_   € ð Ô˜bÔ! $Ô'ˆØˆXŒ;˜dÐ"Ð"¥s¨1¨X¬;Ñ'7Ô'7¸!¼+Ñ'EÈÌÒ'OÐ'OØˆAˆh‰KˆKˆKð #Ð"Ð'OÐ'Or   ú
str | Nonec                ó  — |                       |d¦  «        }|sdS |\  }}|                     | j        d         ¦  «        r5| j        d                              |¦  «         |                      ¦   «          nt          d¦  «        ‚|S )zÒRemove metadata of cached file.

        If path is in the cache, return the filename of the cached file,
        otherwise return ``None``.  Caller is responsible for deleting the
        cached file.
        NrU   z<Can only delete cached file in last, writable cache location)rP   Ú
startswithr   r   rZ   ÚsaveÚPermissionError)r   r:   ÚdetailsrN   r   s        r   Úpop_filezCacheMetadata.pop_fileŸ   s�   € ð —/’/ $¨Ñ-Ô-ˆØð 	Ø�4Ø‰ˆˆ2Ø�=Š=˜œ rÔ*Ñ+Ô+ð 	ØÔ˜bÔ!×%Ò% dÑ+Ô+Ð+Ø�IŠI‰KŒKˆKˆKå!ØNñô ð ð ˆ	r   c                óz  — t          |                      ¦   «         | j        ¦  «        D �]‘\  \  }}}}|sŒt          j                             |¦  «        rÛ|                      |¦  «        }|                     ¦   «         D ]�\  }}||v r„|d         du s||         d         du rd|d<   n.||         d         }|                     |d         ¦  «         ||d<   t          |d         ||         d         ¦  «        |d<   ||         d         |d<   ŒŽ|                     ¦   «         D ]\  }}||vr|||<   Œn|}d„ |                     ¦   «         D ¦   «         }| 
                    ¦   «         D ]5}t          |d         t          ¦  «        rt          |d         ¦  «        |d<   Œ6|                      ||¦  «         || j        d<   �Œ“dS )zSave metadata to diskr   TrE   rD   c                ó>   — i | ]\  }}||                      ¦   «         “ŒS © )rG   )Ú.0ÚkÚvs      r   ú
<dictcomp>z&CacheMetadata.save.<locals>.<dictcomp>Ð   s&   € ÐBÐBÐB¡T Q¨�Q˜Ÿš™œÐBÐBÐBr   rU   N)rF   r?   r   r9   r:   rL   r*   rW   ÚupdateÚmaxr"   r#   r&   r%   r1   )	r   r   rN   r>   r6   r   ro   r)   r   s	            r   rg   zCacheMetadata.save³   së  € å(+¨D×,@Ò,@Ñ,BÔ,BÀDÔDUÑ(VÔ(Vð  	1ñ  	1Ñ$ÑˆR��H˜uØð ØåŒw�~Š~˜bÑ!Ô!ð %Ø#Ÿzšz¨"™~œ~�Ø(×.Ò.Ñ0Ô0ð 3ð 3‘D�A�qØ˜E�z�zØ˜Xœ;¨$Ð.Ð.°%¸´(¸8Ô2DÈÐ2LÐ2LØ*.˜A˜h™K˜Kð &+¨1¤X¨hÔ%7˜FØ"ŸMšM¨!¨H¬+Ñ6Ô6Ð6Ø*0˜A˜h™KÝ$'¨¨&¬	°5¸´8¸FÔ3CÑ$DÔ$D˜˜&™	Ø#(¨¤8¨E¤?˜˜%™øð "ŸKšK™MœMð ,ð ,‘D�A�qØ Ð,Ð,Ø*+˜ Q™øð,ð  %�ØBÐB¨\×-?Ò-?Ñ-AÔ-AÐBÑBÔBˆEØ—\’\‘^”^ð 4ð 4�Ý˜a œk­3Ñ/Ô/ð 4Ý"& q¨¤{Ñ"3Ô"3�A�h‘KøØ�JŠJ�u˜bÑ!Ô!Ð!Ø$0ˆDÔ˜bÑ!Ñ!ðA 	1ð  	1r   rO   c                ó&   — || j         d         |<   dS )z8Update metadata for specific file in memory, do not saverU   N)r   )r   r:   rO   s      r   Úupdate_filezCacheMetadata.update_file×   s   € à&,ˆÔ˜"Ô˜dÑ#Ð#Ð#r   N)r   r   )r   r   r   r   )r+   r   r   r   r   r,   )F)r2   r3   r   r4   )r:   r   r@   rA   r   rB   )rQ   rR   r   rS   )r   r,   )r'   r   r:   r   r   r,   )r:   r   r   rd   )r:   r   rO   r   r   r,   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r*   r1   r?   rP   r^   r!   rc   rj   rg   ru   rm   r   r   r   r      s
  € € € € € ðð ð/ð /ð /ð /ðð ð ð ð+ð +ð +ð +ð %*ðDð Dð Dð Dð Dð,ð ð ð ð63ð 3ð 3ð 3ð4	1ð 	1ð 	1ð 	1ðð ð ð ðð ð ð ð("1ð "1ð "1ð "1ðH-ð -ð -ð -ð -ð -r   r   )Ú
__future__r   r9   rE   Útypingr   Úfsspec.utilsr   Úujsonr    ÚImportErrorÚcollections.abcr   r   r   r	   Úcachedr   Údictr   r   Ú__annotations__r   rm   r   r   ú<module>rƒ      s3  ðØ "Ð "Ð "Ð "Ð "Ð "Ð "à 	€	€	€	Ø €€€Ø  Ð  Ð  Ð  Ð  Ð  à %Ð %Ð %Ð %Ð %Ð %ðØÐÐÐÐøØð ð ð Øð Øˆˆˆøøðøøøð ð 'Ø(Ð(Ð(Ð(Ð(Ð(Ø.Ð.Ð.Ð.Ð.Ð.Ð.Ð.Ð.Ð.à)Ð)Ð)Ð)Ð)Ð)à˜S #˜Xœ€FÐ&Ð&Ð&Ñ&ðA-ð A-ð A-ð A-ð A-ñ A-ô A-ð A-ð A-ð A-s   �" ¢0¯0