
    Ef              
       @   d Z ddlZddlmZmZmZmZ ddlZddlZddl	m
Z
 ddlmZ  G d de
      Zdee   d	efd
Zdeee      d	efdZe	 dddded	ee   fd       Ze	 ddej&                  e   ded	efd       Z	 ddej&                  ded	eeee   f   fdZddgZy)zJModule holding utility and convenience functions for zmq event monitoring.    N)	AwaitableListUnionoverload)	TypedDict)_check_versionc                   ,    e Zd ZU eed<   eed<   eed<   y)_MonitorMessageeventvalueendpointN)__name__
__module____qualname__int__annotations__bytes     3/usr/lib/python3/dist-packages/zmq/utils/monitor.pyr
   r
      s    JJOr   r
   msgreturnc                     t        |       dk7  st        | d         dk7  rt        d| z        t        j                  d| d         \  }}t	        j
                  |      t	        j
                  |      | d   d}|S )a  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`.
       r      z Invalid event message format: %sz=hi   )r   r   r   )lenRuntimeErrorstructunpackzmqEvent)r   event_idr   r   s       r   parse_monitor_messager$      st    * 3x1}CFq(=CDDmmE3q62OHe8$5!FE
 Lr   awaitable_msgc                 8   K   |  d{   }t        |      S 7 w)zyLike parse_monitor_msg, but awaitable

    Given awaitable message, return awaitable for the parsed monitor message.
    N)r$   )r%   r   s     r   _parse_monitor_msg_asyncr'   5   s       
C %% s   socketzzmq.asyncio.Socketflagsc                      y Nr   r(   r)   s     r   recv_monitor_messager-   B       
 r   c                      y r+   r   r,   s     r   r-   r-   J   r.   r   c                     t        dd       | j                  |      }t        |t              rt	        |      S t        |      S )u  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

    .. versionchanged:: 23.1
        Support for async sockets added.
        When called with a async socket,
        returns an awaitable for the monitor message.

    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`.
    )   r   zlibzmq event API)r   recv_multipart
isinstancer   r'   r$   )r(   r)   r   s      r   r-   r-   R   sC    > 6-.



&C #y!',, !%%r   r$   r-   )r   )__doc__r   typingr   r   r   r   r!   zmq.asynciozmq._typingr   	zmq.errorr   r
   r   r$   r'   r   r-   Socket__all__r   r   r   <module>r;      s   P
  3 3 
  ! $i tE{  @
&T%[)
&
& 
    
 
 JJu  
 )&JJ)&)& ?Io667)&X #$:
;r   