ó
Ýà‹]c           @   sd   d  Z  y d d l m Z m Z Wn' e k
 rI d d l m Z m Z n Xd e f d „  ƒ  YZ d S(   sL   Blocking channels

Useful for test suites and blocking terminal interfaces.
iÿÿÿÿ(   t   Queuet   Emptyt   ZMQSocketChannelc           B   sŒ   e  Z d  Z d
 Z d
 Z d
 Z e Z g  Z	 d
 d „ Z
 d „  Z e d
 d „ Z d „  Z d „  Z d „  Z e Z d „  Z d „  Z d	 „  Z RS(   s%   A ZMQ socket in a simple blocking APIc         C   s)   t  t |  ƒ j ƒ  | |  _ | |  _ d S(   s  Create a channel.

        Parameters
        ----------
        socket : :class:`zmq.Socket`
            The ZMQ socket to use.
        session : :class:`session.Session`
            The session to use.
        loop
            Unused here, for other implementations
        N(   t   superR   t   __init__t   sockett   session(   t   selfR   R   t   loop(    (    s?   lib/python2.7/site-packages/jupyter_client/blocking/channels.pyR      s    	c         K   s:   |  j  j |   } |  j j | ƒ \ } } |  j j | ƒ S(   N(   R   t   recv_multipartR   t   feed_identitiest   deserialize(   R   t   kwargst   msgt   identt   smsg(    (    s?   lib/python2.7/site-packages/jupyter_client/blocking/channels.pyt   _recv(   s    c         C   sc   | r4 | d k	 r | d 9} n  |  j j | ƒ } n |  j j d d ƒ } | rY |  j ƒ  St ‚ d S(   s/    Gets a message if there is one that is ready. iè  t   timeouti    N(   t   NoneR   t   pollR   R   (   R   t   blockR   t   ready(    (    s?   lib/python2.7/site-packages/jupyter_client/blocking/channels.pyt   get_msg-   s    
c         C   sI   g  } x< t  rD y | j |  j d t ƒ ƒ Wq	 t k
 r@ Pq	 Xq	 W| S(   s,    Get all messages that are currently ready. R   (   t   Truet   appendR   t   FalseR   (   R   t   msgs(    (    s?   lib/python2.7/site-packages/jupyter_client/blocking/channels.pyt   get_msgs;   s    		c         C   s   t  |  j j d d ƒ ƒ S(   s,    Is there a message that has been received? R   i    (   t   boolR   R   (   R   (    (    s?   lib/python2.7/site-packages/jupyter_client/blocking/channels.pyt	   msg_readyE   s    c         C   sJ   |  j  d  k	 rF y |  j  j d d ƒ Wn t k
 r9 n Xd  |  _  n  d  S(   Nt   lingeri    (   R   R   t   closet	   Exception(   R   (    (    s?   lib/python2.7/site-packages/jupyter_client/blocking/channels.pyR   I   s    c         C   s   |  j  d  k	 S(   N(   R   R   (   R   (    (    s?   lib/python2.7/site-packages/jupyter_client/blocking/channels.pyt   is_aliveR   s    c         C   s   |  j  j |  j | ƒ d S(   s1   Pass a message to the ZMQ socket to send
        N(   R   t   sendR   (   R   R   (    (    s?   lib/python2.7/site-packages/jupyter_client/blocking/channels.pyR"   U   s    c         C   s   d  S(   N(    (   R   (    (    s?   lib/python2.7/site-packages/jupyter_client/blocking/channels.pyt   startZ   s    N(   t   __name__t
   __module__t   __doc__R   R   R   t   streamR   t   _exitingt   proxy_methodsR   R   R   R   R   R   R   t   stopR!   R"   R#   (    (    (    s?   lib/python2.7/site-packages/jupyter_client/blocking/channels.pyR      s    		
				N(   R&   t   queueR    R   t   ImportErrort   objectR   (    (    (    s?   lib/python2.7/site-packages/jupyter_client/blocking/channels.pyt   <module>   s
   