Ë
    }D™j{J  ã                   ó0  — d 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 dd
lmZmZmZ ddlmZmZ ddlmZmZmZ ddlmZmZ  ee«      Z  G d„ de«      Z! G d„ de«      Z" G d„ de"«      Z# G d„ de«      Z$ddee%   de%fd„Z&y)z´Filesystem cache backend. For usage details, see :ref:`Backends: Filesystem <filesystem>`.

.. automodsumm:: requests_cache.backends.filesystem
   :classes-only:
   :nosignatures:
é    )Úcontextmanager)Ú	getLogger)Úmakedirs)ÚPath)ÚPickleError)Úrmtree)ÚRLock)Útime_ns)ÚAnyÚIteratorÚOptionalé   )ÚSerializerTypeÚjson_serializeré   )Ú	BaseCacheÚBaseStorageÚ	StrOrPath)Ú
SQLiteDictÚget_cache_pathc            
       ó’   ‡ — e Zd ZdZ	 	 	 	 ddedededee   fˆ fd„Ze	de
fd„«       Ze	defd	„«       Zdee   fd
„Zd„ Zˆ fd„Zˆ xZS )Ú	FileCachea[  Filesystem cache backend.

    Args:
        cache_name: Base directory for cache files
        use_cache_dir: Store database in a user cache directory (e.g., `~/.cache/`)
        use_temp: Store cache files in a temp directory (e.g., ``/tmp/http_cache/``).
            Note: if ``cache_name`` is an absolute path, this option will be ignored.
        decode_content: Decode JSON or text response body into a human-readable format
        extension: Extension for cache files. If not specified, the serializer default extension
            will be used.
        max_cache_bytes: Enable LRU caching, and set the maximum total size (in bytes) of cached
            responses on the file system.
        max_file_bytes: The maximum size of a single file.
            By default, this is the same as ``max_cache_bytes``.
            Only used if ``max_cache_bytes`` is set.
        block_bytes: The size of a block of data on the file system, which will be used when
            computing total file size on disk. Only used if ``max_cache_bytes`` is set.
        sync_index: On startup, sync LRU metadata with any changes on disk since last use. Use this
            if you intend to modify cache files outside of requests-cache. Leave off to reduce
            startup time for larger caches. Only used if ``max_cache_bytes`` is set.
        lock: Replace the default :class:`threading.RLock` object without your own. Use this if you
            want to share the lock between multiple cache instances, and/or use a different lock
            type (such as :py:class:`multiprocessing.RLock` or :py:class:`filelock.FileLock`).
    Ú
cache_nameÚuse_tempÚdecode_contentÚ
serializerc                 ó  •— t        ‰| �  ddt        |«      i|¤Ž |rd|i|¥n|} d|v rt        nt        |f||dœ|¤Ž| _        | j                  5  t        | j                  dz  dfdd i|¤Ž| _	        d d d «       y # 1 sw Y   y xY w)Nr   r   Úmax_cache_bytes)r   r   zredirects.sqliteÚ	redirects© )
ÚsuperÚ__init__ÚstrÚLRUFileDictÚFileDictÚ	responsesÚlockr   Ú	cache_dirr   )Úselfr   r   r   r   ÚkwargsÚskwargsÚ	__class__s          €ún/var/www/html/Astrologybackend/backend/venv/lib/python3.12/site-packages/requests_cache/backends/filesystem.pyr"   zFileCache.__init__3   s¨   ø€ ô 	‰ÑÑ>¤C¨
£OÐ>°vÒ>Ù:D�< Ð6¨vÑ6È&ˆØ$\Ð3DÈÑ3N¥KÔT\Øð$
Ø!)¸.ñ$
ØLSñ$
ˆŒð �Y‰Yñ 	Ü)3Ø—‘Ð!3Ñ3°[ñ*ØMQð*ØU[ñ*ˆDŒN÷	÷ 	ñ 	ús   Á"A<Á<BÚreturnc                 ó.   — | j                   j                  S ©zThe lock used by the cache.)r&   r'   ©r)   s    r-   r'   zFileCache.lockE   s   € ð �~‰~×"Ñ"Ð"ó    c                 ó@   — t        | j                  j                  «      S )zBase directory for cache files)r   r&   r(   r1   s    r-   r(   zFileCache.cache_dirJ   s   € ô �D—N‘N×,Ñ,Ó-Ð-r2   c                 ó6   — | j                   j                  «       S )ú/Get absolute file paths to all cached responses)r&   Úpathsr1   s    r-   r6   zFileCache.pathsO   s   € à�~‰~×#Ñ#Ó%Ð%r2   c                 ó®   — | j                   5  | j                  j                  «        | j                  j	                  «        ddd«       y# 1 sw Y   yxY w)zClear the cacheN)r'   r&   Úclearr   Úinit_dbr1   s    r-   r8   zFileCache.clearS   s@   € ð �Y‰Yñ 	%Ø�N‰N× Ñ Ô"Ø�N‰N×"Ñ"Ô$÷	%÷ 	%ñ 	%ús   �5AÁAc                 óf   •— | j                   5  t        ‰| �  |i |¤Žcd d d «       S # 1 sw Y   y xY w©N)r'   r!   Údelete©r)   Úargsr*   r,   s      €r-   r<   zFileCache.deleteZ   s0   ø€ Ø�Y‰Yñ 	3Ü‘7‘> 4Ð2¨6Ñ2÷	3÷ 	3ò 	3ús   Ž'§0)Ú
http_cacheFTN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úboolr   r   r"   Úpropertyr	   r'   r   r(   r   r6   r8   r<   Ú__classcell__©r,   s   @r-   r   r      s›   ø„ ñð6 !-ØØ#Ø/3ñàðð ðð ð	ð
 ˜^Ñ,õð$ ð#�eò #ó ð#ð ð.˜4ò .ó ð.ð&�x ‘~ó &ò%÷3ð 3r2   r   c                   ó  ‡ — e Zd ZdZdddedfdedededee   dee	   d	ee
   fˆ fd
