§
    cÌcD-  ã                   óz   — d Z ddlmZ  e¦   «         Z G d„ d¦  «        Z G d„ d¦  «        Z G d„ de¦  «        Zd	S )
z)A simple least-recently-used (LRU) cache.é   )Útracec                   ó"   — e Zd ZdZdZd„ Zd„ ZdS )Ú_LRUNodez:This maintains the linked-list which is the lru internals.)ÚprevÚnext_keyÚkeyÚvaluec                 óH   — d | _         t          | _        || _        || _        d S ©N)r   Ú	_null_keyr   r   r	   )Úselfr   r	   s      ú2/usr/lib/python3/dist-packages/breezy/lru_cache.pyÚ__init__z_LRUNode.__init__    s"   € ØˆŒ	Ý!ˆŒØˆŒØˆŒ
ˆ
ˆ
ó    c                 ó†   — | j         €d }n| j         j        }d                     | j        j        | j        | j        |¦  «        S )Nz{}({!r} n:{!r} p:{!r}))r   r   ÚformatÚ	__class__Ú__name__r   )r   Úprev_keys     r   Ú__repr__z_LRUNode.__repr__&   sD   € ØŒ9ÐØˆHˆHà”y”}ˆHØ'×.Ò.¨t¬~Ô/FÈÌØ%)¤]°Hñ>ô >ð 	>r   N)r   Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   © r   r   r   r      s=   € € € € € ØDÐDà4€Iðð ð ð>ð >ð >ð >ð >r   r   c                   óz   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Zd	„ Z	dd
„Z
d„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„Zdd„ZdS )ÚLRUCachez?A class which manages a cache of entries, removing unused ones.éd   Nc                 ó\   — i | _         d | _        d | _        |                      ||¦  «         d S r   )Ú_cacheÚ_most_recently_usedÚ_least_recently_usedÚ_update_max_cache©r   Ú	max_cacheÚafter_cleanup_counts      r   r   zLRUCache.__init__2   s6   € ØˆŒà#'ˆÔ à$(ˆÔ!Ø×Ò˜yÐ*=Ñ>Ô>Ð>Ð>Ð>r   c                 ó   — || j         v S r   )r    )r   r   s     r   Ú__contains__zLRUCache.__contains__:   s   € Ø�d”kÐ!Ð!r   c                 óþ   — | j         }||         }| j        }||u r|j        S |j        }|j        }|t
          u r|| _        n||         }||_        ||_        |j        |_        ||_        || _        d |_        |j        S r   )r    r!   r	   r   r   r   r"   r   )r   r   ÚcacheÚnodeÚmruÚ	node_prevr   Ú	node_nexts           r   Ú__getitem__zLRUCache.__getitem__=   s”   € Ø”ˆØ�SŒzˆð
 Ô&ˆØ�3ˆ;ˆ;à”:Ðà”Iˆ	Ø”=ˆð •yÐ Ð ð )2ˆDÔ%Ð%à˜hœˆIØ&ˆIŒNØ%ˆ	ÔàœˆŒØˆŒØ#'ˆÔ ØˆŒ	ØŒzÐr   c                 ó*   — t          | j        ¦  «        S r   )Úlenr    ©r   s    r   Ú__len__zLRUCache.__len__\   s   € Ý�4”;ÑÔÐr   c                 ó`  — |t           u rt          d¦  «        ‚|| j        v r*| j        |         }||_        |                      |¦  «         n/t          ||¦  «        }|| j        |<   |                      |¦  «         t          | j        ¦  «        | j        k    r|                      ¦   «          dS dS )úAdd a new value to the cacheúcannot use _null_key as a keyN)	r   Ú
