
    `f.                        d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	 ddl
mZmZ ddlmZmZmZmZmZmZmZ ddlmZ dd	lmZ  ee          Zd
ZdZ G d d          Z G d de          Zd Zd Z d Z!d Z"d,dZ#d Z$d,dZ%d Z&d Z'd Z(d Z) G d dee*          Z+d-dZ,d.d ed!ef         d"e-d#e.fd$Z/d% Z0d,d&Z1d' Z2d( Z3d) Z4d* Z5d+ Z6dS )/zFunctional-style utilities.    N)UserList)partial)isliceteezip_longest)AnyCallable)LRUCache
dictfilteris_listlazymaybe_evaluate
maybe_listmemoize)promise)
get_logger)r
   r   r   r   mlazynoopfirstfirstmethodchunkspadlistmattrgetteruniqregenr   r   r   head_from_funmaybefun_accepts_kwargsz4
def {fun_name}({fun_args}):
    return {fun_value}
c                       e Zd Zd Zd ZdS )DummyContextc                     | S N selfs    I/var/www/html/env/lib/python3.11/site-packages/celery/utils/functional.py	__enter__zDummyContext.__enter__   s        c                     d S r"   r#   )r%   exc_infos     r&   __exit__zDummyContext.__exit__!   s    r(   N)__name__
__module____qualname__r'   r+   r#   r(   r&   r    r       s2              r(   r    c                   *     e Zd ZdZdZdZ fdZ xZS )r   zMemoized lazy evaluation.

    The function is only evaluated once, every subsequent access
    will return the same value.
    FNc                 x    | j         s,t                                                      | _        d| _         | j        S NT)	evaluatedsuperevaluate_value)r%   	__class__s    r&   r4   zmlazy.evaluate0   s3    ~ 	"''**,,DK!DN{r(   )r,   r-   r.   __doc__r2   r5   r4   __classcell__)r6   s   @r&   r   r   %   sN          IF        r(   r   c                      dS )zONo operation.

    Takes any arguments/keyword arguments and does nothing.
    Nr#   )argskwargss     r&   r   r   7   s      r(   c                     | S )z%Return the first positional argument.r#   )argr:   r;   s      r&   pass1r>   >   s    Jr(   c              #   Z   K   | D ]%}t          |t                    r
 |            }|V  &d S r"   )
isinstancer   )itvalues     r&   evaluate_promisesrC   C   sG        eW%% 	EGGE r(   c                 V     t           fdt          |          D             d          S )zReturn the first element in ``it`` that ``predicate`` accepts.

    If ``predicate`` is None it will return the first item that's not
    :const:`None`.
    c              3   <   K   | ]} |          n||V  d S r"   r#   ).0v	predicates     r&   	<genexpr>zfirst.<locals>.<genexpr>Q   sI       	G 	Gq%1IIaLL11q} 
7D}}}	G 	Gr(   N)nextrC   )rH   rA   s   ` r&   r   r   J   sO     	G 	G 	G 	G%b)) 	G 	G 	G  r(   c                       fd}|S )zMultiple dispatch.

    Return a function that with a list of instances,
    finds the first instance that gives a value for the given method.

    The list can also contain lazy instances
    (:class:`~kombu.utils.functional.lazy`.)
    c                     | D ]L}	 t          t          |                    }r |g|R i |n ||i |}||c S =# t          $ r Y Iw xY wd S r"   )getattrr   AttributeError)rA   r:   r;   objmethreplymethodon_calls         r&   _matcherzfirstmethod.<locals>._matchera   s     		! 		!C!~c22F;;;B 47777777"dD3F33 
 $ LLL % "   		! 		!s   3A