„Zede
fd„«       Zeddee   defd„«       Zdedefd„Zdefd„Zd„ Zd„ Zdefd„Zdee   fd„Zdefd„Zdd„Zd„ Zdee   fd„Zdefd„Zˆ xZS )r%   zˆA dictionary-like interface to files on the local filesystem.

    The cache directory will be created if it doesn't already exist.
    FNr   r   Úuse_cache_dirÚ	extensionr   r'   c                 ó  •— t        ‰| �  dd|i|¤Ž t        |||¬«      | _        t	        || j
                  «      | _        t        | j
                  dd«      | _        |�|n	t        «       | _
        t        | j                  d¬«       y )Nr   )rI   r   Ú	is_binaryFT)Úexist_okr    )r!   r"   r   r(   Ú_get_extensionr   rJ   ÚgetattrrL   r	   Ú_lockr   )	r)   r   r   rI   rJ   r   r'   r*   r,   s	           €r-   r"   zFileDict.__init__e   so   ø€ ô 	‰ÑÑ9 JÐ9°&Ò9Ü'¨
À-ÐZbÔcˆŒÜ'¨	°4·?±?ÓCˆŒÜ  §¡°+¸uÓEˆŒØ!Ð-‘T´5³7ˆŒ
Ü�—‘¨$Ö/r2   r.   c                 ó   — | j                   S r0   )rP   r1   s    r-   r'   zFileDict.lockv   s   € ð �z‰zÐr2   ÚkeyÚignore_errorsc              #   óÈ   K  — 	 | j                   5  d–— ddd«       y# 1 sw Y   yxY w# t        t        t        t        f$ r}|st        d|›d�«      |‚Y d}~yd}~ww xY w­w)zPAttempt an I/O operation, and either ignore errors or re-raise them as KeyErrorsNzFile for key z not found.)rP   ÚEOFErrorÚIOErrorÚOSErrorr   ÚKeyError)r)   rR   rS   Úes       r-   Ú_try_iozFileDict._try_io{   sb   è ø€ ð	JØ—‘ñ Û÷÷ ñ ûäœ'¤7¬KÐ8ò 	JÙ Ü ¨s¨g°[ÐAÓBÈÐIô !ûð	JüsD   ‚A"„* �•* �A"ž'£* ¦A"§* ªAÁAÁA"ÁAÁA"c                 ó<   — | j                   |› | j                  › �z  S r;   )r(   rJ   ©r)   rR   s     r-   Ú	_key2pathzFileDict._key2path…   s   € Ø�~‰~ 3 %¨¯©Ð'7Ð 8Ñ8Ð8r2   c                 ó0  — | j                   rdnd}| j                  |«      5  | j                  |«      j                  |«      5 }| j	                  ||j                  «       «      cd d d «       cd d d «       S # 1 sw Y   nxY w	 d d d «       y # 1 sw Y   y xY w)NÚrbÚr)rL   rZ   r]   ÚopenÚdeserializeÚread)r)   rR   ÚmodeÚfs       r-   Ú__getitem__zFileDict.__getitem__ˆ   sˆ   € Ø—~’~‰t¨3ˆØ�\‰\˜#Óñ 	7Ø—‘ Ó$×)Ñ)¨$Ó/ð 7°1Ø×'Ñ'¨¨Q¯V©V«XÓ6÷7ð 7÷	7ñ 	7÷7ð 7úð 7÷	7÷ 	7ñ 	7ús#   ¢!BÁ A6Á#	BÁ6A?	Á;BÂBc                 óŽ   — | j                  |«      5  | j                  |«      j                  «        d d d «       y # 1 sw Y   y xY wr;   )rZ   r]   Úunlinkr\   s     r-   Ú__delitem__zFileDict.__delitem__Ž   s8   € Ø�\‰\˜#Óñ 	)Ø�N‰N˜3Ó×&Ñ&Ô(÷	)÷ 	)ñ 	)ús	   ’ ;»Ac                 ó  — | j                  |«      5  | j                  |«      j                  | j                  rdnd¬«      5 }|j	                  | j                  |«      «       d d d «       d d d «       y # 1 sw Y   ŒxY w# 1 sw Y   y xY w)NÚwbÚw)rd   )rZ   r]   ra   rL   ÚwriteÚ	serialize)r)   rR   Úvaluere   s       r-   Ú__setitem__zFileDict.__setitem__’   sw   € Ø�\‰\˜#Óñ 	/Ø—‘ Ó$×)Ñ)°t·~²~©tÈ3Ð)ÓOð /ÐSTØ—‘˜Ÿ™ uÓ-Ô.÷/÷	/ð 	/÷/ð /ú÷	/ð 	/ús#   ’0B Á!A4Á#B Á4A=	Á9B Â B	c                 ó„   — | j                   5  | j                  |«      j                  «       cd d d «       S # 1 sw Y   y xY wr;   )rP   r]   Úexistsr\   s     r-   Ú__contains__zFileDict.__contains__—   s3   € Ø�Z‰Zñ 	0Ø—>‘> #Ó&×-Ñ-Ó/÷	0÷ 	0ò 	0ús   �6¶?c              #   ó@   K  — | j                  «       E d {  –—†  y 7 Œ­wr;   )Úkeysr1   s    r-   Ú__iter__zFileDict.__iter__›   s   è ø€ Ø—9‘9“;×Òús   ‚–—c                 óB   — t        d„ | j                  «       D «       «      S )Nc              3   ó    K  — | ]  }d –— Œ y­w)r   Nr    )Ú.0Ú_s     r-   ú	<genexpr>z#FileDict.__len__.<locals>.<genexpr>Ÿ   s   è ø€ Ò+˜”1Ñ+ùs   ‚)Úsumr6   r1   s    r-   Ú__len__zFileDict.__len__ž   s   € ÜÑ+˜dŸj™j›lÔ+Ó+Ð+r2   c                 ó´   — | j                  d¬«      5  t        | j                  d¬«       | j                  j                  «        ddd«       y# 1 sw Y   yxY w)zEmpty the cache directory.T)rS   N)rZ   r   r(   Úmkdirr1   s    r-   r8   zFileDict.clear¡   sC   € à�\‰\¨ˆ\Ó-ñ 	#Ü�4—>‘>°Õ6Ø�N‰N× Ñ Ô"÷	#÷ 	#ñ 	#ús   “2AÁAc                 ó\   — | j                  «       D �cg c]  }|j                  ‘Œ c}S c c}w r;   )r6   Ústem)r)   Úpaths     r-   ru   zFileDict.keys§   s    € Ø&*§j¡j£lÖ3˜d�—	“	Ò3Ð3ùÒ3s   “)c                 ó–   — | j                   5  | j                  j                  d| j                  › �«      cddd«       S # 1 sw Y   yxY w)r5   Ú*N)rP   r(   ÚglobrJ   r1   s    r-   r6   zFileDict.pathsª   s<   € à�Z‰Zñ 	=Ø—>‘>×&Ñ&¨¨4¯>©>Ð*:Ð';Ó<÷	=÷ 	=ò 	=ús	   �(?¿Ac                 ó†   — | j                   5  t        d„ | j                  «       D «       «      cddd«       S # 1 sw Y   yxY w)ú)Return the size of the database, in bytesc              3   óP   K  — | ]  }|j                  «       j                  –— Œ  y ­wr;   )ÚstatÚst_size)ry   r‚   s     r-   r{   z FileDict.size.<locals>.<genexpr>²   s   è ø€ ÒD¨t�t—y‘y“{×*Õ*ÑDùs   ‚$&N)rP   r|   r6   r1   s    r-   ÚsizezFileDict.size¯   s6   € à�Z‰Zñ 	EÜÑD°t·z±z³|ÔDÓD÷	E÷ 	Eò 	Eús	   � 7·A )NF)r.   N)r@   rA   rB   rC   r   r   rD   r   r#   r   r	   r"   rE   r'   r   rZ   r   r]   rf   ri   rp   rs   r   rv   Úintr}   r8   ru   r6   r‹   rF   rG   s   @r-   r%   r%   _   s#  ø„ ñð Ø#Ø#'Ø/>Ø $ñ0àð0ð ð0ð ð	0ð
 ˜C‘=ð0ð ˜^Ñ,ð0ð �u‰oõ0ð" ð�eò ó ðð ñJ˜8 C™=ð JÀò Jó ðJð9˜Sð 9 Tó 9ð7˜só 7ò)ò/ð
