ó
L]c           @   sS   d  Z  d d l Z d d l Z d d l m Z d   Z d d  Z d d g Z d S(	   sJ   Module holding utility and convenience functions for zmq event monitoring.i’’’’N(   t   _check_versionc         C   s   t  |   d k s( t  |  d  d k r; t d |    n  i t j d |  d  d d 6t j d |  d  d d 6|  d d	 6} | S(
   sŲ  decode zmq_monitor event messages.
    
    Parameters
    ----------
    msg : list(bytes)
        zmq multipart message that has arrived on a monitor PAIR socket.
        
        First frame is::
        
            16 bit event id
            32 bit event value
            no padding

        Second frame is the endpoint as a bytestring

    Returns
    -------
    event : dict
        event description as dict with the keys `event`, `value`, and `endpoint`.
    i   i    i   s    Invalid event message format: %ss   =hit   eventi   t   valuet   endpoint(   t   lent   RuntimeErrort   structt   unpack(   t   msgR   (    (    s0   lib/python2.7/site-packages/zmq/utils/monitor.pyt   parse_monitor_message   s    (i    c         C   s&   t  d d  |  j |  } t |  S(   sā  Receive and decode the given raw message from the monitoring socket and return a dict.

    Requires libzmq ā„ 4.0

    The returned dict will have the following entries:
      event     : int, the event id as described in libzmq.zmq_socket_monitor
      value     : int, the event value associated with the event, see libzmq.zmq_socket_monitor
      endpoint  : string, the affected endpoint
    
    Parameters
    ----------
    socket : zmq PAIR socket
        The PAIR socket (created by other.get_monitor_socket()) on which to recv the message
    flags : bitfield (int)
        standard zmq recv flags

    Returns
    -------
    event : dict
        event description as dict with the keys `event`, `value`, and `endpoint`.
    i   i    s   libzmq event API(   i   i    (   R    t   recv_multipartR	   (   t   sockett   flagsR   (    (    s0   lib/python2.7/site-packages/zmq/utils/monitor.pyt   recv_monitor_message(   s    R	   R   (   t   __doc__R   t   zmqt	   zmq.errorR    R	   R   t   __all__(    (    (    s0   lib/python2.7/site-packages/zmq/utils/monitor.pyt   <module>   s   	