
    ^f)                    l   d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
mZ ddlmZmZ ddlmZmZ ddlmZ d	d
lmZ dZ e            Z G d d          Z G d de          ZddefdZ G d d          Zd Zeefe
ffdZeeffdZ d&dZ!d Z"d'dZ#d(dZ$	 	 	 d)dZ%d*d"Z&d+d$Z'd% Z(eZ)eZ*dS ),zFunctional Utilities.    )annotationsN)OrderedDictUserDict)IterableMapping)countrepeat)sleeptime)wraps   )	safe_repr)LRUCachememoizelazymaybe_evaluateis_list
maybe_list
dictfilterretry_over_timec                       e Zd Zd Zd Zd ZdS )ChannelPromisec                    || _         d S N)__contract__)selfcontracts     H/var/www/html/env/lib/python3.11/site-packages/kombu/utils/functional.py__init__zChannelPromise.__init__   s    $    c                l    	 | j         S # t          $ r  |                                 x}| _         |cY S w xY wr   )	__value__AttributeErrorr   )r   values     r   __call__zChannelPromise.__call__   sK    	>! 	 	 	%)%6%6%8%88EDNLLL	s   	 '33c                ~    	 t          | j                  S # t          $ r dt          | j                  ddcY S w xY w)Nz<promise: 0xx>)reprr"   r#   idr   r   s    r   __repr__zChannelPromise.__repr__%   sW    	=''' 	= 	= 	=<"T%6"7"7<<<<<<<	=s    #<<N)__name__
__module____qualname__r   r%   r,    r    r   r   r      sA        % % %  = = = = =r    r   c                  x    e Zd ZdZddZd Zd ZddZd Zd	 Z	d
 Z
e
Zd ZeZd ZeZddZd Zd ZeZeZe
ZdS )r   aM  LRU Cache implementation using a doubly linked list to track access.

    Arguments:
    ---------
        limit (int): The maximum number of keys to keep in the cache.
            When a new key is inserted and the limit has been exceeded,
            the *Least Recently Used* key will be discarded from the
            cache.
    Nc                j    || _         t          j                    | _        t	                      | _        d S r   )limit	threadingRLockmutexr   data)r   r3   s     r   r   zLRUCache.__init__7   s'    
_&&
MM			r    c                    | j         5  | j                            |          x}| |<   |cd d d            S # 1 swxY w Y   d S r   )r6   r7   popr   keyr$   s      r   __getitem__zLRUCache.__getitem__<   s    Z 	 	 $	c 2 22EDI	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   !6::c                   | j         5  | j        | j        }} |j        |i | |rKt	          |          |k    r8t          t	          |          |z
            D ]}|                    d           d d d            d S # 1 swxY w Y   d S )NF)last)r6   r7   r3   updatelenrangepopitem)r   argskwargsr7   r3   _s         r   r?   zLRUCache.updateA   s    Z 	- 	-)TZ%DDK(((( -TU**s4yy5011 - -ALLeL,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   A)A>>BBTc                x    | j         5  | j                            |          cd d d            S # 1 swxY w Y   d S r   )r6   r7   rB   )r   r>   s     r   rB   zLRUCache.popitemJ   s    Z 	+ 	+9$$T**	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+s   /33c                   | j         5  | j        rVt          | j                  | j        k    r9| j                            t          t          | j                                       || j        |<   d d d            d S # 1 swxY w Y   d S r   )r6   r3   r@   r7   r9   nextiterr:   s      r   __setitem__zLRUCache.__setitem__N   s    Z 	# 	#z 5c$)nn
::	d4	??33444"DIcN	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   A(A==BBc                *    t          | j                  S r   )rI   r7   r+   s    r   __iter__zLRUCache.__iter__U   s    DIr    c              #     K   | j         5  | D ]$}	 || j        |         fV  # t          $ r Y !w xY w	 d d d            d S # 1 swxY w Y   d S r   r6   r7   KeyErrorr   ks     r   _iterate_itemszLRUCache._iterate_itemsX   s      Z 	 	  dil+++++   D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s,   A "A 
/A /A  AAc              #     K   | j         5  | D ]"}	 | j        |         V  # t          $ r Y w xY w	 d d d            d S # 1 swxY w Y   d S r   rN   rP   s     r   _iterate_valueszLRUCache._iterate_valuesa   s      Z 	 	  )A,&&&&   D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s'   > >
->->AAc                v    | j         5  | j                                        cd d d            S # 1 swxY w Y   d S r   )r6   r7   keysr+   s    r   _iterate_keyszLRUCache._iterate_keysk   s}    Z 	$ 	$9>>##	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   .22r   c                    | j         5  t          | j                            |                    |z   }t	          |          | |<   |cd d d            S # 1 swxY w Y   d S r   )r6   intr7   r9   str)r   r;   deltanewvals       r   incrzLRUCache.incrq   s    Z 	 	 s++,,u4FFDI	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   >AAAc                h    t          t          |                     }|                    d           |S )Nr6   )dictvarsr9   )r   ds     r   __getstate__zLRUCache.__getstate__y   s)    d	gr    c                D    || _         t          j                    | _        d S r   )__dict__r4   r5   r6   )r   states     r   __setstate__zLRUCache.__setstate__~   s    _&&