AAr#   )rR   rS   rT   s   `` r&   r   r   W   s)    
! 
! 
! 
! 
! 
! Or(   c           	   #   `   K   | D ](}|gt          t          | |dz
                      z   V  )dS )as  Split an iterator into chunks with `n` elements each.

    Warning:
        ``it`` must be an actual iterator, if you pass this a
        concrete sequence will get you repeating elements.

        So ``chunks(iter(range(1000)), 10)`` is fine, but
        ``chunks(range(1000), 10)`` is not.

    Example:
        # n == 2
        >>> x = chunks(iter([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 2)
        >>> list(x)
        [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10]]

        # n == 3
        >>> x = chunks(iter([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 3)
        >>> list(x)
        [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10]]
       N)listr   )rA   nitems      r&   r   r   p   sM      *  / /ftF2q1u--......./ /r(   c                 ^    t          |           d|         |g|t          |           z
  z  z   S )a  Pad list with default elements.

    Example:
        >>> first, last, city = padlist(['George', 'Costanza', 'NYC'], 3)
        ('George', 'Costanza', 'NYC')
        >>> first, last, city = padlist(['George', 'Costanza'], 3)
        ('George', 'Costanza', None)
        >>> first, last, city, planet = padlist(
        ...     ['George', 'Costanza', 'NYC'], 4, default='Earth',
        ... )
        ('George', 'Costanza', 'NYC', 'Earth')
    N)rW   len)	containersizedefaults      r&   r   r      s0     	??5D5!WII1F$GGGr(   c                        fdS )zGet attributes, ignoring attribute errors.

    Like :func:`operator.itemgetter` but return :const:`None` on missing
    attributes instead of raising :exc:`AttributeError`.
    c                 "      fdD             S )Nc                 4    i | ]}|t          |d           S r"   )rM   )rF   attrrO   s     r&   
<dictcomp>z1mattrgetter.<locals>.<lambda>.<locals>.<dictcomp>   s'    III4gc466IIIr(   r#   )rO   attrss   `r&   <lambda>zmattrgetter.<locals>.<lambda>   s    IIII5III r(   r#   )rd   s   `r&   r   r      s     JIIIIr(   c                 <    t                      fd| D             S )z7Return all unique elements in ``it``, preserving order.c              3   N   K   | ]}|v                     |          p|V   d S r"   )add)rF   rO   seens     r&   rI   zuniq.<locals>.<genexpr>   s6      BBS#T//DHHSMM S////BBr(   )set)rA   ri   s    @r&   r   r      s&    55DBBBBBBBBBr(   c                 f    t          |           \  }}t          |d           t          ||          S )zYield pairs of (current, next) items in `it`.

    `next` is None if `current` is the last item.
    Example:
        >>> list(lookahead(x for x in range(6)))
        [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, None)]
    N)r   rJ   r   )rA   abs      r&   	lookaheadrn      s0     r77DAqDMMMq!r(   c                 \    t          | t          t          f          r| S t          |           S )zConvert iterator to an object that can be consumed multiple times.

    ``Regen`` takes any iterable, and if the object is an
    generator it will cache the evaluated list on first access,
    so that the generator can be "consumed" multiple times.
    )r@   rW   tuple_regen)rA   s    r&   r   r      s+     "tUm$$ 	"::r(   c                   \    e Zd Zd Zd Zd Zd ZddZd Zd Z	d	 Z
ed
             Zd ZdS )rq   c                 0    || _         g | _        d| _        d S )NF)
