File: //lib64/python3.6/site-packages/zmq/eventloop/__pycache__/zmqstream.cpython-36.pyc
3
VS�_)L � $ @ s. d Z ddlmZ ddlZddlZddlZddlmZ yddlZ W n e
k
r\ ddl Z Y nX ddlmZm
Z
yddlmZ W n4 e
k
r� dejkr�ddlmZ nd d
� ZY nX yddlmZ W n e
k
r� ddlmZ Y nX ddlmZ ye W n ek
�r d
d� ZY nX G dd� de�ZdS )z�A utility class to send to and recv from a non-blocking socket,
using tornado.
.. seealso::
- :mod:`zmq.asyncio`
- :mod:`zmq.eventloop.future`
� )�with_statementN)�jsonapi� )�IOLoop�gen_log)�wrapzzmq.eventloop.minitornadoc C s | S )N� )�callbackr r �!/usr/lib64/python3.6/zmqstream.py�stack_context_wrap0 s r )�Queue)�
basestringc C s
t | d�S )N�__call__)�hasattr)�objr r r
�<lambda>= s r c @ sX e Zd ZdZdZdZdZdZdZdZ dZ
dZdZdZ
dZdFdd�Zdd� Zd d
� Zdd� Zd
d� ZdGdd�ZdHdd�Zdd� Zdd� ZdIdd�ZdJdd�ZdKdd�ZeZdLdd �ZdNd"d#�Zd$d%� Zej ej!B dfd&d'�Z"d(d)� Z#dOd*d+�Z$d,d-� Z%d.d/� Z&d0d1� Z'd2d3� Z(d4d5� Z)d6d7� Z*d8d9� Z+d:d;� Z,d<d=� Z-d>d?� Z.d@dA� Z/dBdC� Z0dDdE� Z1dS )P� ZMQStreama> A utility class to register callbacks when a zmq socket sends and receives
For use with zmq.eventloop.ioloop
There are three main methods
Methods:
* **on_recv(callback, copy=True):**
register a callback to be run every time the socket has something to receive
* **on_send(callback):**
register a callback to be run every time you call send
* **send(self, msg, flags=0, copy=False, callback=None):**
perform a send that will trigger the callback
if callback is passed, on_send is also called.
There are also send_multipart(), send_json(), send_pyobj()
Three other methods for deactivating the callbacks:
* **stop_on_recv():**
turn off the recv callback
* **stop_on_send():**
turn off the send callback
which simply call ``on_<evt>(None)``.
The entire socket interface, excluding direct recv methods, is also
provided, primarily through direct-linking the methods.
e.g.
>>> stream.bind is stream.socket.bind
True
Nr Fc C s� || _ |ptj� | _tj� | _| j j| _t � | _
d | _d | _d | _
d| _d| _d| _| j� | j j| _| j j| _| j j| _| j j| _| j j| _| j j| _| j j| _| j j| _| j j| _d S )NFr )�socketr Zcurrent�io_loop�zmqZPoller�pollerZFD�_fdr �_send_queue�_recv_callback�_send_callback�_close_callback�
_recv_copy�_flushed�_state�_init_io_stateZbindZbind_to_random_portZconnectZ
setsockoptZ
getsockoptZsetsockopt_stringZgetsockopt_stringZsetsockopt_unicodeZgetsockopt_unicode)�selfr r r r r
�__init__q s*
zZMQStream.__init__c C s
| j d�S )z)Disable callback and automatic receiving.N)�on_recv)r r r r
�stop_on_recv� s zZMQStream.stop_on_recvc C s
| j d�S )zDisable callback on sending.N)�on_send)r r r r
�stop_on_send� s zZMQStream.stop_on_sendc C s t jd� dS )zDEPRECATED, does nothingz(on_err does nothing, and will be removedN)r �warn)r r r r
�stop_on_err� s zZMQStream.stop_on_errc C s t jd� dS )zDEPRECATED, does nothingz(on_err does nothing, and will be removedN)r r&