0 4ó 0ð˜( 3™-ó ð,˜ó ,ó#ò4ð=�x ‘~ó =ð
E�c÷ Er2   r%   c            	       óª   ‡ — e Zd ZdZdddddœdeded	ee   d
efˆ fd„Zˆ fd„Zde	de
ddfˆ fd„Zˆ fd„Zdefd„Zd„ Zdedefd„Zˆ fd„Zdefd„Zˆ xZS )r$   aQ  A size-restricted version of FileDict, using LRU eviction.

    Args:
        block_bytes: The size of a block of data on the file system.
            File sizes will be aligned with this.
        max_cache_bytes: The maximum total size of all files in the cache.
        max_file_bytes: The maximum size of a single file.
            By default, this is the same as ``max_cache_bytes``.
        sync_index: Check for filesystem changes since last use. Use this if you intend to modify
            cache files outside of requests-cache. Leave off to reduce startup time for larger caches.
    r   i  @NF)Úblock_bytesr   Úmax_file_bytesÚ
sync_indexrŽ   r   r�   r�   c                óÄ  •— t        ‰| �  |i |¤Ž || _        || _        |xs || _        | j                  | j                  kD  rt        d|› d�«      ‚| j                  | j                  kD  rt        d|› d�«      ‚| j                  dk  rt        d|› �«      ‚t        | j                  dz  dfi |¤Ž| _        |st        | j                  «      dk(  r| j                  «        y y )	Nz<max_file_bytes must be smaller or equal to max_cache_bytes (ú)z1block_bytes must be smaller than max_file_bytes (r   z(block_bytes must be greater than 0, not zlru.dbÚlrur   )r!   r"   r   rŽ   r�   Ú
ValueErrorÚLRUDictr(   Ú	lru_indexÚlenÚ_sync_lru_index)r)   rŽ   r   r�   r�   r>   r*   r,   s          €r-   r"   zLRUFileDict.__init__Â   sô   ø€ ô 	‰Ñ˜$Ð) &Ò)Ø.ˆÔØ&ˆÔØ,Ò?°ˆÔØ×Ñ ×!5Ñ!5Ò5ÜØNÈÐN_Ð_`Ðaóð ð ×Ñ˜d×1Ñ1Ò1ÜÐPÐQ_ÐP`Ð`aÐbÓcÐcØ×Ñ˜aÒÜÐGÈÀ}ÐUÓVÐVä  §¡°(Ñ!:¸EÑLÀVÑLˆŒñ œ˜TŸ^™^Ó,°Ò1Ø× Ñ Õ"ð 2r2   c                 ó0  •— t         ‰| �  |«      }	 | j                  j                  |«       |S # t        $ r] | j                  |«      }|j                  «       r8| j                  |j                  «       j                  «      }|| j                  |<   Y |S w xY w)z7Get a value and update its access time in the LRU index)
r!   rf   r–   Úupdate_access_timerX   r]   rr   Ú_get_size_on_diskr‰   rŠ   )r)   rR   ro   Ú	file_pathÚ	file_sizer,   s        €r-   rf   zLRUFileDict.__getitem__Þ   sŒ   ø€ ä‘Ñ# CÓ(ˆð	0Ø�N‰N×-Ñ-¨cÔ2ð ˆøô ò 	0ØŸ™ sÓ+ˆIØ×ÑÔ!Ø ×2Ñ2°9·>±>Ó3C×3KÑ3KÓL�	Ø&/�—‘˜sÑ#øàˆð	0ús   ’/ ¯A"BÂBrR   ro   r.   c                 óú  •— | j                  |«      }t        |t        «      r|j                  d«      n|}~| j	                  t        |«      «      }|| j                  kD  r't        j                  d|›d| j                  › d�«       y | j                  |«      5  	 t        ‰| �-  |«       | j                  |«       t        ‰| �9  ||«       || j                  |<   d d d «       y # t        $ r Y ŒDw xY w# 1 sw Y   y xY w)NzUTF-8zNot caching z because it is larger than z bytes.)rn   Ú
isinstancer#   Úencoder›   r—   r�   ÚloggerÚdebugrZ   r!   ri   rX   Ú_evictrp   r–   )r)   rR   ro   ÚcontentÚdatar�   r,   s         €r-   rp   zLRUFileDict.__setitem__î   sô   ø€ Ø—.‘. Ó'ˆÜ*4°W¼cÔ*Bˆw�~‰~˜gÔ&ÈˆØØ×*Ñ*¬3¨t«9Ó5ˆ	à�t×*Ñ*Ò*Ü�L‰LØ˜s˜gÐ%@À×ATÑATÐ@UÐU\Ð]ôð à�\‰\˜#Óñ 	,ðÜ‘Ñ# CÔ(ð
 �K‰K˜	Ô"Ü‰GÑ  UÔ+ð #,ˆD�N‰N˜3Ñ÷	,ð 	,øô ò Ùðú÷	,ð 	,ús0   ÂC1ÂC"Â)0C1Ã"	C.Ã+C1Ã-C.Ã.C1Ã1C:c                 ó^   •— 	 | j                   |= t        ‰| �  |«       y# t        $ r Y Œw xY w)z.Delete a file and remove it from the LRU indexN)r–   rX   r!   ri   )r)   rR   r,   s     €r-   ri   zLRUFileDict.__delitem__  s7   ø€ ð	Ø—‘˜sÐ#ô 	‰Ñ˜CÕ øô ò 	Ùð	ús   ƒ   	,«,Údesired_free_bytesc                 óÒ   — | j                   j                  «       }||z   | j                  z
  }|dk  ry| j                   j                  |«      }|D ]  }	 | |= Œ y# t        $ r Y Œw xY w)z’Make space in the cache to fit the given number of bytes, if needed.

        This starts deleting the least recently used entries first.
        r   N)r–   Ú
