o
    wi#                     @   s   d dl mZ d dlZd dlmZ d dlmZ edg dZeej	ej
ejfddZ	G d	d
 d
eZe feeheeefddZdddZdd ZdS )    )absolute_importN)
namedtuple)RLock
_CacheInfo)hitsmissesmaxsizecurrsizec                    s0   t  fdd|D }t|  ||}  | _| S )z5
    Patch two bugs in functools.update_wrapper.
    c                 3   s    | ]
}t  |r|V  qd S N)hasattr).0attrwrapped `/home/ubuntu/maya3_transcribe/venv/lib/python3.10/site-packages/backports/functools_lru_cache.py	<genexpr>   s    z!update_wrapper.<locals>.<genexpr>)tuple	functoolsupdate_wrapper__wrapped__)wrapperr   assignedupdatedr   r   r   r   
   s   r   c                   @   s(   e Zd ZdZdZefddZdd ZdS )
_HashedSeqzThis class guarantees that hash() will be called no more than once
    per element.  This is important because the lru_cache() will hash
    the key multiple times on a cache miss.

    	hashvaluec                 C   s   || d d < ||| _ d S r
   r   )selftuphashr   r   r   __init__%   s   z_HashedSeq.__init__c                 C   s   | j S r
   r   )r   r   r   r   __hash__)   s   z_HashedSeq.__hash__N)__name__
__module____qualname____doc__	__slots__r   r    r!   r   r   r   r   r      s
    r   c           
         s   | }|r||7 }|  D ]}	||	7 }q|r7|| fdd| D 7 }|r3|| fdd| D 7 }t|S ||dkrI |d |v rI|d S t|S )a  Make a cache key from optionally typed positional and keyword arguments

    The key is constructed in a way that is flat as possible rather than
    as a nested structure that would take more memory.

    If there is only a single argument and its data type is known to cache
    its hash value, then that argument is returned without a wrapper.  This
    saves space and improves lookup speed.

    c                 3       | ]} |V  qd S r
   r   r   vtyper   r   r   K       z_make_key.<locals>.<genexpr>c                 3   r'   r
   r   r(   r*   r   r   r   M   r,      r   )itemsvaluesr   )
argskwdstypedkwd_mark	fasttypesr   r+   lenkeyitemr   r*   r   	_make_key-   s   
r8      Fc                    s~   t  tr dk rd n*t r.t tr. d} t| t} fdd|_t||S  dur6td fdd}|S )	a  Least-recently-used cache decorator.

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

    If *typed* is True, arguments of different types will be cached separately.
    For example, f(decimal.Decimal("3.0")) and f(3.0) will be treated as
    distinct calls with distinct results. Some types such as str and int may
    be cached separately even when typed is false.

    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__.

    See:  https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)

    r   r9   c                      
    dS Nr   r2   r   r   r<   r   r   <lambda>u      
 zlru_cache.<locals>.<lambda>Nz=Expected first argument to be an integer, a callable, or Nonec                    s(   t |  t} fdd|_t|| S )Nc                      r:   r;   r   r   r<   r   r   r=   |   r>   z8lru_cache.<locals>.decorating_function.<locals>.<lambda>)_lru_cache_wrapperr   cache_parametersr   )user_functionr   r<   r   r   decorating_functionz   s   
z&lru_cache.<locals>.decorating_function)	
isinstanceintcallableboolr?   r   r@   r   	TypeError)r   r2   rA   r   rB   r   r<   r   	lru_cacheS   s   


rH   c                    s   t  td\ i d 	djjt 
g d d gd d < dkr4fdd}n'd u rF	fdd}n 	
fdd}	
fdd	}	
fd
d}||_||_|S )N)r   r-         r   Fc                     s    d7  | i |}|S Nr-   r   )r0   r1   result)r   rA   r   r   r      s   z#_lru_cache_wrapper.<locals>.wrapperc                     sL   | |}|}|urd7 |S d7 | i |}| |< |S rK   r   )r0   r1   r6   rL   )cache	cache_getr   make_keyr   sentinelr2   rA   r   r   r      s   
c                     s  
| |}	C |}|d ur@|\}}}}||< ||<  }| |< < ||< |< d7 |W  d    S d7 W d    n1 sNw   Y  | i |}	] |v rbnGr}	||	 < ||	< |	   }
d   < < |
= |	|< n+ }|||g}| |<  < |<  kW d    |S W d    |S W d    |S 1 sw   Y  |S rK   r   )r0   r1   r6   link	link_prev	link_next_keyrL   lastoldrootoldkey)KEYNEXTPREVRESULTrM   rN   	cache_lenfullr   lockrO   r   r   rootr2   rA   r   r   r      sV   


#
#
##c                      s8      W  d   S 1 sw   Y  dS )zReport cache statisticsNr   r   )r   r\   r   r^   r   r   r   r   
cache_info   s   $z&_lru_cache_wrapper.<locals>.cache_infoc                      sR        ddgdd< d dW d   dS 1 s"w   Y  dS )z$Clear the cache and cache statisticsNr   F)clearr   )rM   r]   r   r^   r   r_   r   r   cache_clear   s   "z'_lru_cache_wrapper.<locals>.cache_clear)objectr8   get__len__r   r`   rb   )rA   r   r2   r   r   r`   rb   r   )rX   rY   rZ   r[   r   rM   rN   r\   r]   r   r^   rO   r   r   r_   rP   r2   rA   r   r?      s*   *8	r?   )r9   F)
__future__r   r   collectionsr   	threadingr   r   wrapsr   WRAPPER_ASSIGNMENTSWRAPPER_UPDATESlistr   rc   rD   strr   r+   r5   r8   rH   r?   r   r   r   r   <module>   s$    


&/