+
    }i%                    `   ^ RI Ht ^ RIt^ RIt^ RIt^ RIHtHt ^ RIH	t	 ^ RI
HtHtHtHtHtHt ^RIHtHtHt . ROt ! R R]4      t ! R R	4      t]P0                   ! R R4      4       t ! R R
4      t]P0                   ! R R4      4       t ! R R4      t ! R R4      t ! R R4      tR# )    )annotationsN)OrderedDictdeque)
ContextVar)CallableDequeDictOptionalProtocolUnion)DomainPartialResultResolverCacheCachingResolverLruS3FifoSievec                  n    ] tR t^tRt]P                  R R l4       t]P                  R R l4       tRt	R# )r   zCache()

Cache abstract protocol. The :class:`CachingResolver` will look
values up, merge what was returned (possibly nothing) with what it
got from its actual parser, and *re-set the result*.
c               $    V ^8  d   QhRRRRRR/#    keystrvaluer   returnNone )formats   "c/Users/ahmad/.openclaw/workspace/my-crawler/.venv/lib/python3.14/site-packages/ua_parser/caching.py__annotate__Cache.__annotate__%   s!      s = T     c                    R# )z6Adds or replace ``value`` to the cache at key ``key``.Nr   selfr   r   s   &&&r    __setitem__Cache.__setitem__$        	r#   c                    V ^8  d   QhRRRR/# r   r   r   r   zOptional[PartialResult]r   )r   s   "r    r!   r"   *   s      s '> r#   c                    R# )z5Returns a partial result for ``key`` if there is any.Nr   r&   r   s   &&r    __getitem__Cache.__getitem__)   r)   r#   r   N)
__name__
__module____qualname____firstlineno____doc__abcabstractmethodr'   r.   __static_attributes__r   r#   r    r   r      s;     	  	 r#   c                  >    ] tR t^/tRtR R ltR R ltR R ltRtR	# )
r   a  Cache following a least-recently used replacement policy: when
there is no more room in the cache, whichever entry was last seen
the least recently is removed.

Simple LRUs are generally outdated and to avoid as they have
relatively low hit rates for modern caches (at lower sizes). The
main use case here is if the workload can lead to the cache being
full of popular items then all of them being replaced at once:
:class:`S3Fifo` and :class:`Sieve` are FIFO-based caches and have
worst-case O(n) eviction.
c                   V ^8  d   QhRR/# r   maxsizeintr   )r   s   "r    r!   Lru.__annotate__<   s     % % %r#   c                	d    Wn         \        4       V n        \        P                  ! 4       V n        R # N)r;   r   cache	threadingLocklockr&   r;   s   &&r    __init__Lru.__init__<   s    6Am
NN$	r#   c                    V ^8  d   QhRRRR/# r+   r   )r   s   "r    r!   r=   A   s      s '> r#   c                	    V P                   ;_uu_ 4        V P                  P                  V4      pV'       d   V P                  P                  V4       VuuR R R 4       #   + '       g   i     R # ; ir?   )rC   r@   getmove_to_endr&   r   es   && r    r.   Lru.__getitem__A   sA    YYY

s#A

&&s+	 YYYs   A A  A1	c               $    V ^8  d   QhRRRRRR/# r   r   )r   s   "r    r!   r=   H   s!     $ $s $= $T $r#   c                	$   V P                   ;_uu_ 4        \        V P                  4      V P                  8  d-   WP                  9  d   V P                  P	                  R R7       W P                  V&   RRR4       R#   + '       g   i     R# ; i)F)lastN)rC   lenr@   r;   popitemr%   s   &&&r    r'   Lru.__setitem__H   sT    YYY4::$,,.3jj3H

""".#JJsO YYYs   AA>>B	)r@   rC   r;   N)	r0   r1   r2   r3   r4   rE   r.   r'   r7   r   r#   r    r   r   /   s    
%
$ $r#   c                  >    ] tR t^Ot$ . R	OtR]R&   R]R&   R]R&   RtR# )

CacheEntryfreqr   r   r   r   r<   r   N)rV   r   r   r0   r1   r2   r3   	__slots____annotations__r7   r   r#   r    rU   rU   O   s    (I	H
Ir#   rU   c                  V    ] tR t^WtRtR R ltR R ltR R ltR R	 ltR
 R lt	Rt
R# )r   a.  FIFO-based quick-demotion lazy-promotion cache [S3-FIFO]_.

Experimentally provides excellent hit rate at lower cache sizes,
for a relatively simple and efficient implementation. Notably
excellent at handling "one hit wonders", aka entries seen only
once during a work-set (or reasonable work window).
c                   V ^8  d   QhRR/# r:   r   )r   s   "r    r!   S3Fifo.__annotate__`   s     % % %r#   c                	   Wn         / V n        \        ^\        V^
,          4      4      V n        \        4       V n        WP                  ,
          V n        \        4       V n        \        4       V n	        \        P                  ! 4       V n        R#    N)r;   indexmaxr<   small_targetr   smallmain_targetmainghostrA   rB   rC   rD   s   &&r    rE   S3Fifo.__init__`   s`    8:
3w|#45(-
"%6%66',w	!&
NN$	r#   c                    V ^8  d   QhRRRR/# r+   r   )r   s   "r    r!   r\   j   s      s '> r#   c                	    V P                   P                  V4      ;p'       dB   \        V4      \        J d/   \	        VP
                  ^,           ^4      Vn        VP                  # R# r^   )r`   rI   typerU   minrV   r   rK   s   && r    r.   S3Fifo.__getitem__j   sG    $$A$$q'Z*?!Q'AF77Nr#   c               $    V ^8  d   QhRRRRRR/# )r   r   r   rr   r   r   r   )r   s   "r    r!   r\   r   s!     $ $s $} $ $r#   c                	p   V P                   ;_uu_ 4        V P                  P                  V4      ;p'       d%   \        V4      \        J d   W#n         R R R 4       R # \        V P                  4      \        V P                  4      ,           V P                  8  d   \        V P                  4      V P                  8  d   V P                  4        \        V P                  4      \        V P                  4      ,           V P                  8  d   V P                  4        \	        W^ 4      p\        V P                  P                  V4      4      \        J d   V P                  P                  V4       MV P                  P                  V4       W@P                  V&   R R R 4       R #   + '       g   i     R # ; ir?   )rC   r`   rI   rj   rU   r   rQ   rc   re   r;   rd   _evict_small_evict_mainr   
