o
    ?Zc                     @   s  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 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 zddlmZ W n eyM   dZY nw dZeeZdZedjedZeedZeddZee	fddZeG dd dZ G dd dZ!dS )z"Timer scheduling Python callbacks.    N)
namedtuple)datetime)total_ordering)	monotonic)time)proxy)wraps)
get_logger)utc)EntryTimerto_timestamp   tzinfo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.
    Nr   r   )
isinstancer   r   replace_timemaxEPOCHtotal_seconds)ddefault_timezoner   diff r   N/var/www/chikooza/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__7   s   



zEntry.__init__c                 C   s   | j | ji | jS N)r!   r"   r#   r)   r   r   r    __call__?   s   zEntry.__call__c                 C   s$   zd| j _W d S  ty   Y d S w NT)r$   r%   ReferenceErrorr,   r   r   r    cancelB   s
   zEntry.cancelc                 C   s   d | jj| j| jS )Nz<TimerEntry: {}(*{!r}, **{!r}))formatr!   __name__r"   r#   r,   r   r   r    __repr__H   s   zEntry.__repr__c                 C   s   t | t |k S r+   )id)r)   otherr   r   r    __lt__M   s   zEntry.__lt__c                 C   s   | j S r+   r%   r,   r   r   r    	cancelledP   s   zEntry.cancelledc                 C   s
   || _ d S r+   r7   )r)   valuer   r   r    r8   T   s   
NN)r2   
__module____qualname____doc__IS_PYPY	__slots__r*   r-   r0   r3   r6   propertyr8   setterr   r   r   r    r   -   s    

r   c                   @   s   e Zd ZdZeZdZd+ddZdd Zdd Zd,ddZ	d,ddZ
d,d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'd(Zed)d* ZdS )-r   zAsync timer implementation.Nc                 K   s$   t |pt| _|p| j| _g | _d S r+   )floatDEFAULT_MAX_INTERVALmax_intervalon_error_queue)r)   rD   rE   r#   r   r   r    r*   `   s   
zTimer.__init__c                 C      | S r+   r   r,   r   r   r    	__enter__e      zTimer.__enter__c                 G   s   |    d S r+   )stopr)   exc_infor   r   r    __exit__h      zTimer.__exit__r   r   c                 C   s$   |si n|}|  | |||||S r+   )enter_atr   )r)   r   r!   r"   r#   r   r   r   r    call_atk      zTimer.call_atc                 C   s$   |si n|}|  || ||||S r+   )enter_afterr   )r)   secsr!   r"   r#   r   r   r   r    
call_aftero   rQ   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 r+   )r&   r   r%   rR   )r"   r#   lastnowlsincenextr!   r   rS   r)   r$   r   r    _reschedulesw   s*    
z+Timer.call_repeatedly.<locals>._reschedules)r   r   r!   r&   rR   )r)   rS   r!   r"   r#   r   rZ   r   rY   r    call_repeatedlys   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 )zEnter 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    rO      s   

zTimer.enter_atc                 C   s   |  || t| |S r+   )rO   rB   )r)   rS   r   r   r   r   r   r    rR      s   zTimer.enter_afterc                 C   s   || j t||| |S r+   )rF   r   )r)   r   r   r   pushr   r   r    r^      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)rL   )r\   r]   loggererror)r)   r   r_   r   r   r    apply_entry   s   
zTimer.apply_entryc                 C   s   | j r
|  | dS d S r.   )rE   rK   r   r   r    r]      s   
zTimer.handle_errorc                 C   s   d S r+   r   r,   r   r   r    rJ      rI   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)zIterate 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:   )rD   rF   r%   )r)   minnowfunpopr`   rD   queueeventArV   r   eventBr   r   r   r    __iter__   s$   
zTimer.__iter__c                 C   s   g | j d d < d S r+   )rF   r,   r   r   r    clear   s   zTimer.clearc                 C   s   |   d S r+   )r0   )r)   r$   r   r   r    r0      rN   zTimer.cancelc                 C   s
   t | jS r+   )lenrF   r,   r   r   r    __len__   s   
zTimer.__len__c                 C   s   dS r.   r   r,   r   r   r    __nonzero__   rI   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>)listrF   rm   )r)   rs   eventsr   rr   r    rh      s   
zTimer.queuec                 C   rG   r+   r   r,   r   r   r    schedule   s   zTimer.scheduler:   )r   Nr   )r2   r;   r<   r=   r   rE   r*   rH   rM   rP   rT   r[   r   rO   rR   heapqheappushr^   rc   r]   rJ   re   heappoprk   rl   r0   rn   ro   r@   rh   rw   r   r   r   r    r   Y   s6    




r   )"r=   rx   syscollectionsr   r   	functoolsr   r   r   r   weakrefr   r(   
vine.utilsr   	kombu.logr	   pytzr
   ImportError__all__r2   ra   rC   utcfromtimestampr   r   hasattrr>   r   r   r   r   r   r   r   r    <module>   s4    

+