_regen__it_regen__consumed_regen__done)r%   rA   s     r&   __init__z_regen.__init__   s     	r(   c                      t           | j        ffS r"   )rW   datar$   s    r&   
__reduce__z_regen.__reduce__   s    di\!!r(   c                 l    fd| j         D             | _         t          | j                  | _        d S )Nc                 &    g | ]} |          S r#   r#   )rF   elfuncs     r&   
<listcomp>z_regen.map.<locals>.<listcomp>   s!    >>>4488>>>r(   )ru   maprt   )r%   r~   s    `r&   r   z
_regen.map   s7    >>>>do>>>di((			r(   c                 4    | j                                         S r"   )rt   __length_hint__r$   s    r&   r   z_regen.__length_hint__   s    y((***r(   Nc              #     K   | j         s||dk    rt          | j                  }	 t          |          }n# t          $ r Y d S w xY w| j                            |           | j         st	 t          |          }| j                            |           n# t          $ r d| _         Y |V  d S w xY w	 |V  n	# |V  w xY w|}||dz  }|dk    rd S | j         nd S d S d S d S )Nr   TrV   )rv   iterrt   rJ   StopIterationru   append)r%   limitrA   nownext_s        r&   __lookahead_consumez_regen.__lookahead_consume   sJ     { 	diB2hh    O""3''' k  HHEO**51111$   "&DKIIIII	 2
 IIII#IIII$QJEzz k   	 	 s9   7 
AA*)B B6 B-%B6 ,B--B6 6B<c              #   X   K   | j         E d {V  |                                 E d {V  d S r"   )ru   _regen__lookahead_consumer$   s    r&   __iter__z_regen.__iter__   sJ      ?"""""""++-----------r(   c                     |dk     r| j         |         S |t          | j                  z
  dz   }|                     |          D ]}| j        |         S )Nr   rV   )r   )ry   r[   ru   r   )r%   indexconsume_count_s       r&   __getitem__z_regen.__getitem__   sc    1999U## DO 4 44q8)))>> 	 	Au%%r(   c                     t          | j                  rdS 	 t          t          |                      dS # t          $ r Y dS w xY w)NTF)r[   ru   rJ   r   r   r$   s    r&   __bool__z_regen.__bool__   s]    t 	4	d 4  	 	 	55	s   6 
AAc                 j    | j         s&| j                            | j                   d| _         | j        S r1   )rv   ru   extendrt   r$   s    r&   ry   z_regen.data	  s3    { 	O""49---DKr(   c                     d                     | j        j        d                    d | j        D                       | j        sdnd          S )Nz<{}: [{}{}]>, c              3   4   K   | ]}t          |          V  d S r"   )repr)rF   es     r&   rI   z"_regen.__repr__.<locals>.<genexpr>  s(      77!d1gg777777r(   z... )formatr6   r,   joinru   rv   r$   s    r&   __repr__z_regen.__repr__  sP    $$N#II77t77777,EE"
 
 	
r(   r"   )r,   r-   r.   rw   rz   r   r   r   r   r   r   propertyry   r   r#   r(   r&   rq   rq      s          " " ") ) )+ + +   4. . .& & &	 	 	   X
 
 
 
 
r(   rq   Tc                    | j         rt          | j                   }|r.t          t          t          | j                                       n| j         }| j        d |          }t          t          | j        | d          |                    }n	| j        g }}| j        }| j        }| j        rt          | j
                  t          | j                                                  z
  }|r1d t          | j                                                  D             }	n0t          | j                                                  }	n	| j
        g }	}d                    t          d d                    |          d                    d |D                       |rd| nd |s|	r|sdnd |rd                    |          nd d                    d |	D                       |rd| nd g                    S )Nc                     g | ]	\  }}||f
S r#   r#   )rF   ikws      r&   r   z!_argsfromspec.<locals>.<listcomp>'  s-     # # #!ArQ# # #r(   r   c              3   *   K   | ]\  }}| d | V  dS )=Nr#   rF   krG   s      r&   rI   z _argsfromspec.<locals>.<genexpr>1  s0      22AQ****222222r(   *c              3   ,   K   | ]\  }}| d | dV  dS )z=""Nr#   r   s      r&   rI   z _argsfromspec.<locals>.<genexpr>5  s2      ??41aQ,,!,,,??????r(   z**)defaultsr[   rW   ranger:   zipvarargsvarkwkwonlydefaultsrj   
kwonlyargskeys	enumerateitemsr   filter)
specreplace_defaultssplitr   
positionaloptionalr   r   r   kwonlyargs_optionals
             r&   _argsfromspecr     s   } -DM""7G 'Ds4=1122333 	Yww'
DIufgg.99::#y"H
lGJE 	>))C0C0H0H0J0J,K,KK
 	D# #%.t/B/G/G/I/I%J%J# # # #'t':'@'@'B'B"C"C*./2'
99VD		*		2222222 *GdL1L7L!+5		*		??+>?????'U4#     r(   Ffun.boundreturnc                    t          j        |           }t          |           }| j        j        dk    }t          j        |           }|s|r|s|s| j        j        | j        } }n| j        }t                              |t          t          j
        |                     d          }t                              |           d| j        i}t          ||           ||         }	||	_        |rt!          |	t#                                S |	S )z1Generate signature function from actual function.cython_function_or_methodrV   )fun_namefun_args	fun_valuer,   )inspect
isfunctioncallabler6   r,   ismethod__call__FUNHEAD_TEMPLATEr   r   getfullargspecloggerdebugr-   exec_sourcer   object)
r   r   is_functionis_callable	is_cython	is_methodname
definition	namespaceresults
             r&   r   r   :  s    $S))K3--K&*EEI %%I ; y  M*CLc|!((w5c::;; )  J
 LLS^,I 	Yt_FFN )vvxx(((Mr(   c                 h    t          j        |           }|j        pt          |j                  |k    S r"   )r   r   r   r[   r:   )r   rX   argspecs      r&   arity_greaterr   [  s.    $S))G?3c',//!33r(   c                     t          j        |          }|j        p)|j        p"|rt	          |j                  |k    n| |j        v S r"   )r   r   r   r   r[   r:   )r   r   positionr   s       r&   fun_takes_argumentr   `  sM    !#&&D
 	Hdl 	H'/	FTY8	#	#TTY5Fr(   c                     t          d t          j        |           j                                        D                       S )z<Return true if function accepts arbitrary keyword arguments.c              3   :   K   | ]}|j         |j        k    |V  d S r"   )kindVAR_KEYWORD)rF   ps     r&   rI   z%fun_accepts_kwargs.<locals>.<genexpr>j  s=        6Q]"" 	