ValueErrorr    r	   Ú_record_accessr   r1   Ú
_max_cacheÚcleanup)r   r   r	   r+   s       r   Ú__setitem__zLRUCache.__setitem___   s²   € à•)ÐÐÝÐ<Ñ=Ô=Ð=Ø�$”+ÐÐØ”;˜sÔ#ˆDØˆDŒJØ×Ò Ñ%Ô%Ð%Ð%å˜C Ñ'Ô'ˆDØ#ˆDŒK˜ÑØ×Ò Ñ%Ô%Ð%åˆtŒ{ÑÔ˜dœoÒ-Ð-à�LŠL‰NŒNˆNˆNˆNð .Ð-r   c                 ó   — | j         S )z(Get the number of entries we will cache.)r9   r2   s    r   Ú
cache_sizezLRUCache.cache_sizep   s
   € àŒÐr   c                 óx   — | j                              |d ¦  «        }|€|S |                      |¦  «         |j        S r   )r    Úgetr8   r	   )r   r   Údefaultr+   s       r   r?   zLRUCache.gett   s=   € ØŒ{�Š˜s DÑ)Ô)ˆØˆ<ØˆNØ×Ò˜DÑ!Ô!Ð!ØŒzÐr   c                 óN   — t          | j                             ¦   «         ¦  «        S )a  Get the list of keys currently cached.

        Note that values returned here may not be available by the time you
        request them later. This is simply meant as a peak into the current
        state.

        :return: An unordered list of keys that are currently cached.
        )Úlistr    Úkeysr2   s    r   rC   zLRUCache.keys{   s    € õ �D”K×$Ò$Ñ&Ô&Ñ'Ô'Ð'r   c                 óH   — d„ | j                              ¦   «         D ¦   «         S )z9Get a new dict with the same key:value pairs as the cachec                 ó$   — i | ]\  }}||j         “ŒS r   )r	   )Ú.0ÚkÚns      r   ú
<dictcomp>z$LRUCache.as_dict.<locals>.<dictcomp>‰   s    € Ð;Ð;Ð;™t˜q !��1”7Ð;Ð;Ð;r   )r    Úitemsr2   s    r   Úas_dictzLRUCache.as_dict‡   s$   € à;Ð; t¤{×'8Ò'8Ñ':Ô':Ð;Ñ;Ô;Ð;r   c                 ó¦   — t          | j        ¦  «        | j        k    r3|                      ¦   «          t          | j        ¦  «        | j        k    °1d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_count.
        N)r1   r    Ú_after_cleanup_countÚ_remove_lrur2   s    r   r:   zLRUCache.cleanup‹   sT   € õ �$”+ÑÔ Ô!:Ò:Ð:Ø×ÒÑÔÐõ �$”+ÑÔ Ô!:Ò:Ð:Ð:Ð:Ð:Ð:r   c                 óR  — | j         €|| _         || _        dS || j         u rdS || j        u r|j        | _        |j        �|j        |j        _        |j        t          ur| j        |j                 }|j        |_        | j         j        |_        || j         _        || _         d|_        dS )zRecord that key was accessed.N)r!   r"   r   r   r   r    r   ©r   r+   r.   s      r   r8   zLRUCache._record_access•   s²   € ð Ô#Ð+Ø'+ˆDÔ$Ø(,ˆDÔ%ØˆFØ�TÔ-Ð-Ð-àˆFð �4Ô,Ð,Ð,Ø(,¬	ˆDÔ%ØŒ9Ð Ø!%¤ˆDŒIÔØŒ=¥	Ð)Ð)Øœ D¤MÔ2ˆIØ!œYˆIŒNàÔ0Ô4ˆŒØ(,ˆÔ Ô%Ø#'ˆÔ ØˆŒ	ˆ	ˆ	r   c                 ó8  — || j         u r|j        | _         | j                             |j        ¦  «         | j         €d | _        |j        �|j        |j        _        |j        t          ur| j        |j                 }|j        |_        d |_        t          |_        d S r   )r"   r   r    Úpopr   r!   r   r   rP   s      r   Ú_remove_nodezLRUCache._remove_node¯   s‹   € Ø�4Ô,Ð,Ð,Ø(,¬	ˆDÔ%ØŒ�Š˜œÑ!Ô!Ð!àÔ$Ð,Ø'+ˆDÔ$ØŒ9Ð Ø!%¤ˆDŒIÔØŒ=¥	Ð)Ð)Øœ D¤MÔ2ˆIØ!œYˆIŒNàˆŒ	Ý!ˆŒˆˆr   c                 ó:   — |                       | j        ¦  «         dS )z¯Remove one entry from the lru, and handle consequences.

        If there are no more references to the lru, then this entry should be
        removed from the cache.
        N)rS   r"   r2   s    r   rN   zLRUCache._remove_lru¿   s!   € ð 	×Ò˜$Ô3Ñ4Ô4Ð4Ð4Ð4r   c                 óN   — | j         r|                      ¦   «          | j         °dS dS )zClear out all of the cache.N)r    rN   r2   s    r   ÚclearzLRUCache.clearÇ   s@   € ð Œkð 	Ø×ÒÑÔÐð Œkð 	ð 	ð 	ð 	ð 	r   c                 ó4   — |                       ||¬¦  «         dS )z1Change the number of entries that will be cached.)r&   N)r#   r$   s      r   ÚresizezLRUCache.resizeÍ   s3   € à×Ò˜yØ3Fð 	ñ 	Hô 	Hð 	Hð 	Hð 	Hr   c                 óš   — || _         |€| j         dz  dz  | _        nt          || j         ¦  «        | _        |                      ¦   «          d S ©Né   é
   )r9   rM   Úminr:   r$   s      r   r#   zLRUCache._update_max_cacheÒ   sQ   € Ø#ˆŒØÐ&Ø(,¬¸!Ñ(;¸rÑ(AˆDÔ%Ð%å(+Ð,?Ø,0¬Oñ)=ô )=ˆDÔ%à�Š‰Œˆˆˆr   )r   Nr   )r   r   r   r   r   r(   r/   r3   r;   r=   r?   rC   rK   r:   r8   rS   rN   rV   rX   r#   r   r   r   r   r   /   s"  € € € € € ØIÐIð?ð ?ð ?ð ?ð"ð "ð "ðð ð ð> ð  ð  ðð ð ð"ð ð ðð ð ð ð
