§
    cÌc '  ã                   óf   — d Z ddlmZ ddlmZmZmZmZ  G d„ de¦  «        Z	 G d„ de	¦  «        Z
dS )	z)A simple first-in-first-out (FIFO) cache.é    )Údeque)ÚDictÚAnyÚCallableÚDequec                   ó€   — e Zd ZdZddeddfd„Zd„ Zd„ Zd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S )Ú	FIFOCachez<A class which manages a cache of entries, removing old ones.éd   NÚ	max_cacheÚreturnc                 óÚ   — t                                | ¦  «         || _        |€| j        dz  dz  | _        nt	          || j        ¦  «        | _        i | _        t          ¦   «         | _        d S )Né   é
   )ÚdictÚ__init__Ú
_max_cacheÚ_after_cleanup_countÚminÚ_cleanupr   Ú_queue©Úselfr   Úafter_cleanup_counts      ú3/usr/lib/python3/dist-packages/breezy/fifo_cache.pyr   zFIFOCache.__init__   sh   € Ý�Š�dÑÔÐØ#ˆŒØÐ&Ø(,¬¸!Ñ(;¸rÑ(AˆDÔ%Ð%å(+Ð,?Ø,0¬Oñ)=ô )=ˆDÔ%à79ˆŒÝ"'¡'¤'ˆŒˆˆó    c                 ó6   — |                       ||d¬¦  «         dS )z<Add a value to the cache, there will be no cleanup function.N)Úcleanup)Úadd)r   ÚkeyÚvalues      r   Ú__setitem__zFIFOCache.__setitem__%   s    € à�Š��e TˆÑ*Ô*Ð*Ð*Ð*r   c                 ód   — | j                              |¦  «         |                      |¦  «         d S ©N)r   ÚremoveÚ_remove©r   r   s     r   Ú__delitem__zFIFOCache.__delitem__)   s0   € àŒ×Ò˜3ÑÔÐØ�Š�SÑÔÐÐÐr   c                 óô   — || v r| |= | j                              |¦  «         t                               | ||¦  «         |�
|| j        |<   t          | ¦  «        | j        k    r|                      ¦   «          dS dS )a}  Add a new value to the cache.

        Also, if the entry is ever removed from the queue, call cleanup.
        Passing it the key and value being removed.

        :param key: The key to store it under
        :param value: The object to store
        :param cleanup: None or a function taking (key, value) to indicate
                        'value' should be cleaned up
        N)r   Úappendr   r!   r   Úlenr   r   )r   r   r    r   s       r   r   zFIFOCache.add.   s‚   € ð �$ˆ;ˆ;ð �S�	ØŒ×Ò˜3ÑÔÐÝ×Ò˜˜s EÑ*Ô*Ð*ØÐØ!(ˆDŒM˜#ÑÝˆt‰9Œ9�t”Ò&Ð&Ø�LŠL‰NŒNˆNˆNˆNð 'Ð&r   c                 ó   — | j         S )z(Get the number of entries we will cache.)r   ©r   s    r   Ú
cache_sizezFIFOCache.cache_sizeD   s
   € àŒÐr   c                 ó@  — t          | ¦  «        | j        k    r,|                      ¦   «          t          | ¦  «        | j        k    °,t          | j        ¦  «        t          | ¦  «        k    r4t	          dt          | j        ¦  «        ›dt          | ¦  «        ›�¦  «        ‚dS )z¯Clear the cache until it shrinks to the requested size.

        This does not completely wipe the cache, just makes sure it is under
        the after_cleanup_count.
        zDThe length of the queue should always equal the length of the dict. z != N)r*   r   Ú_remove_oldestr   ÚAssertionErrorr,   s    r   r   zFIFOCache.cleanupH   s�   € õ �$‰iŒi˜$Ô3Ò3Ð3Ø×ÒÑ!Ô!Ð!õ �$‰iŒi˜$Ô3Ò3Ð3åˆtŒ{ÑÔ�s 4™yœyÒ(Ð(Ý �.å$'¨¬Ñ$4Ô$4Ð$4Ð$4µc¸$±i´i°ið"Añ Bô Bð Bð )Ð(r   c                 ó:   — | r|                       ¦   «          | °dS dS )zClear out all of the cache.N)r/   r,   s    r   ÚclearzFIFOCache.clearV   s<   € ð ð 	"Ø×ÒÑ!Ô!Ð!ð ð 	"ð 	"ð 	"ð 	"ð 	"r   c                 óŽ   — | j                              |d¦  «        }t                               | |¦  «        }|� |||¦  «         |S )z:Remove an entry, making sure to call any cleanup function.N)r   Úpopr   )r   r   r   Úvals       r   r%   zFIFOCache._remove\   sK   € à”-×#Ò# C¨Ñ.Ô.ˆõ �hŠh�t˜SÑ!Ô!ˆØÐØˆG�C˜ÑÔÐØˆ
r   c                 ób   — | j                              ¦   «         }|                      |¦  «         dS )zRemove the oldest entry.N)r   Úpopleftr%   r&   s     r   r/   zFIFOCache._remove_oldestf   s-   € àŒk×!Ò!Ñ#Ô#ˆØ�Š�SÑÔÐÐÐr   c                 óº   — || _         |€|dz  dz  | _        nt          ||¦  «        | _        t          | ¦  «        | j         k    r|                      ¦   «          dS dS )a  Increase/decrease the number of cached entries.

        :param max_cache: The maximum number of entries to cache.
        :param after_cleanup_count: After cleanup, we should have at most this
            many entries. This defaults to 80% of max_cache.
        Nr   r   )r   r   r   r*   r   r   s      r   ÚresizezFIFOCache.resizek   sd   € ð $ˆŒØÐ&Ø(1°A©¸Ñ(;ˆDÔ%Ð%å(+¨IÐ7JÑ(KÔ(KˆDÔ%Ýˆt‰9Œ9�t”Ò&Ð&Ø�LŠL‰NŒNˆNˆNˆNð 'Ð&r   c                 ó*   — t          | j        ¦  «        ‚r#   )ÚNotImplementedErrorÚcopyr,   s    r   r<   zFIFOCache.copy|   s   € Ý! $¤)Ñ,Ô,Ð,r   c                 ó*   — t          | j        ¦  «        ‚r#   )r;   r4   )r   r   Údefaults      r   r4   zFIFOCache.pop   s   € õ " $¤(Ñ+Ô+Ð+r   c                 ó*   — t          | j        ¦  «        ‚r#   )r;   Úpopitemr,   s    r   r@   zFIFOCache.popitem‡   s   € å! $¤,Ñ/Ô/Ð/r   c                 ó(   — || v r| |         S || |<   |S )zsimilar to dict.setdefault© )r   r   Ú
defaultvals      r   Ú
setdefaultzFIFOCache.setdefault‹   s$   € à�$ˆ;ˆ;Ø˜”9ÐØˆˆS‰	ØÐr   c                 ó¢  — t          |¦  «        dk    rd|d         }t          |t          ¦  «        r"|D ]}|                      |||         ¦  «         ŒnW|d         D ]\  }}|                      ||¦  «         Œn2t          |¦  «        dk    rt	          dt          |¦  «        z  ¦  «        ‚|r!|D ] }|                      |||         ¦  «         ŒdS dS )zSimilar to dict.update()é   r   z*update expected at most 1 argument, got %dN)r*   Ú
isinstancer   r   Ú	TypeError)r   ÚargsÚkwargsÚargr   r5   s         r   ÚupdatezFIFOCache.update’   s  € åˆt‰9Œ9˜Š>ˆ>Ø�q”'ˆCÝ˜#�tÑ$Ô$ð 'Øð ,ð ,�CØ—H’H˜S # c¤(Ñ+Ô+Ð+Ð+ð,ð !% Q¤ð 'ð '‘H�C˜Ø—H’H˜S #Ñ&Ô&Ð&Ð&ð'å�‰YŒY˜Š]ˆ]ÝÐHÝ! $™iœiñ(ñ )ô )ð )àð 	+Øð +ð +�Ø—’˜˜f SœkÑ*Ô*Ð*Ð*ð	+ð 	+ð+ð +r   )r
   Nr#   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úintr   r!   r'   r   r-   r   r2   r%   r/   r9   r<   r4   r@   rD   rL   rB   r   r   r	   r	      s*  € € € € € ØFÐFð	*ð 	* #ð 	*È$ð 	*ð 	*ð 	*ð 	*ð+ð +ð +ðð ð ð
ð ð ð ð,ð ð ðBð Bð Bð"ð "ð "ðð ð ðð ð ð
ð ð ð ð"-ð -ð -ð,ð ,ð ,ð ,ð0ð 0ð 0ðð ð ð ð+ð +ð +ð +ð +r   r	   c                   ó@   — e Zd ZdZ	 	 d
d„Zdd„Zd„ Zd„ Zd„ Zdd	„Z	dS )ÚFIFOSizeCachezÙAn FIFOCache that removes things based on the size of the values.

    This differs in that it doesn't care how many actual items there are,
    it restricts the cache to be cleaned based on the size of the data.
    é   Nc                 óæ   — t                                | |¬¦  «         || _        |€| j        dz  dz  | _        nt	          || j        ¦  «        | _        d| _        || _        |€t          | _        dS dS )aŠ  Create a new FIFOSizeCache.

        :param max_size: The max number of bytes to store before we start
            clearing out entries.
        :param after_cleanup_size: After cleaning up, shrink everything to this
            size (defaults to 80% of max_size).
        :param compute_size: A function to compute the size of a value. If
            not supplied we default to 'len'.
        )r   Nr   r   r   )r	   r   Ú	_max_sizeÚ_after_cleanup_sizer   Ú_value_sizeÚ_compute_sizer*   )r   Úmax_sizeÚafter_cleanup_sizeÚcompute_sizes       r   r   zFIFOSizeCache.__init__«   s‚   € õ 	×Ò˜4¨8ÐÑ4Ô4Ð4Ø!ˆŒØÐ%Ø'+¤~¸Ñ'9¸RÑ'?ˆDÔ$Ð$å'*Ð+=¸t¼~Ñ'NÔ'NˆDÔ$àˆÔØ)ˆÔØÐÝ!$ˆDÔÐÐð  Ðr   c                 óH  — || v r| |= |                       |¦  «        }|| j        k    rdS | j                             |¦  «         t                               | ||¦  «         |�
