
     hl)                     `   d 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.    N)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     R/var/www/html/Sam_Eipo/venv/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   a?  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   r2   s     r   r   zLRUCache.__init__4   s'    
_&&
MM			r   c                     | j         5  | j                            |          x}| |<   |cd d d            S # 1 swxY w Y   d S r   )r5   r6   popr   keyr#   s      r   __getitem__zLRUCache.__getitem__9   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)r5   r6   r2   updatelenrangepopitem)r   argskwargsr6   r2   _s         r   r>   zLRUCache.update>   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   )r5   r6   rA   )r   r=   s     r   rA   zLRUCache.popitemG   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   )r5   r2   r?   r6   r8   nextiterr9   s      r   __setitem__zLRUCache.__setitem__K   s    Z 	# 	#z 5c$)nn
::	d4	??33444"DIcN	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   A(A==BBc                 *    t          | j                  S r   )rH   r6   r*   s    r   __iter__zLRUCache.__iter__R   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   r5   r6   KeyErrorr   ks     r   _iterate_itemszLRUCache._iterate_itemsU   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   rM   rO   s     r   _iterate_valueszLRUCache._iterate_values^   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   )r5   r6   keysr*   s    r   _iterate_keyszLRUCache._iterate_keysh   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   )r5   intr6   r8   str)r   r:   deltanewvals       r   incrzLRUCache.incrn   s    Z 	 	 s++,,u4FFDI	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   >AAAc                 h    t          t          |                     }|                    d           |S )Nr5   )dictvarsr8   )r   ds     r   __getstate__zLRUCache.__getstate__v   s)    d	gr   c                 D    || _         t          j                    | _        d S r   )__dict__r3   r4   r5   )r   states     r   __setstate__zLRUCache.__setstate__{   s    _&&


r   r   )T)r   )r,   r-   r.   __doc__r   r;   r>   rA   rI   rK   rQ   	iteritemsrS   
itervaluesrV   iterkeysr\   ra   re   rU   valuesitemsr/   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)r2   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sortedrk   hitsrN   misses)	rB   rC   r:   r#   _Mcachefunkeyfunr5   s	       r   rt   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)clearrr   rs   )rt   ru   s   r   ry   z(memoize.<locals>._memoize.<locals>.clear   s"    KKMMM"##BGbiiir   r   )r3   Lockr   rr   rs   ry   original_func)rv   ry   rt   ru   r5   Cacherw   maxsizes   ` @@@r   _memoizezmemoize.<locals>._memoize   s      G$$$	s	 	 	 	 	 	 	 	 
	"	$ 	$ 	$ 	$ 	$ 	$
  ")	r   r/   )r}   rw   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   rv   rB   rC   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   )rY   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   r/   r   rhss     r   __eq__zlazy.__eq__       tvv}r   c                      |             |k    S r   r/   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.   rf   r   r$   r   r   r+   r   r   r   r   r/   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 )znReturn true if the object is iterable.

    Note:
        Returns false if object is a mapping or string.
    r/   )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   r/   ).0rP   vs      r   
<dictcomp>zdictfilter.<locals>.<dictcomp>   s    888TQ!-Aq---r   )r^   rk   )r`   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   rD   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   r/   )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   floatrG   r@   rX   r	   abs)rv   catchrB   rC   errbackmax_retriesinterval_startinterval_stepinterval_maxcallbacktimeoutinterval_rangeendretriesexcttsrD   s                    r   r   r     s   B )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   rP   r   fmts      r   	<genexpr>zreprkwargs.<locals>.<genexpr>L  s;      LLTQCJJq*Q--00LLLLLLr   )joinrk   )rC   sepr   s     `r   
reprkwargsr   K  s2    88LLLLV\\^^LLLLLLr   r/   c           	          |si n|}d                     | |                    t          t          |pd                    |r|r|pdt	          ||                    S )Nz
{}({}{}{})r/    )r   r   mapr   r   )namerB   rC   r   s       r   reprcallr   O  se    )RR6Fchhs:tzr2233	&!c'R63  r   c                 N    t          j        |           }||j        v p||j        v S r   )inspectgetfullargspecrB   
kwonlyargs)funcargument_nameargument_specs      r   accepts_argumentr   X  s2    *400M++ 	211r   r   )r   Nr   F)r   Nr   r   )	NNNNr   r   r   NN)r   r   )r/   Nr   ))rf   r   r   r3   collectionsr   r   collections.abcr   r   	itertoolsr   r   r
   r	   
vine.utilsr   encodingr   r   __all__objectro   r   r   r   r   r   rY   r   r   r   r   r   r   r   r   r   r   promisemaybe_promiser/   r   r   <module>r      sx           - - - - - - - - - - - - - - - - # # # # # # # #               - - - - - -
 vxx= = = = = = = =&W W W W Wx W W Wt 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<@9+ 9+ 9+ 9+xM M M M      r   