appendleft)r&   r   rn   rL   entrys   &&&  r    r'   S3Fifo.__setitem__r   s   YYYZZ^^C(((d1g.C Y
 4::TYY/4<<?tyy>D$4$44%%' tzz?S^3t||C$$&sq)EDJJNN3'(C/		$$U+

%%e,#JJsO' YYYs   >F$D=F$$F5	c                   V ^8  d   QhRR/# r   r   r   r   )r   s   "r    r!   r\      s      T r#   c                	     V P                   P                  4       pVP                  '       d7   V;P                  ^,          un        V P                   P                  V4       Kc  V P                  VP
                   R# TN)re   poprV   rr   r`   r   )r&   rL   s   & r    rq   S3Fifo._evict_main   sO    		Avvv!		$$Q'JJquu%r#   c                   V ^8  d   QhRR/# rv   r   )r   s   "r    r!   r\      s      d r#   c                	*   V P                   '       Ed    V P                   P                  4       pVP                  '       d%   ^ Vn        V P                  P	                  V4       Kc  VP
                  ;q P                  VP
                  &   V P                  P	                  V4       \        V P                  4      V P                  8  dK   V P                  P                  4       pV P                  P                  V4      VJ g   K_  V P                  V Kn  R# R# )r   N)rc   ry   rV   re   rr   r   r`   rf   rQ   rd   rI   )r&   rL   gs   &  r    rp   S3Fifo._evict_small   s    jjj

 Avvv		$$Q'()-JJquu%

%%a($**o(8(88

(Azz~~a(A- JJqM r#   )rf   r`   rC   re   rd   r;   rc   rb   N)r0   r1   r2   r3   r4   rE   r.   r'   rq   rp   r7   r   r#   r    r   r   W   s%    %$, r#   c                  D    ] tR t^t$ RtR]R&   R]R&   R]R&   R]R&   R	tR
# )	SieveNoder   nextr   visitedr   r   boolzOptional[SieveNode]r   N)r   r   r   r   rW   r   r#   r    r   r      s    3I	HM
r#   r   c                  J    ] tR t^tRtR R ltR R ltR R ltR R	 ltR
t	R# )r   a  FIFO-based quick-demotion cache [SIEVE]_.

Simpler FIFO-based cache, cousin of :class:`S3Fifo`.
Experimentally slightly lower hit rates than :class:`S3Fifo` (if
way superior to LRU still), but much more compact (~50% lower
memory overhead at larger cache sizes, up to 100% at very small
cache sizes).

Can be an interesting candidate when trying to save on memory,
although the contained entries will generally be much larger than
the cache itself.
c                    V ^8  d   QhRRRR/# )r   r;   r<   r   r   r   )r   s   "r    r!   Sieve.__annotate__   s     % % % %r#   c                	    Wn         / V n        R V n        R V n        R V n        R V n        \        P                  ! 4       V n        R # r?   )	r;   r@   headtailhandprevrA   rB   rC   rD   s   &&r    rE   Sieve.__init__   s8    +-
)-	)-	)-	)-	NN$	r#   c                    V ^8  d   QhRRRR/# r+   r   )r   s   "r    r!   r      s      s '> r#   c                	r    V P                   P                  V4      ;p'       d   R Vn        VP                  # R# rx   )r@   rI   r   r   )r&   r   rs   s   && r    r.   Sieve.__getitem__   s.    JJNN3''5' EM;;r#   c               $    V ^8  d   QhRRRRRR/# r   r   )r   s   "r    r!   r      s!     ! !s != !T !r#   c                	   V P                   ;_uu_ 4        V P                  P                  V4      ;p'       d   W#n         R R R 4       R # \	        V P                  4      V P
                  8  d   V P                  4        \        WRR 4      ;q@P                  V&   V P                  '       d   W@P                  n	        W@n        V P                  f   W@n
        R R R 4       R #   + '       g   i     R # ; iNF)rC   r@   rI   r   rQ   r;   _evictr   r   r   r   )r&   r   r   rL   nodes   &&&  r    r'   Sieve.__setitem__   s    YYYJJNN3''q' Y
 4::$,,.%.s5$%GGD::c?yyy!%		Iyy  	 YYYs   +C
BCC0	c                   V ^8  d   QhRR/# rv   r   )r   s   "r    r!   r      s     ! ! !r#   c                	   V P                   '       d   V P                   V P                  r!MV P                  R r!V'       dJ   VP                  '       d8   RVn        VP                  '       d   VP                  Tr!KB  V P                  R r!KQ  V'       g   R # VP                  V n         W n        V P
                  VP                   VP                  '       g   W n        V'       d   VP                  Vn        R # VP                  V n        R # r   )r   r   r   r   r   r@   r   r   )r&   objpobjs   &  r    r   Sieve._evict   s    999		499		4ckkkCKxxxHHcT IItTHH		JJswwxxxIDIDIr#   )r@   r   r   rC   r;   r   r   N)
r0   r1   r2   r3   r4   rE   r.   r'   r   r7   r   r#   r    r   r      s     %! ! !r#   c                  T    ] tR t^tRtR R lt]R R l4       tR R ltR R	 lt	R
t
R# )LocalaL  Thread local cache decorator. Takes a cache factory and lazily
instantiates a cache for each thread it's accessed from.

This means the cache capacity and memory consumption is
figuratively multiplied by however many threads the cache is used
from, but those threads don't share their caching, and thus don't
contend on cache use.

c                    V ^8  d   QhRRRR/# )r   factoryzCallable[[], Cache]r   r   r   )r   s   "r    r!   Local.__annotate__  s       3  r#   c                	2    \        R 4      V n        Wn        R# )zlocal-cacheN)r   cvr   )r&   r   s   &&r    rE   Local.__init__  s    %/%>r#   c                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r    r!   r     s      u r#   c                	    V P                   P                  R 4      pVf,   V P                  4       pV P                   P                  V4       V# r?   )r   rI   r   set)r&   cs   & r    r@   Local.cache  s8    GGKK9AGGKKNr#   c                    V ^8  d   QhRRRR/# r+   r   )r   s   "r    r!   r     s      s '> r#   c                	(    V P                   V,          # r?   r@   r-   s   &&r    r.   Local.__getitem__  s    zz#r#   c               $    V ^8  d   QhRRRRRR/# r   r   )r   s   "r    r!   r     s!        s  =  T  r#   c                	"    W P                   V&   R # r?   r   r%   s   &&&r    r'   Local.__setitem__  s    

3r#   )r   r   N)r0   r1   r2   r3   r4   rE   propertyr@   r.   r'   r7   r   r#   r    r   r      s/         r#   r   c                  2    ] tR tRtRtR R ltR R ltRtR# )	r   i  a  A wrapper resolver which takes an underlying concrete
:class:`Cache` for the actual caching and cache strategy.

This resolver only interacts with the :class:`Cache` and delegates
to the wrapped resolver in case of lookup failure.

:class:`CachingParser` will set entries back in the cache when
filling them up, it does not update results in place (and can't
really, they're immutable).

c                    V ^8  d   QhRRRR/# )r   resolverr   r@   r   r   )r   s   "r    r!   CachingResolver.__annotate__"  s     " " "% "r#   c                	    Wn         W n        R # r?   )parserr@   )r&   r   r@   s   &&&r    rE   CachingResolver.__init__"  s     (!
r#   c               $    V ^8  d   QhRRRRRR/# )r   uar   domainsr   r   r   r   )r   s   "r    r!   r   &  s!      3  } r#   c               	   V P                   V,          pV'       d&   W#P                  9   d   V# W#P                  ( ,          pV P                  W4      pV'       d   \        TVP                  VP                  ,          VP                  ;'       g    VP                  VP
                  ;'       g    VP
                  VP                  ;'       g    VP                  R 7      pW@P                   V&   V# ))stringr   
user_agentosdevice)r@   r   r   r   r   r   r   )r&   r   r   rs   rn   s   """  r    __call__CachingResolver.__call__&  s    

2--'~%GKK$		1 ++;;q||88##qtt||//qxxA 

2r#   )r@   r   N)r0   r1   r2   r3   r4   rE   r   r7   r   r#   r    r   r     s    
" r#   )r   r   r   r   r   )
__future__r   r5   dataclassesrA   collectionsr   r   contextvarsr   typingr   r   r	   r
   r   r   corer   r   r   __all__r   r   	dataclassrU   r   r   r   r   r   r   r#   r    <module>r      s    " 
   * "  2 1H &$ $@   H HV   I! I!X   <# #r#   