o
    —¨Êh
  ã                   @  s*  d Z ddlmZ ddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddl
m
Z dd	lmZ dd
lmZ ddlmZ ddlmZ ejdkrRddlmZ nddlmZ er`ddlmZ dZeeƒZdZe  dedƒ¡Z!e"edƒZ#eddƒZ$edƒefdd„Z%e	G dd„ dƒƒZ&G dd„ dƒZ'dS )z"Timer scheduling Python callbacks.é    )ÚannotationsN)Ú
namedtuple)Údatetime)Útotal_ordering)Ú	monotonic)Útime)ÚTYPE_CHECKING)Úproxy)Úwraps)Ú
get_logger)é   é	   )ÚZoneInfo)ÚTracebackType)ÚEntryÚTimerÚto_timestampé   ÚUTCÚpypy_version_infoÚ	scheduled)ÚetaÚpriorityÚentryc                 C  sF   t | tƒr!| jdu r| j|d�} tƒ |ƒ  }t| t  ¡ | dƒS | S )z^Convert datetime to timestamp.

    If d' is already a timestamp, then that will be used.
    N)Útzinfor   )Ú
isinstancer   r   ÚreplaceÚ_timeÚmaxÚEPOCHÚtotal_seconds)ÚdÚdefault_timezoner   Údiff© r$   úJ/var/www/html/env/lib/python3.10/site-packages/kombu/asynchronous/timer.pyr   &   s   

r   c                   @  s\   e Zd ZdZes
dZddd„Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
edd„ ƒZejdd„ ƒZdS )r   zSchedule Entry.)ÚfunÚargsÚkwargsÚtrefÚcanceledÚ	_last_runÚ__weakref__Nc                 C  s4   || _ |pg | _|pi | _t| ƒ| _d | _d| _d S )NF)r&   r'   r(   Úweakrefproxyr)   r+   r*   )Úselfr&   r'   r(   r$   r$   r%   Ú__init__=   s   



zEntry.__init__c                 C  s   | j | ji | j¤ŽS ©N)r&   r'   r(   ©r.   r$   r$   r%   Ú__call__E   s   zEntry.__call__c                 C  s$   zd| j _W d S  ty   Y d S w ©NT)r)   r*   ÚReferenceErrorr1   r$   r$   r%   ÚcancelH   s
   ÿzEntry.cancelc                 C  s   d  | jj| j| j¡S )Nz<TimerEntry: {}(*{!r}, **{!r}))Úformatr&   Ú__name__r'   r(   r1   r$   r$   r%   Ú__repr__N   s   ÿzEntry.__repr__c                 C  s   t | ƒt |ƒk S r0   )Úid)r.   Úotherr$   r$   r%   Ú__lt__S   s   zEntry.__lt__c                 C  s   | j S r0   ©r*   r1   r$   r$   r%   Ú	cancelledV   s   zEntry.cancelledc                 C  s
   || _ d S r0   r<   )r.   Úvaluer$   r$   r%   r=   Z   s   
©NN)r7   Ú
__module__Ú__qualname__Ú__doc__ÚIS_PYPYÚ	__slots__r/   r2   r5   r8   r;   Úpropertyr=   Úsetterr$   r$   r$   r%   r   3   s    

r   c                   @  sê   e Zd ZdZeZdZd3dd„Zdd„ Zd4dd„Zd5dd„Z	d5dd„Z
d5dd„Zddefdd„Zdefdd„Zejfdd„Zdd „ Zd!d"„ Zd#d$„ Zeeejejfd%d&„Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zeejfd/d0„ƒZed1d2„ ƒZdS )6r   zAsync timer implementation.Nc                 K  s$   t |ptƒ| _|p| j| _g | _d S r0   )ÚfloatÚDEFAULT_MAX_INTERVALÚmax_intervalÚon_errorÚ_queue)r.   rI   rJ   r(   r$   r$   r%   r/   f   s   
zTimer.__init__c                 C  ó   | S r0   r$   r1   r$   r$   r%   Ú	__enter__k   ó   zTimer.__enter__Úexc_typeútype[BaseException] | NoneÚexc_valúBaseException | NoneÚexc_tbúTracebackType | NoneÚreturnÚNonec                 C  s   |   ¡  d S r0   )Ústop)r.   rO   rQ   rS   r$   r$   r%   Ú__exit__n   s   zTimer.__exit__r$   r   c                 C  s$   |si n|}|   |  |||¡||¡S r0   )Úenter_atr   )r.   r   r&   r'   r(   r   r$   r$   r%   Úcall_atv   ó   zTimer.call_atc                 C  s$   |si n|}|   ||  |||¡|¡S r0   )Úenter_afterr   )r.   Úsecsr&   r'   r(   r   r$   r$   r%   Ú
call_afterz   r[   zTimer.call_afterc                   sP   |si n|}ˆ  ˆ ||¡‰tˆ ƒ‡ ‡‡‡‡fdd„ƒ}|ˆ_d ˆ_ˆ ˆˆˆ¡S )Nc                    sÞ   ˆj tƒ }}|r|ˆj  nˆ}zE|r:|ˆkr:|ˆ_ ˆ | i |¤ŽW ˆjs9ˆj }|r/ˆ||  nˆ}ˆ |ˆˆ¡ S S W ˆjsTˆj }|rIˆ||  nˆ}ˆ |ˆˆ¡ d S d S ˆjsnˆj }|rdˆ||  nˆ}ˆ |ˆˆ¡ w w r0   )r+   r   r*   r\   )r'   r(   ÚlastÚnowÚlsinceÚnext©r&   r   r]   r.   r)   r$   r%   Ú_reschedules‚   s*   ý€ 
ýýz+Timer.call_repeatedly.<locals>._reschedules)r   r
   r&   r+   r\   )r.   r]   r&   r'   r(   r   rd   r$   rc   r%   Úcall_repeatedly~   s   zTimer.call_repeatedlyc              
   C  sf   |du r|ƒ }t |tƒr,zt|ƒ}W n ty+ } z|  |¡s ‚ W Y d}~dS d}~ww |  |||¡S )zîEnter function into the scheduler.

        Arguments:
        ---------
            entry (~kombu.asynchronous.timer.Entry): Item to enter.
            eta (datetime.datetime): Scheduled time.
            priority (int): Unused.
        N)r   r   r   Ú	ExceptionÚhandle_errorÚ_enter)r.   r   r   r   r   Úexcr$   r$   r%   rY   ”   s   	

€ýzTimer.enter_atc                 C  s   |   ||ƒ t|ƒ |¡S r0   )rY   rG   )r.   r]   r   r   r   r$   r$   r%   r\   ¨   s   zTimer.enter_afterc                 C  s   || j t|||ƒƒ |S r0   )rK   r   )r.   r   r   r   Úpushr$   r$   r%   rh   «   s   zTimer._enterc              
   C  s\   z|ƒ  W d S  t y- } z|  |¡s"tjd|dd� W Y d }~d S W Y d }~d S d }~ww )NzError in timer: %rT)Úexc_info)rf   rg   ÚloggerÚerror)r.   r   ri   r$   r$   r%   Úapply_entry¯   s   
ÿ€ÿzTimer.apply_entryc                 C  s   | j r
|   |¡ dS d S r3   )rJ   )r.   rk   r$   r$   r%   rg   ¶   s   
þzTimer.handle_errorc                 C  s   d S r0   r$   r1   r$   r$   r%   rW   »   rN   z
Timer.stopc                 c  sˆ   � | j }| j}	 |r@|d }|ƒ |d }}	||	k r%||	| |ƒdfV  n||ƒ}
|
|u r:|d }|js9d|fV  q|||
ƒ ndV  q)zâIterate over schedule.

        This iterator yields a tuple of ``(wait_seconds, entry)``,
        where if entry is :const:`None` the caller should wait
        for ``wait_seconds`` until it polls the schedule again.
        é   r   Nr   r?   )rI   rK   r*   )r.   ÚminÚnowfunÚpoprj   rI   ÚqueueÚeventAr`   r   ÚeventBr   r$   r$   r%   Ú__iter__¾   s$   €