|| j        |<   | xj        |z  c_        | j        | j        k    r|  	                    ¦   «          dS dS )aÜ  Add a new value to the cache.

        Also, if the entry is ever removed from the queue, call cleanup.
        Passing it the key and value being removed.

        :param key: The key to store it under
        :param value: The object to store, this value by itself is >=
            after_cleanup_size, then we will not store it at all.
        :param cleanup: None or a function taking (key, value) to indicate
                        'value' sohuld be cleaned up.
        N)
rY   rW   r   r)   r   r!   r   rX   rV   r   )r   r   r    r   Ú	value_lens        r   r   zFIFOSizeCache.addÃ   s¹   € ð �$ˆ;ˆ;ð �S�	Ø×&Ò& uÑ-Ô-ˆ	Ø˜Ô0Ò0Ð0ØˆFØŒ×Ò˜3ÑÔÐÝ×Ò˜˜s EÑ*Ô*Ð*ØÐØ!(ˆDŒM˜#ÑØÐÔ˜IÑ%ÐÔØÔ˜dœnÒ,Ð,à�LŠL‰NŒNˆNˆNˆNð -Ð,r   c                 ó   — | j         S )z&Get the number of bytes we will cache.)rV   r,   s    r   r-   zFIFOSizeCache.cache_sizeá   s
   € àŒ~Ðr   c                 ór   — | j         | j        k    r&|                      ¦   «          | j         | j        k    °$dS dS )z®Clear the cache until it shrinks to the requested size.

        This does not completely wipe the cache, just makes sure it is under
        the after_cleanup_size.
        N)rX   rW   r/   r,   s    r   r   zFIFOSizeCache.cleanupå   sF   € ð Ô Ô!9Ò9Ð9Ø×ÒÑ!Ô!Ð!ð Ô Ô!9Ò9Ð9Ð9Ð9Ð9Ð9r   c                 ó‚   — t                                | |¦  «        }| xj        |                      |¦  «        z  c_        |S )z8Remove an entry, making sure to maintain the invariants.)r	   r%   rX   rY   )r   r   r5   s      r   r%   zFIFOSizeCache._removeï   s>   € å×Ò  cÑ*Ô*ˆØÐÔ˜D×.Ò.¨sÑ3Ô3Ñ3ÐÔØˆ
