3
Z_ð]{  ã               @   sL   d dl Z d dlZd dlmZ d dlZdZG dd„ deƒZ	G dd„ de	ƒZ
dS )é    N)Ú	greenletsFc               @   sP   e Zd Zdd„ Zedd„ ƒZdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚTimerc             O   s8   || _ |||f| _d| _tr4tjƒ | _tj| jd� dS )a�  Create a timer.
            seconds: The minimum number of seconds to wait before calling
            cb: The callback to call when the timer has expired
            *args: The arguments to pass to cb
            **kw: The keyword arguments to pass to cb

        This timer will not be run unless it is scheduled in a runloop by
        calling timer.schedule() or runloop.add_timer(timer).
        F)ÚfileN)ÚsecondsÚtplÚcalledÚ_g_debugÚsixÚStringIOÚ	tracebackÚprint_stack)Úselfr   ÚcbÚargsÚkw© r   ú7/tmp/pip-build-yz_zf6az/eventlet/eventlet/hubs/timer.pyÚ__init__   s    

zTimer.__init__c             C   s   | j  S )N)r   )r   r   r   r   Úpending   s    zTimer.pendingc             C   sR   t | dd ƒ}t | ddƒ\}}}d||||f }trNt| dƒrN|d| jjƒ  7 }|S )Nr   r   zTimer(%s, %s, *%s, **%s)r   Ú
)NNN)Úgetattrr   Úhasattrr   Úgetvalue)r   Zsecsr   r   r   Úretvalr   r   r   Ú__repr__"   s    zTimer.__repr__c             C   s"   | j \}}}| j| j|f|ž|ŽS )N)r   Ú	__class__r   )r   r   r   r   r   r   r   Úcopy+   s    z
Timer.copyc             C   s   d| _ tjjƒ j| ƒ| _| S )z;Schedule this timer to run in the current runloop.
        F)r   ÚeventletÚhubsÚget_hubZ	add_timerZscheduled_time)r   r   r   r   Úschedule/   s    zTimer.schedulec             G   sL   | j sHd| _ | j\}}}z|||Ž W d y| `W n tk
rD   Y nX X d S )NT)r   r   ÚAttributeError)r   r   r   r   r   r   r   Ú__call__6   s    zTimer.__call__c             C   s>   | j s:d| _ tjjƒ j| ƒ y| `W n tk
r8   Y nX dS )zwPrevent this timer from being called. If the timer has already
        been called or canceled, has no effect.
        TN)r   r   r   r   Ztimer_canceledr   r!   )r   r   r   r   ÚcancelB   s    zTimer.cancelc             C   s   t | ƒt |ƒk S )N)Úid)r   Úotherr   r   r   Ú__lt__P   s    zTimer.__lt__N)Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr   r   r   r    r"   r#   r&   r   r   r   r   r      s   	r   c               @   s0   e Zd Zdd„ Zedd„ ƒZdd„ Zdd„ Zd	S )
Ú
LocalTimerc             O   s    t jƒ | _ tj| f|ž|Ž d S )N)ÚgreenletZ
getcurrentr   r   )r   r   Úkwargsr   r   r   r   V   s    
zLocalTimer.__init__c             C   s   | j d ks| j jrdS | j S )NF)r,   Údeadr   )r   r   r   r   r   Z   s    zLocalTimer.pendingc             G   s<   | j s8d| _ | jd k	r"| jjr"d S | j\}}}|||Ž d S )NT)r   r,   r.   r   )r   r   r   r   r   r   r   r"   `   s    zLocalTimer.__call__c             C   s   d | _ tj| ƒ d S )N)r,   r   r#   )r   r   r   r   r#   h   s    zLocalTimer.cancelN)r'   r(   r)   r   r*   r   r"   r#   r   r   r   r   r+   T   s   r+   )r   Zeventlet.hubsr   Zeventlet.supportr   r,   r	   r   Úobjectr   r+   r   r   r   r   Ú<module>   s   H