)L iddlmZddlmZddlmZddlmZmZm 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 efZdddZy)) annotations)deque)wraps)AnyCallableDictGenericHashableTupleTypeVarcast) SimpleCache FastDictCachememoized_T)bound_Uc*eZdZdZdddZddZd dZy) 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.) cL|dkDsJi|_t|_||_yNr)_datar_keysmaxsize)selfrs Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/cache.py__init__zSimpleCache.__init__s%{{#% % # cT |j|S#t$r|}||j|<|jj|t |j|j kDr5|jj }||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)rkey getter_funcvalue key_to_removes rgetzSimpleCache.get s ::c? " ME#DJJsO JJ  c "4::- $ 2 2 4  DJJ. =1L sBB'&B'c0i|_t|_y)z Clear cache.N)rrr)rs rclearzSimpleCache.clear7s W rN))rintreturnNone)r#rr$zCallable[[], _U]r,r)r,r-)__name__ __module__ __qualname____doc__rr'r)rrrrs$.rr_K._Vc"eZdZdZdddZddZy)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. cL|dkDsJt|_||_||_yr)rr get_valuesize)rr7r8s rrzFastDictCache.__init__Vs$axx % " rct||jkDr!|jj}||vr||=|j|}|||<|jj ||SN)r!r8rr"r7r )rr#r&results r __missing__zFastDictCache.__missing__]sd t9tyy  JJ..0M$'%S  # rN)i@B)r7zCallable[..., _V]r8r+r,r-)r#r3r,r4)r.r/r0r1rr<r2rrrrAs ( rr_Fcdfd }|S)zI Memoization decorator for immutable classes and pure functions. cjttdfd }tt|S)N)rcdfd }ttjf}j||S)NciSr:r2)akwobjsr create_newzEmemoized..decorator..new_callable..create_newwsA}}$r)r,r)tuplesorteditemsr')rBrCrEr#cacherDs`` r new_callablez1memoized..decorator..new_callableus5 %eF288:./0C99S*- -r)rBrrCrr,r)rrr r=)rDrJrIrs` @r decoratorzmemoized..decoratorrs2,7,H s .  .B %%r)rDr=r,r=r2)rrKs` rrrms & rN)i)rr+r,zCallable[[_F], _F]) __future__r collectionsr functoolsrtypingrrrr r r r r __all__rrrr3r4robjectr=rr2rrrRs"OOO   T" T])'"b&/)X Tx}-. T]&DRL&R T#v+./r