r   c                 óà   — t                                | |¦  «         || _        |€|dz  dz  | _        nt	          ||¦  «        | _        | j        | j        k    r|                      ¦   «          dS dS )a  Increase/decrease the amount of cached data.

        :param max_size: The maximum number of bytes to cache.
        :param after_cleanup_size: After cleanup, we should have at most this
            many bytes cached. This defaults to 80% of max_size.
        Nr   r   )r	   r9   rV   rW   r   rX   r   )r   rZ   r[   s      r   r9   zFIFOSizeCache.resizeõ   sw   € õ 	×Ò˜˜xÑ(Ô(Ð(Ø!ˆŒØÐ%Ø'/°!¡|°rÑ'9ˆDÔ$Ð$å'*¨8Ð5GÑ'HÔ'HˆDÔ$ØÔ˜dœnÒ,Ð,Ø�LŠL‰NŒNˆNˆNˆNð -Ð,r   )rT   NNr#   )
rM   rN   rO   rP   r   r   r-   r   r%   r9   rB   r   r   rS   rS   ¤   s‘   € € € € € ðð ð AEØ"ð%ð %ð %ð %ð0ð ð ð ð<ð ð ð"ð "ð "ðð ð ðð ð ð ð ð r   rS   N)rP   Úcollectionsr   Útypingr   r   r   r   r   r	   rS   rB   r   r   ú<module>re      s´   ðð" 0Ð /à Ð Ð Ð Ð Ð Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -ðJ+ð J+ð J+ð J+ð J+�ñ J+ô J+ð J+ðZ_ð _ð _ð _ð _�Iñ _ô _ð _ð _ð _r   