o
    wvXjÕ)  ã                   @   st  d Z ddlmZmZmZ ddlZddlZddl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mZmZ d	Zd
ZG dd„ deƒZG dd„ deƒZdd„ Zdd„ Z dd„ Z!dd„ Z"d9dd„Z#dd„ Z$d9dd„Z%dd„ Z&dd „ Z'd!d"„ Z(G d#d$„ d$ee)ƒZ*d:d&d'„Z+d;d)d*„Z,d+d,„ Z-d9d-d.„Z.e/ed/ƒr¨d0d1„ Z0nd2d1„ Z0d3d4„ Z1d5d6„ Z2d7d8„ Z3dS )<zFunctional-style utilties.é    )Úabsolute_importÚprint_functionÚunicode_literalsN)Úpartial)ÚchainÚislice)ÚLRUCacheÚ
dictfilterÚis_listÚlazyÚmaybe_evaluateÚ
maybe_listÚmemoize)Úpromise)ÚUserListÚgetfullargspecÚrange)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                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚDummyContextc                 C   ó   | S ©N© ©Úselfr"   r"   úT/var/www/html/myproject/venv/lib/python3.10/site-packages/celery/utils/functional.pyÚ	__enter__   ó   zDummyContext.__enter__c                 G   s   d S r!   r"   )r$   Úexc_infor"   r"   r%   Ú__exit__"   r'   zDummyContext.__exit__N)Ú__name__Ú
__module__Ú__qualname__r&   r)   r"   r"   r"   r%   r      s    r   c                       s(   e Zd ZdZdZdZ‡ fdd„Z‡  ZS )r   z€Memoized lazy evaluation.

    The function is only evaluated once, every subsequent access
    will return the same value.
    FNc                    s"   | j stt| ƒ ¡ | _d| _ | jS )NT)Ú	evaluatedÚsuperr   ÚevaluateÚ_valuer#   ©Ú	__class__r"   r%   r/   1   s   zmlazy.evaluate)r*   r+   r,   Ú__doc__r-   r0   r/   Ú__classcell__r"   r"   r1   r%   r   &   s
    r   c                  O   s   dS )zONo operation.

    Takes any arguments/keyword arguments and does nothing.
    Nr"   )ÚargsÚkwargsr"   r"   r%   r   8   s    r   c                 O   r    )z%Return the first positional argument.r"   )Úargr5   r6   r"   r"   r%   Úpass1?   s   r8   c                 c   s&   � | D ]}t |tƒr|ƒ }|V  qd S r!   )Ú
isinstancer   )ÚitÚvaluer"   r"   r%   Úevaluate_promisesD   s   €
ýr<   c                    s   t ‡ fdd„t|ƒD ƒdƒS )z�Return 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   s.   � | ]}ˆ d urˆ |ƒrn|d ur|V  qd S r!   r"   )Ú.0Úv©Ú	predicater"   r%   Ú	<genexpr>R   s   € ÿÿzfirst.<locals>.<genexpr>N)Únextr<   )r@   r:   r"   r?   r%   r   K   s   ýr   c                    s   ‡ ‡fdd„}|S )zîMultiple 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              	      sl   | D ]1}zt t|ƒˆ ƒ}ˆrˆ|g|¢R i |¤Žn||i |¤Ž}W n	 ty*   Y qw |d ur3|  S qd S r!   )Úgetattrr   ÚAttributeError)r:   r5   r6   ÚobjÚmethÚreply©ÚmethodÚon_callr"   r%   Ú_matchera   s   ÿÿÿøzfirstmethod.<locals>._matcherr"   )rI   rJ   rK   r"   rH   r%   r   X   s   	r   c                 c   s*   � | D ]}|gt t| |d ƒƒ V  q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Úitemr"   r"   r%   r   o   s   €ÿr   c                 C   s"   t | ƒd|… |g|t| ƒ   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)rM   Úlen)Ú	containerÚsizeÚdefaultr"   r"   r%   r   ˆ   s   "r   c                     s   ‡ fdd„S )z²Get attributes, ignoring attribute errors.

    Like :func:`operator.itemgetter` but return :const:`None` on missing
    attributes instead of raising :exc:`AttributeError`.
    c                    s   ‡ fdd„ˆD ƒS )Nc                    s   i | ]	}|t ˆ |d ƒ“qS r!   )rC   )r=   Úattr©rE   r"   r%   Ú
