
     h-                     N   d Z ddl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mZmZmZmZmZ ddlm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Z'd Z(d%d Z)d! Z*d" Z+d# Z,d$ Z-dS )(zFunctional-style utilities.    N)UserList)partial)isliceteezip_longest)LRUCache
dictfilteris_listlazymaybe_evaluate
maybe_listmemoize)promise)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    S/var/www/html/Sam_Eipo/venv/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#   r1   zmlazy.evaluate-   s3    ~ 	"''**,,DK!DN{r%   )r)   r*   r+   __doc__r/   r2   r1   __classcell__)r3   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   4   s      r%   c                     | S )z%Return the first positional argument.r    )argr7   r8   s      r#   pass1r;   ;   s    Jr%   c              #   Z   K   | D ]%}t          |t                    r
 |            }|V  &d S r   )
isinstancer   )itvalues     r#   evaluate_promisesr@   @   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>N   sI       	G 	Gq%1IIaLL11q} 
7D}}}	G 	Gr%   N)nextr@   )rE   r>   s   ` r#   r   r   G   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)r>   r7   r8   objmethreplymethodon_calls         r#   _matcherzfirstmethod.<locals>._matcher^   s     		! 		!C!~c22F;;;B 47777777"dD3F33 
 $ LLL % "   		! 		!s   3A
AAr    )rO   rP   rQ   s   `` r#   r   r   T   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   )r>   nitems      r#   r   r   m   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)rT   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   )rJ   )rC   attrrL   s     r#   
<dictcomp>z1mattrgetter.<locals>.<lambda>.<locals>.<dictcomp>   s'    III4gc466IIIr%   r    )rL   attrss   `r#   <lambda>zmattrgetter.<locals>.<lambda>   s    IIII5III r%   r    )ra   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)rC   rL   seens     r#   rF   zuniq.<locals>.<genexpr>   s6      BBS#T//DHHSMM S////BBr%   )set)r>   rf   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   rG   r   )r>   abs      r#   	lookaheadrk      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=   rT   tuple_regen)r>   s    r#   r   r      s+     "tUm$$ 	"::r%   c                   V    e 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 )rn   c                 0    || _         g | _        d| _        d S )NF)
_regen__it_regen__consumed_regen__done)r"   r>   s     r#   __init__z_regen.__init__   s     	r%   c                      t           | j        ffS r   )rT   datar!   s    r#   
__reduce__z_regen.__reduce__   s    di\!!r%   c                 4    | j                                         S r   )rq   __length_hint__r!   s    r#   ry   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   TrS   )rs   iterrq   rG   StopIterationrr   append)r"   limitr>   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   )rr   _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   rS   )r~   )rv   rX   rr   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)rX   rr   rG   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 r.   )rs   rr   extendrq   r!   s    r#   rv   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)rC   es     r#   rF   z"_regen.__repr__.<locals>.<genexpr>  s(      77!d1gg777777r%   z... )formatr3   r)   joinrr   rs   r!   s    r#   __repr__z_regen.__repr__	  sP    $$N#II77t77777,EE"
 
 	
r%   r   )r)   r*   r+   rt   rw   ry   r   r   r   r   propertyrv   r   r    r%   r#   rn   rn      s          " " "+ + +   4. . .& & &	 	 	   X
 
 
 
 
r%   rn   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    )rC   ikws      r#   
<listcomp>z!_argsfromspec.<locals>.<listcomp>   s-     # # #!ArQ# # #r%   r   c              3   *   K   | ]\  }}| d | V  dS )=Nr    rC   krD   s      r#   rF   z _argsfromspec.<locals>.<genexpr>*  s0      22AQ****222222r%   *c              3   ,   K   | ]\  }}| d | dV  dS )z=""Nr    r   s      r#   rF   z _argsfromspec.<locals>.<genexpr>.  s2      ??41aQ,,!,,,??????r%   z**)defaultsrX   rT   ranger7   zipvarargsvarkwkwonlydefaultsrg   
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%   Fc                    t          j        |           }t          | d          }| j        j        dk    }t          j        |           }|s|r|s|s| j        j        | j        } }n| j        }t                              |t          t          j
        |                     d          }|rt          |t          j                   d| j        i}	t          ||	           |	|         }
||
_        |rt#          |
t%                                S |
S )z1Generate signature function from actual function.__call__cython_function_or_methodrS   )fun_namefun_args	fun_value)filer)   )inspect
isfunctionhasattrr3   r)   ismethodr   FUNHEAD_TEMPLATEr   r   getfullargspecprintsysstderrr*   exec_sourcer   object)funbounddebugis_functionis_callable	is_cython	is_methodname
definition	namespaceresults              r#   r   r   3  s    $S))K#z**K&*EEI %%I ; y  M*CLc|!((w5c::;; )  J
  +jsz****S^,I 	Yt_FFN )vvxx(((Mr%   c                 h    t          j        |           }|j        pt          |j                  |k    S r   )r   r   r   rX   r7   )r   rU   argspecs      r#   arity_greaterr   U  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   rX   r7   )r   r   positionr   s       r#   fun_takes_argumentr   Z  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)rC   ps     r#   rF   z%fun_accepts_kwargs.<locals>.<genexpr>d  s=        6Q]"" 	
"""" r%   )anyr   	signature
parametersvalues)r   s    r#   r   r   b  sJ      $S))4;;==     r%   c                      | | |          n|S )z$Call typ on value if val is defined.r    )typvals     r#   r   r   j  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=   rm   )seqrV   s     r#   seq_concat_itemr   o  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maxrX   r=   )ri   rj   prefers      r#   seq_concat_seqr   y  si     #q!f#&&&''Fa   F1IIa   F1IIq5Lr%   r   )T)FF).r4   r   r   collectionsr   	functoolsr   	itertoolsr   r   r   kombu.utils.functionalr   r	   r
   r   r   r   r   viner   __all__r   r   r   r   r;   r@   r   r   r   r   r   r   rk   r   rT   rn   r   r   r   r   r   r   r   r   r    r%   r#   <module>r      s   ! !  



                   . . . . . . . . . .I I I I I I I I I I I I I I I I I I                  D   $    
  
 
 
   2/ / /2H H H H J J JC C C
 
 
	 	 	P
 P
 P
 P
 P
Xt P
 P
 P
f   D   D4 4 4
     0 0 0
E E E    r%   