"""" r(   )anyr   	signature
parametersvalues)r   s    r&   r   r   h  sJ      $S))4;;==     r(   c                      | | |          n|S )z$Call typ on value if val is defined.r#   )typvals     r&   r   r   p  s    33s888C/r(   c                 D    t          | t                    r| |fz   n| |gz   S )zReturn copy of sequence seq with item added.

    Returns:
        Sequence: if seq is a tuple, the result will be a tuple,
           otherwise it depends on the implementation of ``__add__``.
    )r@   rp   )seqrY   s     r&   seq_concat_itemr   u  s)     'sE22D3$==tfDr(   c                     t          t          | |gt                              }t          | |          s ||           } t          ||          s ||          }| |z   S )a  Concatenate two sequences: ``a + b``.

    Returns:
        Sequence: The return value will depend on the largest sequence
            - if b is larger and is a tuple, the return value will be a tuple.
            - if a is larger and is a list, the return value will be a list,
    )key)typemaxr[   r@   )rl   rm   prefers      r&   seq_concat_seqr     si     #q!f#&&&''Fa   F1IIa   F1IIq5Lr(   c                 f    t          | t          t          f          ot          | t                     S r"   )r@   intfloatbool)rB   s    r&   is_numeric_valuer     s(    ec5\**J:eT3J3J/JJr(   r"   )T)F)7r7   r   collectionsr   	functoolsr   	itertoolsr   r   r   typingr   r	   kombu.utils.functionalr
   r   r   r   r   r   r   viner   celery.utils.logr   r,   r   __all__r   r    r   r   r>   rC   r   r   r   r   r   r   rn   r   rW   rq   r   r   strr   r   r   r   r   r   r   r   r#   r(   r&   <module>r     s   ! !                    . . . . . . . . . .                 k k k k k k k k k k k k k k k k k k       ' ' ' ' ' '	H		            D   $    
  
 
 
   2/ / /2H H H H J J JC C C
 
 
	 	 	T
 T
 T
 T
 T
Xt T
 T
 T
n   D xS) $ 3    B4 4 4
     0 0 0
E E E  $K K K K Kr(   