total_sizer   Úget_lrurX   )r)   r§   Úcurrent_sizeÚspace_neededÚkeys_to_evictrR   s         r-   r£   zLRUFileDict._evict  s|   € ð
 —~‘~×0Ñ0Ó2ˆØ#Ð&8Ñ8¸4×;OÑ;OÑOˆØ˜1ÒØð Ÿ™×.Ñ.¨|Ó<ˆØ ò 	ˆCðØ˜‘Iñ	øô ò Ùðús   ÁAÁ	A&Á%A&c                 ó*  — | j                   5  | j                  j                  «        | j                  «       D ]D  }|j                  }| j                  |j                  «       j                  «      | j                  |<   ŒF 	 ddd«       y# 1 sw Y   yxY w)z(Rebuild the LRU index from files on diskN)rP   r–   r8   r6   r�   r›   r‰   rŠ   )r)   r‚   rR   s      r-   r˜   zLRUFileDict._sync_lru_index#  sw   € à�Z‰Zñ 	RØ�N‰N× Ñ Ô"ØŸ
™
›ò R�Ø—i‘i�Ø&*×&<Ñ&<¸T¿Y¹Y»[×=PÑ=PÓ&Q�—‘˜sÒ#ñR÷	R÷ 	Rñ 	Rús   �A2B	Â	Br�   c                 óx   — |dk  rdnd}||z  | j                   z   dz
  | j                   z  | j                   z  |z  S )zKReturn a file size on disk, rounded up to fit the blocks on the file systemr   éÿÿÿÿr   )rŽ   )r)   r�   Úsigns      r-   r›   zLRUFileDict._get_size_on_disk+  sH   € à ’]‰r¨ˆà˜Ñ × 0Ñ 0Ñ0°1Ñ4¸×9IÑ9IÑIÈD×L\ÑL\Ñ\Ð_cÑcð	