îzTimer.__iter__c                 C  s   g | j d d …< d S r0   )rK   r1   r$   r$   r%   ÚclearÝ   s   zTimer.clearc                 C  s   |  ¡  d S r0   )r5   )r.   r)   r$   r$   r%   r5   à   s   zTimer.cancelc                 C  s
   t | jƒS r0   )ÚlenrK   r1   r$   r$   r%   Ú__len__ã   s   
zTimer.__len__c                 C  s   dS r3   r$   r1   r$   r$   r%   Ú__nonzero__æ   rN   zTimer.__nonzero__c                   s&   t | jƒ}‡ fdd„|gt|ƒ D ƒS )z%Snapshot of underlying datastructure.c                   s   g | ]}ˆ |ƒ‘qS r$   r$   )Ú.0Úv©Ú_popr$   r%   Ú
<listcomp>í   s    zTimer.queue.<locals>.<listcomp>)ÚlistrK   rx   )r.   r~   Úeventsr$   r}   r%   rs   é   s   
zTimer.queuec                 C  rL   r0   r$   r1   r$   r$   r%   Úscheduleï   s   zTimer.scheduler?   )rO   rP   rQ   rR   rS   rT   rU   rV   )r$   Nr   )r7   r@   rA   rB   r   rJ   r/   rM   rX   rZ   r^   re   r   rY   r\   ÚheapqÚheappushrh   rn   rg   rW   rp   Úheappoprv   rw   r5   ry   rz   rE   rs   r‚   r$   r$   r$   r%   r   _   s6    





ÿr   )(rB   Ú
__future__r   rƒ   ÚsysÚcollectionsr   r   Ú	functoolsr   r   r   r   Útypingr   Úweakrefr	   r-   Ú
vine.utilsr
   Ú	kombu.logr   Úversion_infoÚzoneinfor   Úbackports.zoneinfoÚtypesr   Ú__all__r7   rl   rH   Úfromtimestampr   ÚhasattrrC   r   r   r   r   r$   r$   r$   r%   Ú<module>   s8    


+