
    =wgF4                         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mZ d dl	m
Z
 d dlmZ d dlmZmZ 	 d d	lmZ d ZddZddZddZddZddZy# e$ r  G d
 de      ZY *w xY w)    )with_statementN)array)	nsmallest)
itemgetter)Lock)time)	iteritemsxrange)Counterc                       e Zd Zd Zy)r   c                      y)Nr    )selfkeys     H/var/www/horilla/myenv/lib/python3.12/site-packages/whoosh/util/cache.py__missing__zCounter.__missing__+   s        N)__name__
__module____qualname__r   r   r   r   r   r   *   s    	r   r   c                 J     i t        j                          fd       }|S )z4Caching decorator with an unbounded cache size.
    c                  F    	 |    S # t         $ r  |  }|| <   |cY S w xY wNKeyError)argsresultcachefuncs     r   caching_wrapperz&unbound_cache.<locals>.caching_wrapper5   s8    	; 	4[F E$KM	s      )	functoolswraps)r   r    r   s   ` @r   unbound_cacher#   /   s-     E__T  r   c                       fd}|S )a  A simple cache that, when the cache is full, deletes the least recently
    used 10% of the cached values.

    This function duplicates (more-or-less) the protocol of the
    ``functools.lru_cache`` decorator in the Python 3.2 standard library.

    Arguments to the cached function must be hashable.

    View the cache statistics tuple ``(hits, misses, maxsize, currsize)``
    with f.cache_info().  Clear the cache and statistics with f.cache_clear().
    Access the underlying function with f.__wrapped__.
    c                      ddgi i t        j                          fd       }fd}fd}||_        ||_        |S )Nr   c                  D   	 |    }dxx   dz  cc<   t               | <   |S # t         $ r` dxx   dz  cc<   t              k(  r5t        dz  xs dt              t	        d            D ]  \  }}|= |=   |  | <   |    }Y ww xY w# t               | <   w xY wNr      
   )r   )r   lenr   r	   r   r   )	r   r   k_datalastusedmaxsizestatsuser_functions	       r   wrapperz7lru_cache.<locals>.decorating_function.<locals>.wrapperT   s    (daA "&M  	$aAt9' )'R-*<1*3H*=.8m!= (1 !G$QK	(
 +D1T
d	$ "&"   $ A&B
B BB Bc                  .    d   d   t               fS Nr   r(   r*   r-   r/   r0   s   r   
cache_infoz:lru_cache.<locals>.decorating_function.<locals>.cache_infog       8U1XwD	99r   c                  Z     j                          j                          dxd<   d<   y r5   clear)r-   r.   r0   s   r   cache_clearz;lru_cache.<locals>.decorating_function.<locals>.cache_clearj   s(    JJLNN"##E!HuQxr   r!   r"   r8   r=   )r1   r2   r8   r=   r-   r.   r0   r/   s   `   @@@r   decorating_functionz&lru_cache.<locals>.decorating_functionO   sR    A		'	 
(	$	:	$
 ()r   r   r/   r?   s   ` r   	lru_cacherA   A   s    "F r   c                       fd}|S )a  A simple cache that, when the cache is full, deletes the least frequently
    used 10% of the cached values.

    This function duplicates (more-or-less) the protocol of the
    ``functools.lru_cache`` decorator in the Python 3.2 standard library.

    Arguments to the cached function must be hashable.

    View the cache statistics tuple ``(hits, misses, maxsize, currsize)``
    with f.cache_info().  Clear the cache and statistics with f.cache_clear().
    Access the underlying function with f.__wrapped__.
    c                      ddgi t               t        j                          fd       }fd}fd}||_        ||_        |S )Nr   c                  D   	 |    }dxx   dz  cc<   | xx   dz  cc<   |S # t         $ r` dxx   dz  cc<   t              k(  r5t        dz  xs dt              t	        d            D ]  \  }}|= |=   |  | <   |    }Y ww xY w# | xx   dz  cc<   w xY wr'   )r   r*   r   r	   r   )	r   r   r+   r,   r-   r/   r0   usecountr1   s	       r   r2   z7lfu_cache.<locals>.decorating_function.<locals>.wrapper   s    $daA !#M  	$aAt9' )'R-*<1*3H*=.8m!= (1 !G$QK	(
 +D1T
