
    h.                     |   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) Z6y)-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y)DummyContextc                     | S N selfs    S/var/www/Befach/backend/env/lib/python3.12/site-packages/celery/utils/functional.py	__enter__zDummyContext.__enter__   s        c                      y r"   r#   )r%   exc_infos     r&   __exit__zDummyContext.__exit__!   s    r(   N)__name__
__module____qualname__r'   r+   r#   r(   r&   r    r       s    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                 h    | j                   st        | 	         | _        d| _         | j                  S NT)	evaluatedsuperevaluate_value)r%   	__class__s    r&   r4   zmlazy.evaluate0   s*    ~~'*,DK!DN{{r(   )r,   r-   r.   __doc__r2   r5   r4   __classcell__)r6   s   @r&   r   r   %   s     IF r(   r   c                       y)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              #   P   K   | D ]  }t        |t              r |       }|  y wr"   )
isinstancer   )itvalues     r&   evaluate_promisesrC   C   s&     eW%GE s   $&c                 @     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   | ]  }	 |      rn||  y wr"   r#   ).0v	predicates     r&   	<genexpr>zfirst.<locals>.<genexpr>Q   s*      	Gq%1IaLq} 
 	Gs   N)nextrC   )rH   rA   s   ` r&   r   r   J   s)     	G%b) 	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 ]4  }	 t        t        |            }r |g|i |n ||i |}|2|c S  y # t        $ r Y Cw xY wr"   )getattrr   AttributeError)rA   r:   r;   objmethreplymethodon_calls         r&   _matcherzfirstmethod.<locals>._matchera   sj    C!~c2F;;B777"D3F3 
 $ L 
 " s   +<	AAr#   )rR   rS   rT   s   `` r&   r   r   W   s    
! Or(   c           	   #   V   K   | D ]   }|gt        t        | |dz
              z    " yw)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   s/     * ftF2q1u-... s   ')c                 D    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      s*     	?5D!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 ci c]  }|t        | |d        c}S c c}w r"   )rM   )rO   attrattrss     r&   <lambda>zmattrgetter.<locals>.<lambda>   s!    5I4gc466IIs   r#   )rb   s   `r&   r   r      s     JIr(   c                 .    t               fd| D        S )z7Return all unique elements in ``it``, preserving order.c              3   R   K   | ]  }|vsj                  |      xs |   y wr"   )add)rF   rO   seens     r&   rI   zuniq.<locals>.<genexpr>   s'     BS#T/DHHSM S Bs   	'')set)rA   rg   s    @r&   r   r      s    5DBBBBr(   c                 N    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&   	lookaheadrl      s'     r7DAqDMq!r(   c                 H    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                   T    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y)ro   c                 .    || _         g | _        d| _        y )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    dii\!!r(   c                     | j                   D cg c]
  } ||       c}| _         t        || j                        | _        y c c}w r"   )rs   maprr   )r%   funcels      r&   rz   z
_regen.map   s3    .2oo>48>dii(	 ?s   Ac                 6    | j                   j                         S r"   )rr   __length_hint__r$   s    r&   r~   z_regen.__length_hint__   s    yy((**r(   Nc              #     K   | j                   s||dkD  rt        | j                        }	 t        |      }| j
                  j                  |       | j                   sI	 t        |      }| j
                  j                  |       	 | |}||dz  }|dk  ry | j                   sHy y y y # t        $ r Y y w xY w# t        $ r d| _         Y | y w xY w# | w xY ww)Nr   TrV   )rt   iterrr   rJ   StopIterationrs   append)r%   limitrA   nownext_s        r&   __lookahead_consumez_regen.__lookahead_consume   s     {{diiB2h OO""3' kk HEOO**51
 I$QJEz kk 2;{ !  % "&DKI	 Isc   )CB* 'C&B9 C&C*	B63C5B66C9C	C 
CCC CCc              #   l   K   | j                   E d {    | j                         E d {    y 7 7 wr"   )rs   _regen__lookahead_consumer$   s    r&   __iter__z_regen.__iter__   s.     ??""++--- 	#-s   404244c                     |dk  r| j                   |   S |t        | j                        z
  dz   }| j                  |      D ]  } | j                  |   S )Nr   rV   )r   )rw   r[   rs   r   )r%   indexconsume_count_s       r&   __getitem__z_regen.__getitem__   s\    1999U## DOO 44q8)))>A ?u%%r(   c                 x    t        | j                        ry	 t        t        |              y# t        $ r Y yw xY w)NTF)r[   rs   rJ   r   r   r$   s    r&   __bool__z_regen.__bool__   s;    t	d   		s   - 	99c                     | j                   s,| j                  j                  | j                         d| _         | j                  S r1   )rt   rs   extendrr   r$   s    r&   rw   z_regen.data	  s0    {{OO""499-DKr(   c                     dj                  | j                  j                  dj                  d | j                  D              | j
                  sd      S d      S )Nz<{}: [{}{}]>, c              3   2   K   | ]  }t        |        y wr"   )repr)rF   es     r&   rI   z"_regen.__repr__.<locals>.<genexpr>  s     7!d1g7   z... )formatr6   r,   joinrs   rt   r$   s    r&   __repr__z_regen.__repr__  sP    $$NN##II7t77E
 	
 +-
 	
