HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/dulwich/__pycache__/lru_cache.cpython-39.pyc
a

�~�_8�@s>dZe�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)z)A simple least-recently-used (LRU) cache.c@s.eZdZdZdZd
dd�Zdd�Zdd	�ZdS)�_LRUNodez:This maintains the linked-list which is the lru internals.)�prev�next_key�key�value�cleanup�sizeNcCs(d|_t|_||_||_||_d|_dS�N)r�	_null_keyrrrrr)�selfrrr�r�3/usr/lib/python3/dist-packages/dulwich/lru_cache.py�__init__sz_LRUNode.__init__cCs0|jdurd}n|jj}d|jj|j|j|fS)Nz%s(%r n:%r p:%r))rr�	__class__�__name__r)r
Zprev_keyrrr�__repr__*s
�z_LRUNode.__repr__cCs*|jdur|�|j|j�d|_d|_dSr)rrr�r
rrr�run_cleanup2s
z_LRUNode.run_cleanup)N)r�
__module__�__qualname__�__doc__�	__slots__r
rrrrrrrs

rc@s�eZdZdZd(dd�Zdd�Zdd	�Zd
d�Zdd
�Zd)dd�Z	dd�Z
d*dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd+d$d%�Zd,d&d'�ZdS)-�LRUCachez?A class which manages a cache of entries, removing unused ones.�dNcCs"i|_d|_d|_|�||�dSr)�_cache�_most_recently_used�_least_recently_used�_update_max_cache�r
�	max_cache�after_cleanup_countrrrr
=szLRUCache.__init__cCs
||jvSr)r)r
rrrr�__contains__EszLRUCache.__contains__cCsr|j}||}|j}||ur"|jS|j}|j}|tur>||_n||}||_||_|j|_||_||_d|_|jSr)rrrrrr	rr)r
r�cache�nodeZmruZ	node_prevr�	node_nextrrr�__getitem__Hs"zLRUCache.__getitem__cCs
t|j�Sr)�lenrrrrr�__len__gszLRUCache.__len__ccs�|j}|dur&|jdur&td|f��|dur�|jturV||jurPtd|f��d}n$|j|j}|j|urztd|f��|jdur�||jur�td|f��n|jj|jkr�td|f��|V|}q&dS)z2Walk the LRU list, only meant to be used in tests.NzIthe _most_recently_used entry is not supposed to have a previous entry %sz0only the last node should have no next value: %sz/inconsistency found, node.next.prev != node: %sz@only the _most_recently_used should not have a previous node: %sz/inconsistency found, node.prev.next != node: %s)rr�AssertionErrorrr	rrr�r
r"r#rrr�	_walk_lrujs:
�

�
�

��zLRUCache._walk_lrucCsx|turtd��||jvr:|j|}|��||_||_nt|||d�}||j|<|�|�t|j�|j	krt|��dS)�]Add a new value to the cache.

        Also, if the entry is ever removed from the cache, call
        cleanup(key, value).

        Args:
          key: The key to store it under
          value: The object to store
          cleanup: None or a function taking (key, value) to indicate
                        'value' should be cleaned up.
        �cannot use _null_key as a key�rN)
r	�
ValueErrorrrrrr�_record_accessr%�
_max_cache)r
rrrr"rrr�add�s



zLRUCache.addcCs|jS)z(Get the number of entries we will cache.)r/rrrr�
cache_size�szLRUCache.cache_sizecCs*|j�|d�}|dur|S|�|�|jSr)r�getr.r)r
r�defaultr"rrrr2�s

zLRUCache.getcCs
|j��S)aGet 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.

        Returns: An unordered list of keys that are currently cached.
        )r�keysrrrrr4�s	z
LRUCache.keyscCstdd�|j��D��S)z"Get the key:value pairs as a dict.css|]\}}||jfVqdSr)r)�.0�k�nrrr�	<genexpr>��z!LRUCache.items.<locals>.<genexpr>)�dictr�itemsrrrrr;�szLRUCache.itemscCst|j�|jkr|��qdS)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)r%r�_after_cleanup_count�_remove_lrurrrrr�szLRUCache.cleanupcCs|j||dd�dS)z<Add a value to the cache, there will be no cleanup function.Nr,)r0)r
rrrrr�__setitem__�szLRUCache.__setitem__cCs�|jdur||_||_dS||jur(dS||jur:|j|_|jdurN|j|j_|jturl|j|j}|j|_|jj|_||j_||_d|_dS)zRecord that key was accessed.N)rrrrr	rrr(rrrr.�s"






zLRUCache._record_accesscCsz||jur|j|_|j�|j�|jdur0d|_|��|jdurL|j|j_|jturj|j|j}|j|_d|_t|_dSr)	rrr�poprrrrr	r(rrr�_remove_node�s




zLRUCache._remove_nodecCs|�|j�dS)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)r@rrrrrr=�szLRUCache._remove_lrucCs|jr|��qdS)zClear out all of the cache.N)rr=rrrr�clearszLRUCache.clearcCs|j||d�dS)z1Change the number of entries that will be cached.)rN)rrrrr�resizes�zLRUCache.resizecCs:||_|dur |jdd|_nt||j�|_|��dS�N��
)r/r<�minrrrrrrs�zLRUCache._update_max_cache)rN)N)N)N)N)rrrrr
r r$r&r)r0r1r2r4r;rr>r.r@r=rArBrrrrrr:s&




rc@sHeZdZdZddd�Zddd�Zdd	�Zd
d�Zddd
�Zddd�Z	dS)�LRUSizeCacheaUAn 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.
    �NcCsHd|_||_|durt|_|j||d�tj|tt|d�d�d�dS)a�Create a new LRUSizeCache.

        Args:
          max_size: The max number of bytes to store before we start
            clearing out entries.
          after_cleanup_size: After cleaning up, shrink everything to this
            size.
          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)�_value_size�
_compute_sizer%�_update_max_sizerr
�max�int)r
�max_sizerKZcompute_sizerrrr
 szLRUSizeCache.__init__cCs�|turtd��|j�|d�}|�|�}||jkrZ|durD|�|�|durV|||�dS|dur|t|||d�}||j|<n|j|j	8_||_	|j|7_|�
|�|j|jkr�|��dS)r*r+Nr,)
r	r-rr2rO�_after_cleanup_sizer@rrNrr.�	_max_sizer)r
rrrr"Z	value_lenrrrr07s&




zLRUSizeCache.addcCs|j|jkr|��qdS)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)rNrTr=rrrrr]szLRUSizeCache.cleanupcCs |j|j8_t�||�dSr)rNrrr@)r
r"rrrr@gszLRUSizeCache._remove_nodecCs.|j||d�tt|d�d�}|�|�dS)z/Change the number of bytes that will be cached.rJrLrMN)rPrQrRr)r
rSrKrrrrrBkszLRUSizeCache.resizecCs2||_|dur |jdd|_nt||j�|_dSrC)rUrTrF)r
rSrKrrrrPqszLRUSizeCache._update_max_size)rHNN)N)N)N)
rrrrr
r0rr@rBrPrrrrrGs	�

&

rGN)r�objectr	rrrGrrrr�<module>s
 ]