qBFjVddlmZddlmZddlmZddlmZmZm Z m Z m Z m Z m Z mZgdZe de Ze dZGd d e eefZe d e e d fZe d ZGdde eefZe ded efZdddZdS)) annotations)deque)wraps)AnyCallableDictGenericHashableTupleTypeVarcast) SimpleCache FastDictCachememoized_T)bound_Uc,eZdZdZdddZdd ZddZdS)rz Very simple cache that discards the oldest item when the cache size is exceeded. :param maxsize: Maximum size of the cache. (Don't make it too big.) maxsizeintreturnNonecX|dksJi|_t|_||_dSNr)_datar_keysr)selfrs BC:\PYTHON\_runtimes\venv\Lib\site-packages\prompt_toolkit/cache.py__init__zSimpleCache.__init__s,{{{{#% % # keyr getter_funcCallable[[], _U]rc, |j|S#t$rz|}||j|<|j|t |j|jkr*|j}||jvr|j|=|cYSwxYw)z Get object from the cache. If not found, call `getter_func` to resolve it, and put that on the top of the cache instead. )rKeyErrorrappendlenrpopleft)rr"r#value key_to_removes rgetzSimpleCache.get s :c? "   KMME#DJsO J  c " " "4:-- $ 2 2 4 4  DJ.. =1LLL s BBBc:i|_t|_dS)z Clear cache.N)rrr)rs rclearzSimpleCache.clear7s WW r!N)r)rrrr)r"rr#r$rr)rr)__name__ __module__ __qualname____doc__r r,r.r!rrrs_$$$$$.r!r_K._Vc$eZdZdZddd Zdd ZdS)ra Fast, lightweight cache which keeps at most `size` items. It will discard the oldest items in the cache first. The cache is a dictionary, which doesn't keep track of access counts. It is perfect to cache little immutable objects which are not expensive to create, but where a dictionary lookup is still much faster than an object instantiation. :param get_value: Callable that's called in case of a missing key. @B get_valueCallable[..., _V]sizerrrcX|dksJt|_||_||_dSr)rrr8r:)rr8r:s rr zFastDictCache.__init__Vs,axxxx % " r!r"r4r5ct||jkr |j}||vr||=|j|}|||<|j||SN)r(r:rr)r8r')rr"r+results r __missing__zFastDictCache.__missing__]sm t99ty  J..00M$$'%S  # r!N)r7)r8r9r:rrr)r"r4rr5)r/r0r1r2r r?r3r!rrrAsK  (      r!r_FrrrCallable[[_F], _F]cdfd }|S)zI Memoization decorator for immutable classes and pure functions. objr@rcttdfd }tt|S)N)rarkwrcdfd }ttf}||S)NrrciSr=r3)rFrGrDsr create_newzEmemoized..decorator..new_callable..create_newwssA}}}$r!)rr)tuplesorteditemsr,)rFrGrJr"cacherDs`` r new_callablez1memoized..decorator..new_callableuse % % % % % % % %eF288::..//0C99S*-- -r!)rFrrGrrr)rrr r@)rDrOrNrs` @r decoratorzmemoized..decoratorrsZ,7,H,H,H s . . . . . .  .B %%%r!)rDr@rr@r3)rrPs` rrrms) & & & & & & r!N)rA)rrrrB) __future__r collectionsr functoolsrtypingrrrr r r r r __all__rrrr4r5robjectr@rr3r!rrWs""""""OOOOOOOOOOOOOOOOOOOO     WT""" WT]])))))'"b&/)))X WTx}-... WT]]&&&&&DRL&&&R WT#v+.///r!