r    r   )T)r   )r-   r.   r/   __doc__r   r<   r?   rB   rJ   rL   rR   	iteritemsrT   
itervaluesrW   iterkeysr]   rb   rf   rV   valuesitemsr0   r    r   r   r   ,   s        " " " "
  
- - -+ + + +# # #     I   !J$ $ $ H     
' ' ' DFEEEr    r   c                      fd}|S )z)Decorator to cache function return value.c                     t          j                               t                      fd            fd}dx_        _        |_         _        S )N)r3   c                    r | |          }n:| t           fz   t          t          |                                                    z   }	 5  |         }d d d            n# 1 swxY w Y   xj        dz  c_        nG# t
          $ r:  | i |}xj        dz  c_        5  ||<   d d d            n# 1 swxY w Y   Y nw xY w|S )Nr   )KEYWORD_MARKtuplesortedrl   hitsrO   misses)	rC   rD   r;   r$   _Mcachefunkeyfunr6   s	       r   ru   z%memoize.<locals>._memoize.<locals>._M   sq    MfT6**l_,uVFLLNN5K5K/L/LL	 ' '!#JE' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 1  ' ' 'T,V,,		Q		 ' '!&E#J' ' ' ' ' ' ' ' ' ' ' ' ' ' '' LsZ   A? 	A#A? #A''A? *A'+A? ?$C#B5)C5B9	9C<B9	=CCc                 L                                      dx _         _        dS )z+Clear the cache and reset cache statistics.r   N)clearrs   rt   )ru   rv   s   r   rz   z(memoize.<locals>._memoize.<locals>.clear   s"    KKMMM"##BGbiiir    r   )r4   Lockr   rs   rt   rz   original_func)rw   rz   ru   rv   r6   Cacherx   maxsizes   ` @@@r   _memoizezmemoize.<locals>._memoize   s      G$$$	s	 	 	 	 	 	 	 	 
	"	$ 	$ 	$ 	$ 	$ 	$
  ")	r    r0   )r~   rx   r}   r   s   ``` r   r   r      s0          @ Or    c                  H    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZdS )r   a
  Holds lazy evaluation.

    Evaluated when called or if the :meth:`evaluate` method is called.
    The function is re-evaluated on every call.

    Overloaded operations that will evaluate the promise:
        :meth:`__str__`, :meth:`__repr__`, :meth:`__cmp__`.
    c                0    || _         || _        || _        d S r   _fun_args_kwargs)r   rw   rC   rD   s       r   r   zlazy.__init__   s    	
r    c                *    |                                  S r   )evaluater+   s    r   r%   zlazy.__call__   s    }}r    c                0     | j         | j        i | j        S r   r   r+   s    r   r   zlazy.evaluate   s    ty$*5555r    c                0    t           |                       S r   )rZ   r+   s    r   __str__zlazy.__str__   s    4466{{r    c                0    t           |                       S r   )r)   r+   s    r   r,   zlazy.__repr__   s    DDFF||r    c                     |             |k    S r   r0   r   rhss     r   __eq__zlazy.__eq__       tvv}r    c                     |             |k    S r   r0   r   s     r   __ne__zlazy.__ne__   r   r    c                *    | |t          |           <   | S r   )r*   )r   memos     r   __deepcopy__zlazy.__deepcopy__   s    RXXr    c                <    | j         | j        f| j        | j        dfS )N)r   r   )	__class__r   r   r   r+   s    r   
__reduce__zlazy.__reduce__   s.    
:>,/H /H I 	Ir    N)r-   r.   r/   rg   r   r%   r   r   r,   r   r   r   r   r0   r    r   r   r      s           
  6 6 6          I I I I Ir    r   c                X    t          | t                    r|                                 S | S )z9Evaluate value only if value is a :class:`lazy` instance.)
isinstancer   r   )r$   s    r   r   r      s)    %  ~~Lr    c                H    t          | |          ot          | |pd           S )zwReturn true if the object is iterable.

    Note:
    ----
        Returns false if object is a mapping or string.
    r0   )r   )objscalarsiterss      r   r   r      s*     c5!!H*S'-R*H*H&HHr    c                0    | t          | |          r| n| gS )z0Return list of one element if ``l`` is a scalar.)r   )r   r   s     r   r   r      s     +g!6!6+33SEAr    c                h    | |n|rt          | fi |n| } d |                                 D             S )z=Remove all keys from dict ``d`` whose value is :const:`None`.Nc                    i | ]
