%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib64/python2.7/site-packages/zmq/eventloop/
Upload File :
Create Path :
Current File : //usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyo

�
+�{Wc@�sidZddlmZddlZddlZddlmZyddlZWne	k
rmddlZnXddl
mZy$ddlm
Z
ddlmZWn1e	k
r�ddlm
Z
ddlmZnXydd	lmZWn!e	k
r
dd	lmZnXdd
lmZmZmZyeWnek
rNd�ZnXdefd
��YZdS(s?A utility class to send to and recv from a non-blocking socket.i����(twith_statementN(tjsonapii(tIOLoop(tgen_log(t
stack_context(tQueue(tbytestunicodet
basestringcC�s
t|d�S(Nt__call__(thasattr(tobj((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyt<lambda>2st	ZMQStreamcB�s�eZdZd#Zd#Zd#Zd#Zd#Zd#Z	d#Z
dZeZ
eZd#d�Zd�Zd�Zd�Zd�Zed�Zed�Zd	�Zd
�Zdeed#d�Zdeed#d�Zdd
d#d�ZeZdd#d�Zddd#d�Zd�Ze j!e j"Bd#d�Z#d�Z$d#d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+d�Z,d�Z-d�Z.d�Z/d �Z0d!�Z1d"�Z2RS($s>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
    
    icC�s
||_|ptj�|_tj�|_t�|_d|_
d|_d|_t
|_t
|_|jj|_|j�|jj|_|jj|_|jj|_|jj|_|jj|_|jj|_|jj|_|jj|_|jj|_dS(N(tsocketRtinstancetio_looptzmqtPollertpollerRt_send_queuetNonet_recv_callbackt_send_callbackt_close_callbacktFalset
_recv_copyt_flushedtERRORt_statet_init_io_statetbindtbind_to_random_porttconnectt
setsockoptt
getsockopttsetsockopt_stringtgetsockopt_stringtsetsockopt_unicodetgetsockopt_unicode(tselfRR((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyt__init__es(						
cC�s
|jd�S(s)Disable callback and automatic receiving.N(ton_recvR(R(((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pytstop_on_recv�scC�s
|jd�S(sDisable callback on sending.N(ton_sendR(R(((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pytstop_on_send�scC�stjd�dS(sDEPRECATED, does nothings(on_err does nothing, and will be removedN(Rtwarn(R(((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pytstop_on_err�scC�stjd�dS(sDEPRECATED, does nothings(on_err does nothing, and will be removedN(RR.(R(tcallback((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyton_err�scC�s^|j�tj|�|_||_|dkrG|j|jj�n|j	|jj�dS(s�Register a callback for when a message is ready to recv.
        
        There can be only one callback registered at a time, so each
        call to `on_recv` replaces previously registered callbacks.
        
        on_recv(None) disables recv event polling.
        
        Use on_recv_stream(callback) instead, to register a callback that will receive
        both this ZMQStream and the message, instead of just the message.
        
        Parameters
        ----------
        
        callback : callable
            callback must take exactly one argument, which will be a
            list, as returned by socket.recv_multipart()
            if callback is None, recv callbacks are disabled.
        copy : bool
            copy is passed directly to recv, so if copy is False,
            callback will receive Message objects. If copy is True,
            then callback will receive bytes/str objects.
        
        Returns : None
        N(
t
_check_closedRtwrapRRRt_drop_io_stateRtREADt
_add_io_state(R(R0tcopy((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyR*�s
	c�s<�dkr�j�n�j��fd�d|�dS(s"Same as on_recv, but callback will get this stream as first argument
        
        callback must take exactly two arguments, as it will be called as::
        
            callback(stream, msg)
        
        Useful when a single callback should be used with multiple streams.
        c�s
��|�S(N((tmsg(R0R((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyR�sR7N(RR+R*(R(R0R7((R0R(s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyton_recv_stream�s	
cC�s |j�tj|�|_dS(s�Register a callback to be called on each send
        
        There will be two arguments::
        
            callback(msg, status)
        
        * `msg` will be the list of sendable objects that was just sent
        * `status` will be the return result of socket.send_multipart(msg) -
          MessageTracker or None.
        
        Non-copying sends return a MessageTracker object whose
        `done` attribute will be True when the send is complete.
        This allows users to track when an object is safe to write to
        again.
        
        The second argument will always be None if copy=True
        on the send.
        
        Use on_send_stream(callback) to register a callback that will be passed
        this ZMQStream as the first argument, in addition to the other two.
        
        on_send(None) disables recv event polling.
        
        Parameters
        ----------
        
        callback : callable
            callback must take exactly two arguments, which will be
            the message being sent (always a list),
            and the return result of socket.send_multipart(msg) -
            MessageTracker or None.
            
            if callback is None, send callbacks are disabled.
        N(R2RR3R(R(R0((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyR,�s$
c�s6�dkr�j�n�j��fd��dS(sSame as on_send, but callback will get this stream as first argument
        
        Callback will be passed three arguments::
        
            callback(stream, msg, status)
        
        Useful when a single callback should be used with multiple streams.
        c�s��||�S(N((R8tstatus(R0R((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyR�sN(RR-R,(R(R0((R0R(s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyton_send_stream�s	
c
C�s(|j|gd|d|d|d|�S(stSend a message, optionally also register a new callback for sends.
        See zmq.socket.send for details.
        tflagsR7ttrackR0(tsend_multipart(R(R8R<R7R=R0((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pytsend�scC�s�td|d|d|�}|jj||f�|p=|j}|dk	r\|j|�n|jd��|j|jj�dS(s�Send a multipart message, optionally also register a new callback for sends.
        See zmq.socket.send_multipart for details.
        R<R7R=cW�sdS(N(R(targs((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyR
sN(	tdictRtputRRR,R6RtWRITE(R(R8R<R7R=R0tkwargs((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyR>�ssutf-8cC�s@t|t�std��n|j|j|�d|d|�S(sbSend a unicode message with an encoding.
        See zmq.socket.send_unicode for details.
        sunicode/str objects onlyR<R0(t
isinstanceRt	TypeErrorR?tencode(R(tuR<tencodingR0((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pytsend_string
scC�sGtdkrtd��n(tj|�}|j|d|d|�SdS(saSend json-serialized version of an object.
        See zmq.socket.send_json for details.
        s5jsonlib{1,2}, json or simplejson library is required.R<R0N(RRtImportErrortdumpsR?(R(RR<R0R8((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyt	send_jsonsi����cC�s(tj||�}|j||d|�S(stSend a Python object as a message using pickle to serialize.

        See zmq.socket.send_json for details.
        R0(tpickleRLR?(R(RR<tprotocolR0R8((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyt
send_pyobj!scC�s
t|_dS(s%callback for unsetting _flushed flag.N(RR(R(((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyt
_finish_flush)sc	�s��j��j}t�_d}��fd�}|���sGdS�jj�j���jjd�}x�|rX|s�||krX|d\}}|tj@r��j	�|d7}�jdkr�Pq�n|tj@r�j�r�j
�|d7}�jdkrPqn|���rO�jj�j���jjd�}qrg}qrW|r�t�_|s��jj�j�q�n|r�t�_n�j�|S(s�Flush pending messages.

        This method safely handles all pending incoming and/or outgoing messages,
        bypassing the inner loop, passing them to the registered callbacks.

        A limit can be specified, to prevent blocking under high load.

        flush will return the first time ANY of these conditions are met:
            * No more events matching the flag are pending.
            * the total number of events handled reaches the limit.

        Note that if ``flag|POLLIN != 0``, recv events will be flushed even if no callback
        is registered, unlike normal IOLoop operation. This allows flush to be
        used to remove *and ignore* incoming messages.

        Parameters
        ----------
        flag : int, default=POLLIN|POLLOUT
                0MQ poll flags.
                If flag|POLLIN,  recv events will be flushed.
                If flag|POLLOUT, send events will be flushed.
                Both flags can be set at once, which is the default.
        limit : None or int, optional
                The maximum number of messages to send or receive.
                Both send and recv count against this limit.

        Returns
        -------
        int : count of events handled (both send and recv)
        ic�s"�tj@�j�o �tj@BS(sgUpdate the poll flag, to prevent registering POLLOUT events
            if we don't have pending sends.(RtPOLLINtsendingtPOLLOUT((tflagR((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pytupdate_flagSsiN(R2RRRtregisterRtpollRRRt_handle_recvRRTRSt_handle_sendtTrueRtadd_callbackRQt_rebuild_io_state(	R(RUtlimittalready_flushedtcountRVteventststevent((RUR(s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pytflush-sF
			




	
	
cC�stj|�|_dS(s2Call the given callback when the stream is closed.N(RR3R(R(R0((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pytset_close_callbackscC�s^|jdk	rZ|jj|j�|jj|�d|_|jrZ|j|j�qZndS(sClose this stream.N(RRRtremove_handlertcloseRt
_run_callback(R(tlinger((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyRg�s		cC�s
|jdk	S(s;Returns True if we are currently receiving from the stream.N(RR(R(((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyt	receiving�scC�s|jj�S(s7Returns True if we are currently sending to the stream.(Rtempty(R(((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyRS�scC�s
|jdkS(N(RR(R(((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pytclosed�scO�sRy$tj��|||�WdQXWn'tjddt�|j��nXdS(sMWrap running callbacks in try/except to allow us to
        close our socket.Ns'Uncaught exception, closing connection.texc_info(RtNullContextRterrorR[Rg(R(R0R@RD((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyRh�s

cC�s�|jstjd|�dSyz|tj@r>tjd�dS|tj@re|j�|jsedSn|tj@r�|j	�|js�dSn|j
�Wn'tjddt�|j��nXdS(s�This method is the actual handler for IOLoop, that gets called whenever
        an event on my socket is posted. It dispatches to _handle_recv, etc.sGot events for closed stream %sNs8got POLLERR event on ZMQStream, which doesn't make senses'Uncaught exception, closing connection.Rm(
RRtwarningRRRoR5RYRCRZR]R[Rg(R(tfdRa((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyt_handle_events�s*	



	

	
cC�s�|jr
dSy"|jjtjd|j�}WnHtjk
ry}|jtjkrYq�t	j
dtj|j��n&X|jr�|j}|j
||�ndS(sHandle a recv event.NR7sRECV Error: %s(RRtrecv_multipartRtNOBLOCKRtZMQErrorterrnotEAGAINRRotstrerrorRRh(R(R8teR0((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyRY�s	"!		cC�s�|jr
dS|j�s*tjd�dS|jj�\}}y|jj||�}Wn,tj	k
r�}tjd|�|}nX|j
r�|j
}|j|||�ndS(sHandle a send event.Ns#Shouldn't have handled a send eventsSEND Error: %s(RRSRRoRtgetRR>RRuRRh(R(R8RDR:RyR0((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyRZ�s	

		cC�s|jstd��ndS(NsStream is closed(RtIOError(R(((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyR2�s	cC�s�|jdkrdS|jj}|j�r>||jjO}n|j�r]||jjO}n||jkr�||_|j	|�ndS(s8rebuild io state based on self.sending() and receiving()N(
RRRRRjR5RSRCRt_update_handler(R(tstate((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyR]�s	cC�s4|j|@s0|j|B|_|j|j�ndS(sAdd io_state to poller.N(RR|(R(R}((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyR6s
cC�s5|j|@r1|j|@|_|j|j�ndS(s&Stop poller from watching an io_state.N(RR|(R(R}((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyR4s
cC�s-|jdkrdS|jj|j|�dS(s!Update IOLoop handler with state.N(RRRtupdate_handler(R(R}((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyR|scC�s6tj��$|jj|j|j|j�WdQXdS(s#initialize the ioloop event handlerN(RRnRtadd_handlerRRrR(R(((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyRs
N(3t__name__t
__module__t__doc__RRRRRRRRRRRRR)R+R-R/R1R[R*R9R,R;R?R>RJtsend_unicodeRMRPRQRRRRTRdReRgRjRSRlRhRrRYRZR2R]R6R4R|R(((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyR
5sV#				#	)	
	R											
			(R�t
__future__RtsysRt	zmq.utilsRtcPickleRNRKtioloopRttornado.logRttornadoRtminitornado.logtminitornadotqueueRtzmq.utils.strtypesRRRtcallablet	NameErrortobjectR
(((s=/usr/lib64/python2.7/site-packages/zmq/eventloop/zmqstream.pyt<module>s2






Zerion Mini Shell 1.0