r(   r"   )r,   r-   r.   ru   rx   rz   r~   r   r   r   r   propertyrw   r   r#   r(   r&   ro   ro      sC    ")+4.&	  
r(   ro   c                    | j                   r~t        | j                         }|r't        t        t        | j                                     n| j                   }| j                  d |  }t        t        | j                  | d  |            }n| j                  g }}| j                  }| j                  }| j                  rt        | j                        t        | j                  j                               z
  }|r8t        | j                  j                               D 	
cg c]	  \  }	}
|
|	f }}	}
n2t        | j                  j                               }n| j                  g }}dj                  t        d dj                  |      dj                  d |D              |rd| nd |s|r|sdnd |rdj                  |      nd dj                  d |D              |rd| g            S d g            S c c}
}	w )Nr   c              3   0   K   | ]  \  }}| d |   yw)=Nr#   rF   krG   s      r&   rI   z _argsfromspec.<locals>.<genexpr>1  s     2AQCq*2s   *c              3   2   K   | ]  \  }}| d | d  yw)z=""Nr#   r   s      r&   rI   z _argsfromspec.<locals>.<genexpr>5  s      ?41aQCr!A,?r   z**)defaultsr[   rW   ranger:   zipvarargsvarkwkwonlydefaultsrh   
kwonlyargskeys	enumerateitemsr   filter)specreplace_defaultssplitr   
positionaloptionalr   r   r   ikwkwonlyargs_optionals               r&   _argsfromspecr     s   }}DMM"7GDs4==123 	YYw'
DIIufg.9:#yy"H
llGJJE)C0C0C0H0H0J,KK
%.t/B/B/G/G/I%J#!ArQ# # #'t':':'@'@'B"C*.//2'
99VD		*		222 !G9d17!+		*		?+>??"UG#    $(#   #s   G1fun.boundreturnc                    t        j                  |       }t        |       }| j                  j                  dk(  }t        j
                  |       }|s)|r'|s%|s#| j                  j                  | j                  } }n| j                  }t        j                  |t        t        j                  |             d      }t        j                  |       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MM**CLLc||!((w55c:; ) J
 LLS^^,I 	Yt_FFNvvx((Mr(   c                 x    t        j                  |       }|j                  xs t        |j                        |kD  S r"   )r   r   r   r[   r:   )r   rX   argspecs      r&   arity_greaterr   [  s/    $$S)G??3c',,/!33r(   c                     t        j                  |      }|j                  xs6 |j                  xs( |rt	        |j
                        |k\  S | |j
                  v S r"   )r   r   r   r   r[   r:   )r   r   positionr   s       r&   fun_takes_argumentr   `  sS    !!#&D

 	Hdll 	H'/TYY8	#59TYY5Fr(   c                 |    t        d t        j                  |       j                  j	                         D              S )z<Return true if function accepts arbitrary keyword arguments.c              3   R   K   | ]  }|j                   |j                  k(  r| ! y wr"   )kindVAR_KEYWORD)rF   ps     r&   rI   z%fun_accepts_kwargs.<locals>.<genexpr>j  s(      66Q]]" 	
s   %')anyr   	signature
parametersvalues)r   s    r&   r   r   h  s6     $$S)44;;=  r(   c                     | | |      S |S )z$Call typ on value if val is defined.r#   )typvals     r&   r   r   p  s    3s8/C/r(   c                 :    t        | t              r| |fz   S | |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@   rn   )seqrY   s     r&   seq_concat_itemr   u  s$     'sE23$=D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@   )rj   rk   prefers      r&   seq_concat_seqr     sH     #q!f#&'Fa 1Ia 1Iq5Lr(   c                 T    t        | t        t        f      xr t        | t               S r"   )r@   intfloatbool)rB   s    r&   is_numeric_valuer     s"    ec5\*J:eT3J/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   rl   r   rW   ro   r   r   strr   r   r   r   r   r   r   r   r#   r(   r&   <module>r      s    !     . .   k k k  '	H	  D $

2/2H JC
	T
Xt T
nDxS) $ 3 B4
0
E$Kr(   