(ð 
(ð 
(ð<ð <ð <ðð ð ðð ð ð4"ð "ð "ð 5ð 5ð 5ðð ð ðHð Hð Hð Hð
ð ð ð ð ð r   r   c                   ó@   — e Zd ZdZ	 	 d
d„Zd„ Zd„ Zd„ Zdd„Zdd	„Z	dS )ÚLRUSizeCacheaU  An LRUCache 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 just restricts the cache to be cleaned up after so much data is stored.

    The size of items added will be computed using compute_size(value), which
    defaults to len() if not supplied.
    é   Nc           	      óà   — d| _         || _        |€t          | _        |                      ||¬¦  «         t                               | t          t          |dz  ¦  «        d¦  «        ¬¦  «         dS )a¥  Create a new LRUSizeCache.

        :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.
        :param compute_size: A function to compute the size of the values. We
            use a function here, so that you can pass 'len' if you are just
            using simple strings, or a more complex function if you are using
            something like a list of strings, or even a custom object.
            The function should take the form "compute_size(value) => integer".
            If not supplied, it defaults to 'len()'
        é    N©Úafter_cleanup_sizeé   r   )r%   )Ú_value_sizeÚ_compute_sizer1   Ú_update_max_sizer   r   ÚmaxÚint)r   Úmax_sizerd   Úcompute_sizes       r   r   zLRUSizeCache.__init__æ   sq   € ð ˆÔØ)ˆÔØÐÝ!$ˆDÔØ×Ò˜hÐ;MÐÑNÔNÐNÝ×Ò˜$­#­c°(¸c±/Ñ.BÔ.BÀAÑ*FÔ*FÐÑGÔGÐGÐGÐGr   c                 óB  — |t           u rt          d¦  «        ‚| j                             |d¦  «        }|                      |¦  «        }|| j        k    r;t          j        d||| j        | j        ¦  «         |�|  	                    |¦  «         dS |€t          ||¦  «        }|| j        |<   n(| xj        |                      |j        ¦  «        z  c_        | xj        |z  c_        |                      |¦  «         | j        | j        k    r|                      ¦   «          dS dS )r5   r6   NzfAdding the key %r to an LRUSizeCache failed. value %d is too big to fit in a the cache with size %d %d)r   r7   r    r?   rg   Ú_after_cleanup_sizer   ÚmutterÚ	_max_sizerS   r   rf   r	   r8   r:   )r   r   r	   r+   Ú	value_lens        r   r;   zLRUSizeCache.__setitem__ü   s8  € à•)ÐÐÝÐ<Ñ=Ô=Ð=ØŒ{�Š˜s DÑ)Ô)ˆØ×&Ò& uÑ-Ô-ˆ	Ø˜Ô0Ò0Ð0õ ŒLð ,à-0°)ØÔ1°4´>ñCô Cð Cð Ðà×!Ò! $Ñ'Ô'Ð'ØˆFØˆ<Ý˜C Ñ'Ô'ˆDØ#ˆDŒK˜ÑÐàÐÔ × 2Ò 2°4´:Ñ >Ô >Ñ>ÐÔØÐÔ˜IÑ%ÐÔØ×Ò˜DÑ!Ô!Ð!àÔ˜dœnÒ,Ð,à�LŠL‰NŒNˆNˆNˆNð -Ð,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)rf   rn   rN   r2   s    r   r:   zLRUSizeCache.cleanup  sF   € ð Ô Ô!9Ò9Ð9Ø×ÒÑÔÐð Ô Ô!9Ò9Ð9Ð9Ð9Ð9Ð9r   c                 óŒ   — | xj         |                      |j        ¦  «        z  c_         t                               | |¦  «         d S r   )rf   rg   r	   r   rS   )r   r+   s     r   rS   zLRUSizeCache._remove_node#  sB   € ØÐÔ˜D×.Ò.¨t¬zÑ:Ô:Ñ:ÐÔÝ×Ò˜d DÑ)Ô)Ð)Ð)Ð)r   c                 óž   — |                       ||¬¦  «         t          t          |dz  ¦  «        d¦  «        }|                      |¦  «         dS )z/Change the number of bytes that will be cached.rc   re   r   N)rh   ri   rj   r#   )r   rk   rd   r%   s       r   rX   zLRUSizeCache.resize'  sQ   € à×Ò˜hÐ;MÐÑNÔNÐNÝ�˜H¨™OÑ,Ô,¨aÑ0Ô0ˆ	Ø×Ò˜yÑ)Ô)Ð)Ð)Ð)r   c                 ót   — || _         |€| j         dz  dz  | _        d S t          || j         ¦  «        | _        d S rZ   )rp   rn   r]   )r   rk   rd   s      r   rh   zLRUSizeCache._update_max_size-  sD   € Ø!ˆŒØÐ%Ø'+¤~¸Ñ'9¸RÑ'?ˆDÔ$Ð$Ð$å'*Ð+=¸t¼~Ñ'NÔ'NˆDÔ$Ð$Ð$r   )r`   NNr   )
r   r   r   r   r   r;   r:   rS   rX   rh   r   r   r   r_   r_   Ü   s›   € € € € € ðð ð AEØ"ðHð Hð Hð Hð,ð ð ð:ð ð ð*ð *ð *ð*ð *ð *ð *ðOð Oð Oð Oð Oð Or   r_   N)r   Ú r   Úobjectr   r   r   r_   r   r   r   ú<module>rx      sÙ   ðð" 0Ð /ðð ð ð ð ð ð
 ˆF‰HŒH€	ð>ð >ð >ð >ð >ñ >ô >ð >ð(jð jð jð jð jñ jô jð jðZVOð VOð VOð VOð VO�8ñ VOô VOð VOð VOð VOr   