B
    b
,c                 @   s8  U d Z ddlZddlZddlmZ yDddlZddlmZ ddlmZ e	ej
dsdedeedd	 W n, ek
r   d
dlmZ d
dlmZ Y nX ejZG dd deZdd Zde_eed< dejkrd
dlmZ n ej
Zxe ek	re ZqW G dd deZeZ
dd Zdejkr4d
dlm
Z
mZmZ dS )ztornado IOLoop API with zmq compatibility

This module is deprecated in pyzmq 17.
To use zmq with tornado,
eventloop integration is no longer required
and tornado itself should be used.
    N)Any)ioloop)gen_logconfigurable_defaultzTornado too old: %sversionunknown   c                   s2   e Zd ZdZd	 fdd	Zdd Zdd Z  ZS )
DelayedCallbackzSchedules the given callback to be called once.

    The callback is called once, after callback_time milliseconds.

    `start` must be called after the DelayedCallback is created.

    The timeout is calculated from when `start` is called.
    Nc                s*   t dt t|d}t ||| d S )NzDDelayedCallback is deprecated.
        Use loop.add_timeout instead.gMbP?)warningswarnDeprecationWarningmaxsuper__init__)selfcallbackcallback_timeio_loop)	__class__ 3lib/python3.7/site-packages/zmq/eventloop/ioloop.pyr   +   s
    
zDelayedCallback.__init__c             C   s6   d| _ d| _t | jd  | _| j| j| j dS )zStarts the timer.Tg     @@N)_runningZ	_firstruntimer   Z_next_timeoutr   Zadd_timeout_run)r   r   r   r   start5   s    zDelayedCallback.startc             C   sD   | j s
d S d| _ y|   W n" tk
r>   tjddd Y nX d S )NFzError in delayed callbackT)exc_info)r   r   	Exceptionr   error)r   r   r   r   r   <   s    zDelayedCallback._run)N)__name__
__module____qualname____doc__r   r   r   __classcell__r   r   )r   r   r	   !   s   
r	   c               C   s$   t jr
d S dt _tjdtdd d S )NTzlzmq.eventloop.ioloop is deprecated in pyzmq 17. pyzmq now works with default tornado and asyncio eventloops.   )
stacklevel)_deprecatedcalledr
   r   r   r   r   r   r   r%   F   s    r%   F_IOLoopz.minitornado.)	ZMQIOLoopc                   s8   e Zd ZdZ fddZedd Zedd Z  ZS )r(   zDEPRECATED: No longer needed as of pyzmq-17

    PyZMQ tornado integration now works with the default :mod:`tornado.ioloop.IOLoop`.
    c                s   t   t  S )N)r%   r   r   )r   argskwargs)r   r   r   r   d   s    zZMQIOLoop.__init__c             O   s$   t j|  t  t jj||}|S )a  Returns a global `IOLoop` instance.

        Most applications have a single, global `IOLoop` running on the
        main thread.  Use this method to get this instance from
        another thread.  To get the current thread's `IOLoop`, use `current()`.
        )r   IOLoop	configurer%   instance)clsr)   r*   loopr   r   r   r-   i   s    
zZMQIOLoop.instancec             O   s$   t j|  t  t jj||}|S )u&   Returns the current thread’s IOLoop.)r   r+   r,   r%   current)r.   r)   r*   r/   r   r   r   r0   x   s    zZMQIOLoop.current)	r   r   r    r!   r   classmethodr-   r0   r"   r   r   )r   r   r(   ^   s   r(   c               C   s   t   tjt dS )zRDEPRECATED

    pyzmq 17 no longer needs any special integration for tornado.
    N)r%   r   r+   r,   r(   r   r   r   r   install   s    r2   )r+   r(   r2   )r!   r   r
   typingr   Ztornador   Ztornado.logr   hasattrr+   ImportErrorgetattrZminitornadoZminitornado.logZPeriodicCallbackr	   r%   r&   __annotations__r   r(   r'   r   r2   r   r   r   r   <module>   s8   %
&