\  }}|||S r   r0   ).0rQ   vs      r   
<dictcomp>zdictfilter.<locals>.<dictcomp>   s    888TQ!-Aq---r    )r_   rl   )ra   kws     r   r   r      s@    ir8d1mmmmmqA88QWWYY8888r    c              #     K   t          |           } t          j        }t          d           D ]} ||            | d         V  d S )Nr   )listrandomshuffler	   )itr   rE   s      r   shufflecycler      sS      	bBnGD\\  e r          ?Fc              #  N   K   | dz  }	 |r||k    r
|V  ||z  }n|sd S ||z
  V  )Nr   r0   )startstopstep
repeatlastcurs        r   fxranger      sZ      
#+C 	sd{{III4KCC *r          Y@c              #  p   K   d| dz  }}	 ||k    rd S |V  |rt          ||z   |          }n||z  }||z  }-)Nr   r   )min)r   r   r   maxsum_r   s         r   
fxrangemaxr     sc      53;#D3;;E			 	cDj$''CC4KCr          c           	     H   |si n|}|sg n|}t          |||z   |d          }|
rt                      |
z   nd}t                      D ]}	  | |i |c S # |$ r}|||k    r |rt                      |k    r |	r
 |	             t          |r ||||          nt	          |                    }|rft          t          |                    D ]}|	r
 |	             t          d           t          t          t          |          |z
                       Y d}~d}~ww xY wdS )a  Retry the function over and over until max retries is exceeded.

    For each retry we sleep a for a while before we try again, this interval
    is increased for every retry until the max seconds is reached.

    Arguments:
    ---------
        fun (Callable): The function to try
        catch (Tuple[BaseException]): Exceptions to catch, can be either
            tuple or a single exception class.

    Keyword Arguments:
    -----------------
        args (Tuple): Positional arguments passed on to the function.
        kwargs (Dict): Keyword arguments passed on to the function.
        errback (Callable): Callback for when an exception in ``catch``
            is raised.  The callback must take three arguments:
            ``exc``, ``interval_range`` and ``retries``, where ``exc``
            is the exception instance, ``interval_range`` is an iterator
            which return the time in seconds to sleep next, and ``retries``
            is the number of previous retries.
        max_retries (int): Maximum number of retries before we give up.
            If neither of this and timeout is set, we will retry forever.
            If one of this and timeout is reached, stop.
        interval_start (float): How long (in seconds) we start sleeping
            between retries.
        interval_step (float): By how much the interval is increased for
            each retry.
        interval_max (float): Maximum number of seconds to sleep
            between retries.
        timeout (int): Maximum seconds waiting before we give up.
    T)r   Nr   )	r   r   r   floatrH   rA   rY   r
   abs)rw   catchrC   rD   errbackmax_retriesinterval_startinterval_stepinterval_maxcallbacktimeoutinterval_rangeendretriesexcttsrE   s                    r   r   r     s   F )RR6F#22tD^)N:*t= = =N &
/$&&7

4C77 + +	+3'''''' 	+ 	+ 	+&7k+A+A tvv|| 


 2^W===!.113 3C +s3xx  A # 


#JJJJc#c((S.))***	++ +s   	ADB=DD, {0}={1}c                j    |                     fd|                                 D                       S )Nc              3  d   K   | ]*\  }}                     |t          |                    V  +d S r   )format
_safe_repr)r   rQ   r   fmts      r   	<genexpr>zreprkwargs.<locals>.<genexpr>R  s;      LLTQCJJq*Q--00LLLLLLr    )joinrl   )rD   sepr   s     `r   
reprkwargsr   Q  s2    88LLLLV\\^^LLLLLLr    r0   c           	         |si n|}d                     | |                    t          t          |pd                    |r|r|pdt	          ||                    S )Nz
{}({}{}{})r0    )r   r   mapr   r   )namerC   rD   r   s       r   reprcallr   U  se    )RR6Fchhs:tzr2233	&!c'R63  r    c                N    t          j        |           }||j        v p||j        v S r   )inspectgetfullargspecrC   
kwonlyargs)funcargument_nameargument_specs      r   accepts_argumentr   ^  s2    *400M++ 	211r    r   )r   Nr   F)r   Nr   r   )	NNNNr   r   r   NN)r   r   )r0   Nr   )+rg   
__future__r   r   r   r4   collectionsr   r   collections.abcr   r   	itertoolsr   r	   r   r
   
vine.utilsr   encodingr   r   __all__objectrp   r   r   r   r   r   rZ   r   r   r   r   r   r   r   r   r   r   promisemaybe_promiser0   r    r   <module>r      s     " " " " " "       - - - - - - - - - - - - - - - - # # # # # # # #               - - - - - -
 vxx= = = = = = = =&X X X X Xx X X Xv X " " " "J'I 'I 'I 'I 'I 'I 'I 'IT   "3{ I I I I %cN B B B B
9 9 9 9  	 	 	 	
 
 
 
 AEFG<@;+ ;+ ;+ ;+|M M M M      r    