<dictcomp>ž   s    z1mattrgetter.<locals>.<lambda>.<locals>.<dictcomp>r"   rU   ©ÚattrsrU   r%   Ú<lambda>ž   s    zmattrgetter.<locals>.<lambda>r"   rW   r"   rW   r%   r   ˜   s   r   c                    s   t ƒ ‰ ‡ fdd„| D ƒS )z7Return all unique elements in ``it``, preserving order.c                 3   s&   � | ]}|ˆ vrˆ   |¡p|V  qd S r!   )Úadd)r=   rE   ©Úseenr"   r%   rA   ¤   s   €$ zuniq.<locals>.<genexpr>)Úset©r:   r"   r[   r%   r   ¡   s   r   c                 C   s   t | ttfƒr	| S t| ƒS )zþConvert 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.
    )r9   rM   ÚtupleÚ_regenr^   r"   r"   r%   r   §   s   r   c                   @   s@   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zedd„ ƒZ	dS )r`   c                 C   s   || _ d| _g | _d S )Nr   )Ú
_regen__itÚ_regen__indexÚ_regen__consumed)r$   r:   r"   r"   r%   Ú__init__¶   s   
z_regen.__init__c                 C   s   t | jffS r!   )rM   Údatar#   r"   r"   r%   Ú
__reduce__¾   s   z_regen.__reduce__c                 C   s
   | j  ¡ S r!   )ra   Ú__length_hint__r#   r"   r"   r%   rg   Á   s   
z_regen.__length_hint__c                 C   s   t | j| jƒS r!   )r   rc   ra   r#   r"   r"   r%   Ú__iter__Ä   s   z_regen.__iter__c                 C   s€   |dk r	| j | S z| j| W S  ty?   zt| j|d ƒD ]}| j t| jƒ¡ qW n ty7   t|ƒ‚w | j|  Y S w )Nr   rL   )	re   rc   Ú
IndexErrorr   rb   ÚappendrB   ra   ÚStopIteration)r$   ÚindexÚ_r"   r"   r%   Ú__getitem__Ç   s   
ÿÿùz_regen.__getitem__c                 C   s2   z| j  t| jƒ¡ W | j S  ty   Y | j S w r!   )rc   ÚextendrM   ra   rk   r#   r"   r"   r%   re   Õ   s   þþz_regen.dataN)
r*   r+   r,   rd   rf   rg   rh   rn   Úpropertyre   r"   r"   r"   r%   r`   ³   s    r`   Tc           
      C   sT  | j r,t| j ƒ}|rttt| j ƒƒƒn| j }| jd | … }tt| j| d … |ƒƒ}n| jg }}| j}| j}| jrbt| jƒ}| j	d | … }|rZdd„ t
| j	| d … ƒD ƒ}	nt| j ¡ ƒ}	n| j	g }}	d td d |¡d dd„ |D ƒ¡|r€d |¡nd |s…|	r‰|s‰dnd |r‘d |¡nd d dd„ |	D ƒ¡|r¥d	 |¡gƒ¡S d gƒ¡S )
Nc                 S   s   g | ]\}}||f‘qS r"   r"   )r=   ÚiÚkwr"   r"   r%   Ú
<listcomp>î   s    ÿz!_argsfromspec.<locals>.<listcomp>z, c                 s   ó    � | ]\}}d   ||¡V  qdS )z{0}={1}N©Úformat©r=   Úkr>   r"   r"   r%   rA   ÷   ó   € z _argsfromspec.<locals>.<genexpr>z*{0}Ú*c                 s   rt   )z	{0}="{1}"Nru   rw   r"   r"   r%   rA   û   ry   z**{0})ÚdefaultsrP   rM   r   r5   ÚzipÚvarargsÚvarkwÚkwonlydefaultsÚ
kwonlyargsÚ	enumerateÚitemsÚjoinÚfilterrv   )
ÚspecÚreplace_defaultsÚsplitr{   Ú
positionalÚoptionalr}   r~   r€   Úkwonlyargs_optionalr"   r"   r%   Ú_argsfromspecÞ   s<   
ÿ
ÿùùr‹   Fc                 C   s²   t  | ¡}t| dƒ}| jjdk}t  | ¡}|s&|r&|s&|s&| jj| j}} n| j}tj|t	t
| ƒƒdd�}|r>t|tjd� d| ji}	t||	ƒ |	| }
||
_|rWt|
tƒ ƒS |
S )z1Generate signature function from actual function.Ú__call__Úcython_function_or_methodrL   )Úfun_nameÚfun_argsÚ	fun_value)Úfiler*   )ÚinspectÚ
isfunctionÚhasattrr2   r*   ÚismethodrŒ   ÚFUNHEAD_TEMPLATErv   r‹   r   ÚprintÚsysÚstderrr+   ÚexecÚ_sourcer   Úobject)ÚfunÚboundÚdebugÚis_functionÚis_callableÚ	is_cythonÚ	is_methodÚnameÚ
definitionÚ	namespaceÚresultr"   r"   r%   r      s*   



ý

r   c                 C   s   t | ƒ}|jpt|jƒ|kS r!   )r   r}   rP   r5   )r�   rN   Úargspecr"   r"   r%   Úarity_greater"  s   r©   c                 C   s0   t |ƒ}|jp|jp|rt|jƒ|kS | |jv S r!   )r   r~   r}   rP   r5   )r¤   r�   Úpositionr…   r"   r"   r%   Úfun_takes_argument'  s   þþr«   Ú	signaturec                 C   s   t dd„ t | ¡j ¡ D ƒƒS )ú<Return true if function accepts arbitrary keyword arguments.c                 s   s    � | ]}|j |jkr|V  qd S r!   )ÚkindÚVAR_KEYWORD)r=   Úpr"   r"   r%   rA   2  s   € ÿþz%fun_accepts_kwargs.<locals>.<genexpr>)Úanyr’   r¬   Ú
parametersÚvalues)r�   r"   r"   r%   r   0  s   ÿr   c                 C   s`   zt  | ¡}W n ty&   zt  | j¡}W n ttfy#   Y Y dS w Y nw | p/|d duS )r­   Né   )r’   Ú
getargspecÚ	TypeErrorrŒ   rD   )r�   r¨   r"   r"   r%   r   7  s   ÿÿþc                 C   s   |dur| |ƒS |S )z$Call typ on value if val is defined.Nr"   )ÚtypÚvalr"   r"   r%   r   C  s   r   c                 C   s   t | tƒr
| |f S | |g S )zÆReturn 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__``.
    )r9   r_   )ÚseqrO   r"   r"   r%   Úseq_concat_itemH  s   rº   c                 C   s@   t t| |gtd�ƒ}t| |ƒs|| ƒ} t||ƒs||ƒ}| | 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ÚmaxrP   r9   )ÚaÚbÚpreferr"   r"   r%   Úseq_concat_seqR  s   	

rÁ   r!   )T)FF)4r3   Ú
__future__r   r   r   r’   r˜   Ú	functoolsr   Ú	itertoolsr   r   Úkombu.utils.functionalr   r	   r
   r   r   r   r   Úviner   Úcelery.fiver   r   r   Ú__all__r–   rœ   r   r   r   r8   r<   r   r   r   r   r   r   r   rM   r`   r‹   r   r©   r«   r”   r   r   rº   rÁ   r"   r"   r"   r%   Ú<module>   sD   $	

	
+
""