r2   c                 ód   •— t         ‰| �  «        | j                  j                  «        d| _        y)z(Clear the cache directory and LRU index.FN)r!   r8   r–   Ú_lru_initialized)r)   r,   s    €r-   r8   zLRUFileDict.clear2  s$   ø€ ä‰‰ŒØ�‰×ÑÔØ %ˆÕr2   c                 ó6   — | j                   j                  «       S )r‡   )r–   r©   r1   s    r-   r‹   zLRUFileDict.size8  s   € à�~‰~×(Ñ(Ó*Ð*r2   )r@   rA   rB   rC   rŒ   r   rD   r"   rf   r#   r   rp   ri   r£   r˜   r›   r8   r‹   rF   rG   s   @r-   r$   r$   µ   s¡   ø„ ñ
ð Ø0Ø(,Ø ò#ð ð#ð ð	#ð
 ! ™ð#ð õ#ô8ð ,˜sð ,¨3ð ,°4õ ,ô2!ð¨ó ò$Rð
¨3ð 
°3ó 
ô&ð+�c÷ +r2   r$   c            
       óª   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zdefd„Zde	defd	„Z
ˆ fd
„Zd„ Zdefd„Z	 	 	 dde	dedee   dee	   fd„Zdefd„Zde	fd„Zˆ xZS )r•   aî  A SQLite db used to track LRU metadata for cached items:

    * ``key``: The cache key
    * ``access_time``: The last access time, as a UNIX timestamp in nanoseconds
    * ``size``: The size of the cached item, in bytes
    * ``total_size`` Combined size of all cache items in bytes, accessed with :py:meth:`total_size`.

    Implementation Notes:

    * ``total_size`` is managed by triggers and stored in a separate single-row table.
    * As a dict-like interface, ``size`` is treated as the main value and ``access_time`` is set
      automatically and updated with :py:meth:`update_access_time`.
    * :py:meth:`get_lru` Can select multiple keys to evict, up to an arbitrary total size, within a
      single query using a window function.
    c                 óH   •— |j                  dd «       t        ‰| �  |i |¤Ž y )Nr   )Úpopr!   r"   r=   s      €r-   r"   zLRUDict.__init__N  s#   ø€ Ø�
‰
�< Ô&Ü‰Ñ˜$Ð) &Ó)r2   c           
      óþ  — | j                  «        | j                  d¬«      5 }|j                  d| j                  › d�«       |j                  d| j                  › d�«       |j                  d| j                  › d�«       |j                  d| j                  › d	�«       |j                  d
| j                  › d�«       |j                  d| j                  › d| j                  › d| j                  › d�«       |j                  d| j                  › d| j                  › d| j                  › d�«       |j                  d| j                  › d| j                  › d| j                  › d�«       d d d «       y # 1 sw Y   y xY w)NT©ÚcommitzCREATE TABLE IF NOT EXISTS zV (    key TEXT PRIMARY KEY,    access_time INTEGER NOT NULL,    size INTEGER NOT NULL)z.CREATE INDEX IF NOT EXISTS idx_access_time ON z(access_time)z'CREATE INDEX IF NOT EXISTS idx_size ON z(size)z'_size (    total_size INTEGER NOT NULL)zINSERT OR IGNORE INTO z_size (total_size) VALUES (0)z.
                CREATE TRIGGER IF NOT EXISTS z(_insert
                AFTER INSERT ON z2
                BEGIN
                    UPDATE zg_size
                    SET total_size = total_size + NEW.size;
                END;
                z(_delete
                AFTER DELETE ON zg_size
                    SET total_size = total_size - OLD.size;
                END;
                z0_update
                AFTER UPDATE OF size ON z\
                WHEN OLD.size != NEW.size
                BEGIN
                    UPDATE zt_size
                    SET total_size = total_size + (NEW.size - OLD.size);
                END;
                )ÚcloseÚ
connectionÚexecuteÚ
table_name)r)   Úcons     r-   r9   zLRUDict.init_dbR  s¤  € Ø�
‰
ŒØ�_‰_ Dˆ_Ó)ð 5	¨Sà�K‰KØ-¨d¯o©oÐ->ð ?ð ôð �K‰KØ@ÀÇÁÐ@QÐQ^Ð_ôð �K‰KÐAÀ$Ç/Á/ÐARÐRXÐYÔZð �K‰KØ-¨d¯o©oÐ->ð ?ð ôð
 �K‰KÐ0°·±Ð0AÐA^Ð_Ô`ð �K‰Kð.Ø.2¯o©oÐ->ð ?!Ø!%§¡Ð 1ð 2à ŸO™OÐ,ð -ð	ô	ð �K‰Kð.Ø.2¯o©oÐ->ð ?!Ø!%§¡Ð 1ð 2à ŸO™OÐ,ð -ð	ô	ð �K‰Kð.Ø.2¯o©oÐ->ð ?)Ø)-¯©Ð(9ð :ð !ŸO™OÐ,ð -ðô
÷W5	÷ 5	ñ 5	ús   £EE3Å3E<c                 ó¸   — | j                  d¬«      5 }|j                  d| j                  › d�|f«      }d d d «       j                  st        ‚y # 1 sw Y   ŒxY w)NTr¹   zDELETE FROM z WHERE key=?)r¼   r½   r¾   ÚrowcountrX   )r)   rR   r¿   Úcurs       r-   ri   zLRUDict.__delitem__‹  s\   € Ø�_‰_ Dˆ_Ó)ð 	T¨SØ—+‘+ ¨T¯_©_Ð,=¸\ÐJÈSÈFÓSˆC÷	Tà�|Š|ÜˆNð ÷	Tð 	Tús   “"AÁAr.   c                 óÒ   — | j                  «       5 }|j                  d| j                  › d|› d�«      j                  «       }|st	        |«      ‚|d   cd d d «       S # 1 sw Y   y xY w)NzSELECT size FROM z WHERE key='ú'r   )r¼   r½   r¾   ÚfetchonerX   )r)   rR   r¿   Úrows       r-   rf   zLRUDict.__getitem__‘  sf   € Ø�_‰_Óð 	 #ð —+‘+Ð 1°$·/±/Ð1BÀ,ÈsÈeÐSTÐUÓV×_Ñ_ÓaˆCÙÜ˜s“mÐ#Ø�q‘6÷	÷ 	ò 	ús   ‘AAÁA&rR   r‹   c                 ó¾   — t        t        «       «      }| j                  d¬«      5 }|j                  d| j                  › d�|||f«       ddd«       y# 1 sw Y   yxY w)zESave a value (file size), and update access time and total cache sizeTr¹   z
                INSERT INTO zÃ (key, access_time, size)
                VALUES (?, ?, ?)
                ON CONFLICT(key) DO UPDATE
                SET access_time = excluded.access_time, size = excluded.size
                N)rŒ   r
   r¼   r½   r¾   )r)   rR   r‹   Ú	timestampr¿   s        r-   rp   zLRUDict.__setitem__š  se   € ô œ›	“Nˆ	Ø�_‰_ Dˆ_Ó)ð 		¨SØ�K‰KðØ!Ÿ_™_Ð-ð .ðð �i Ð&ô÷		÷ 		ñ 		ús   ¦$AÁAc                 ó®   •— t         ‰| �  «        | j                  d¬«      5 }|j                  d| j                  › d�«       d d d «       y # 1 sw Y   y xY w)NTr¹   úUPDATE z_size SET total_size = 0)r!   r8   r¼   r½   r¾   )r)   r¿   r,   s     €r-   r8   zLRUDict.clear©  sP   ø€ Ü‰‰ŒØ�_‰_ Dˆ_Ó)ð 	M¨SØ�K‰K˜' $§/¡/Ð!2Ð2JÐKÔL÷	M÷ 	Mñ 	Mús   ¢ AÁAc                 ó¬   — | j                  «       5 }|j                  d| j                  › �«      j                  «       d   cd d d «       S # 1 sw Y   y xY w)NzSELECT COUNT(key) FROM r   ©r¼   r½   r¾   rÅ   )r)   r>   r*   r¿   s       r-   ÚcountzLRUDict.count®  sO   € Ø�_‰_Óð 	Z #Ø—;‘;Ð!8¸¿¹Ð8IÐJÓK×TÑTÓVÐWXÑY÷	Z÷ 	Zò 	Zús   ‘/A
Á
Ar©   c                 ó   — | j                  «       5 }|j                  d| j                  › d�|f«      }|j                  «       }|j	                  «        |D �cg c]  }|d   ‘Œ	 c}cddd«       S c c}w # 1 sw Y   yxY w)zCGet the least recently used keys with a combined size >= total_sizez¦
                WITH ordered AS (
                    SELECT key, size, access_time, SUM(size) OVER (ORDER BY access_time) AS running_total
                    FROM zŽ
                )
                SELECT * FROM ordered WHERE running_total - size < ?
                ORDER BY access_time;
                r   N)r¼   r½   r¾   Úfetchallr»   )r)   r©   r¿   rÂ   ÚrowsrÆ   s         r-   rª   zLRUDict.get_lru²  s‡   € ð �_‰_Óð 	, #Ø—+‘+ðð Ÿ/™/Ð*ð +ðð �ó
ˆCð —<‘<“>ˆDØ�I‰IŒKØ&*Ö+˜s�C˜“FÒ+÷	,ñ 	,ùò ,÷	,ð 	,ús   ‘AA4ÁA/Á#A4Á/A4Á4A=ÚreversedÚlimitc              +   ó   K  — |dvrt        d|› �«      ‚|rdnd}|rd|› �nd}| j                  «       5 }|j                  d| j                  › d|› d	|› d	|› �«      D ]	  }|d
   –— Œ 	 ddd«       y# 1 sw Y   yxY w­w)zFGet LRU entries in sorted order, by either ``access_time`` or ``size``)Úaccess_timer‹   rR   zInvalid sort key: ÚDESCÚASCzLIMIT Ú zSELECT key FROM z
 ORDER BY ú r   N)r”   r¼   r½   r¾   )	r)   rR   rÑ   rÒ   r*   Ú	directionÚ
limit_exprr¿   rÆ   s	            r-   ÚsortedzLRUDict.sortedÅ  s¢   è ø€ ð Ð4Ñ4ÜÐ1°#°Ð7Ó8Ð8Ù&‘F¨Eˆ	Ù).�v˜e˜WÑ%°Bˆ
à�_‰_Óð 	 #Ø—{‘{Ø" 4§?¡?Ð"3°:¸c¸UÀ!ÀIÀ;ÈaÐPZÈ|Ð\óò �ð ˜!‘f“ñ÷	÷ 	ñ 	üs   ‚2A>´4A2Á)	A>Á2A;Á7A>c                 óº   — | j                  «       5 }|j                  d| j                  › d�«      j                  «       }|r|d   ndcd d d «       S # 1 sw Y   y xY w)NzSELECT total_size FROM Ú_sizer   rÌ   )r)   r¿   rÆ   s      r-   r©   zLRUDict.total_sizeÙ  sT   € Ø�_‰_Óð 	( #Ø—+‘+Ð 7¸¿¹Ð7HÈÐNÓO×XÑXÓZˆCÙ �3�q’6 a÷	(÷ 	(ò 	(ús   ‘6AÁAc                 óê   — t        t        «       «      }| j                  d¬«      5 }|j                  d| j                  › d�||f«      }ddd«       j
                  st        |«      ‚y# 1 sw Y   Œ!xY w)z‰Update the given key with the current timestamp

        Raises:
            KeyError: If the key doesn't exist in the LRU index
        Tr¹   rÊ   z" SET access_time = ? WHERE key = ?N)rŒ   r
   r¼   r½   r¾   rÁ   rX   )r)   rR   rÈ   r¿   rÂ   s        r-   rš   zLRUDict.update_access_timeÞ  st   € ô œ›	“Nˆ	Ø�_‰_ Dˆ_Ó)ð 	¨SØ—+‘+Ø˜$Ÿ/™/Ð*Ð*LÐMØ˜CÐ óˆC÷	ð
 �|Š|Ü˜3“-Ðð ÷	ð 	ús   ¦#A)Á)A2)rÔ   FN)r@   rA   rB   rC   r"   r9   ri   rŒ   rf   r#   rp   r8   rÍ   rª   rD   r   r   rÛ   r©   rš   rF   rG   s   @r-   r•   r•   =  s¥   ø„ ñô *ò7òrð #ó ð˜sð ¨#ó ôMò
Zð, #ó ,ð* !ØØ#ñ	àðð ðð ˜‰}ð	ð 
�#‰óð((˜Có (ð
  c÷  r2   r•   NrJ   r.   c                 ó    — | rd| › �S ddddddœ}|r=|j                   x}r/|j                  «       D ]  \  }}|j                  ||«      }Œ d|› �S y)zQUse either the provided file extension, or get the serializer's default extensionú.ÚbsonÚpklÚjson)rá   Úsafe_pickleÚpickleÚorjsonÚujsonz.dat)ÚnameÚitemsÚreplace)rJ   r   Úsubsrè   ÚkÚvs         r-   rN   rN   î  sr   € áØ�9�+ˆÐàØØØØñ€Dñ ˜zŸ™Ð.�tÐ.Ø—J‘J“Lò 	&‰DˆAˆqØ—<‘<  1Ó%‰Dð	&à�4�&ˆzÐØr2   )NN)'rC   Ú
contextlibr   Úloggingr   Úosr   Úpathlibr   rå   r   Úshutilr   Ú	threadingr	   Útimer
   Útypingr   r   r   Úserializersr   r   r×   r   r   r   Úsqliter   r   r@   r¡   r   r%   r$   r•   r#   rN   r    r2   r-   ú<module>rø      s•   ðñõ &Ý Ý Ý Ý Ý Ý Ý ß *Ñ *ç 9ß /Ñ /ß .á	�8Ó	€ôC3�	ô C3ôLSEˆ{ô SEôlE+�(ô E+ôPn ˆjô n ñb˜h s™mð Èô r2   