d	$ !#r3   c                  .    d   d   t               fS r5   r6   r7   s   r   r8   z:lfu_cache.<locals>.decorating_function.<locals>.cache_info   r9   r   c                  F     j                          j                          y r   r;   )r-   rE   s   r   r=   z;lfu_cache.<locals>.decorating_function.<locals>.cache_clear   s    JJLNNr   )r   r!   r"   r8   r=   )r1   r2   r8   r=   r-   r0   rE   r/   s   `   @@@r   r?   z&lfu_cache.<locals>.decorating_function   sT    A9		'	 
(	$	:	 ()r   r   r@   s   ` r   	lfu_cacherH   u   s    !D r   c                       fd}|S )a  A very simple cache that, when the cache is filled, deletes 10% of the
    cached values AT RANDOM.

    This function duplicates (more-or-less) the protocol of the
    ``functools.lru_cache`` decorator in the Python 3.2 standard library.

    Arguments to the cached function must be hashable.

    View the cache statistics tuple ``(hits, misses, maxsize, currsize)``
    with f.cache_info().  Clear the cache and statistics with f.cache_clear().
    Access the underlying function with f.__wrapped__.
    c                      ddgi t        j                          fd       }fd}fd}||_        ||_        |S )Nr   c                  X   	 |    }dxx   dz  cc<   |S # t         $ r dxx   dz  cc<   t              k(  r]j                         }t        dz  xs d      D ]8  }t	        j
                  dt        |      dz
        }|j                  |      }|= :  	|  | <   |    }Y |S w xY w)Nr   r(   r)   )r   r*   keysr
   randomrandintpop)
r   r   rL   inr+   r-   r/   r0   r1   s
         r   r2   z:random_cache.<locals>.decorating_function.<locals>.wrapper   s    $daA M  	$aAt9'99;D#GrM$6Q7 $"NN1c$i!m< HHQK G$ +D1T
dM	$s    BB)(B)c                  .    d   d   t               fS r5   r6   r7   s   r   r8   z=random_cache.<locals>.decorating_function.<locals>.cache_info   r9   r   c                  &     j                          y r   r;   )r-   s   r   r=   z>random_cache.<locals>.decorating_function.<locals>.cache_clear   s    JJLr   r>   )r1   r2   r8   r=   r-   r0   r/   s   `   @@r   r?   z)random_cache.<locals>.decorating_function   sM    A		'	 
(	 	:	 ()r   r   r@   s   ` r   random_cacherT      s    < r   c                       fd}|S )a  Double-barrel least-recently-used cache decorator. This is a simple
    LRU algorithm that keeps a primary and secondary dict. Keys are checked
    in the primary dict, and then the secondary. Once the primary dict fills
    up, the secondary dict is cleared and the two dicts are swapped.

    This function duplicates (more-or-less) the protocol of the
    ``functools.lru_cache`` decorator in the Python 3.2 standard library.

    Arguments to the cached function must be hashable.

    View the cache statistics tuple ``(hits, misses, maxsize, currsize)``
    with f.cache_info().  Clear the cache and statistics with f.cache_clear().
    Access the underlying function with f.__wrapped__.
    c                      i i dddgt        j                          fd       }fd}fd}||_        ||_        |S )Nr   c                      d   }|   }|    }| }||v rdxx   dz  cc<   ||   S ||v rdxx   dz  cc<   ||   S dxx   dz  cc<    |  }|||<   t        |      k\  r| d<   |j                          |S )N      r(      )r*   r<   )	r   ptrabr   r   r/   r0   r1   s	         r   r2   z:db_lru_cache.<locals>.decorating_function.<locals>.wrapper   s    (Cc
A#gACaxaAvaAvaA&-#q6W$#&wE!HGGIr   c                  R    d   d    t        d         t        d         z   fS )NrY   rZ   r   r(   r6   )r/   r0   s   r   r8   z=db_lru_cache.<locals>.decorating_function.<locals>.cache_info  s/    8U1XwE!HE!H0MMMr   c                  f     d   j                           d   j                          dx d<    d<   y)$Clear the cache and cache statisticsr   r(   rY   rZ   Nr;   )r0   s   r   r=   z>db_lru_cache.<locals>.decorating_function.<locals>.cache_clear  s1    !HNN!HNN"##E!HuQxr   r>   )r1   r2   r8   r=   r0   r/   s   `   @r   r?   z)db_lru_cache.<locals>.decorating_function   sP    RAq!		'	 
(	*	N	$ ()r   r   r@   s   ` r   db_lru_cachera      s     &N r   c                       fd}|S )au  Least-recently-used cache decorator.

    This function duplicates (more-or-less) the protocol of the
    ``functools.lru_cache`` decorator in the Python 3.2 standard library, but
    uses the clock face LRU algorithm instead of an ordered dictionary.

    If *maxsize* is set to None, the LRU features are disabled and the cache
    can grow without bound.

    Arguments to the cached function must be hashable.

    View the cache statistics named tuple (hits, misses, maxsize, currsize)
    with f.cache_info().  Clear the cache and statistics with f.cache_clear().
    Access the underlying function with f.__wrapped__.
    c                 >    g di 	rPd g	z  t        dd t        	      D              t               t        j                         	 fd       }nt        j                          fd       }	fd}	fd}||_        ||_        |S )N)r   r   r   Bc              3       K   | ]  }d   yw)r   Nr   ).0r,   s     r   	<genexpr>zCclockface_lru_cache.<locals>.decorating_function.<locals>.<genexpr>*  s     $@1Q$@s   c                  x   | }	 5  
|   \  }}d	|<   dxx   dz  cc<   d d d        |S # 1 sw Y   S xY w# t         $ rw  |  }5  d   }|}	 |dz   z  }	|   }|rd	|<   n|r||k(  r|   }|
v r
|= ||<   d	|<   n4||f
|<   |d<   dxx   dz  cc<   d d d        Y |S # 1 sw Y   Y |S xY ww xY w)Nr(   r   rX   r   )r   r   posr   handendcurrent_refcurrent_key
clock_keys
clock_refsr-   lockr/   r0   r1   s           r   r2   zAclockface_lru_cache.<locals>.decorating_function.<locals>.wrapper-  s;   (& &&*3iV*+
3aA&P Q&P E   !&*D1F &$Qx" #$(1H#7D*4T*:K* 45
4 0%0DCK
 /9.>#.$#6(,[(936
4 034
4 0 %# #& &*6NS	#'aaA=& &> ?& &> E!&s<   9 ,9 69 9 B9	AB*B9*B5	/B95B9c                      | }	 |   }dxx   dz  cc<   |S # t         $ r  |  }||<   dxx   dz  cc<   Y |S w xY wr5   r   )r   r   r   r-   r0   r1   s      r   r2   zAclockface_lru_cache.<locals>.decorating_function.<locals>.wrapper\  s`    "!#YF!HMH
 	   "*D1F &DI!HMH	"s     ==c                  .    d   d   t               fS r5   r6   r7   s   r   r8   zDclockface_lru_cache.<locals>.decorating_function.<locals>.cache_infoh  r9   r   c                  x    j                          dxd<   xd<   d<   t              D ]  } d| <   d| <    y)r`   r   r(   rX   N)r<   r
   )rP   rn   ro   r-   r/   r0   s    r   r=   zEclockface_lru_cache.<locals>.decorating_function.<locals>.cache_cleark  sL    JJL-..E!H.uQx%(G_ " $
1 !
1"r   )r   r
   r   r!   r"   r8   r=   )
r1   r2   r8   r=   rn   ro   r-   rp   r0   r/   s
   `   @@@@@r   r?   z0clockface_lru_cache.<locals>.decorating_function"  s    ')Js$@w$@AJ6D__]++ + ,+\ __]+	 ,		:	" 	" ()r   r   r@   s   ` r   clockface_lru_cachert     s    "Sh r   )d   )
__future__r   r!   rM   r   heapqr   operatorr   	threadingr   r   whoosh.compatr	   r
   collectionsr   ImportErrordictr#   rA   rH   rT   ra   rt   r   r   r   <module>r~      sh   8 &       +#$1h0f,^7teQ  $ s   A A'&A'