o
    i                  
   @   s  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 de
Zdee d	efd
dZdeee  d	efddZe	dddded	ee fddZe	ddeje ded	efddZ	ddejded	eeee f fddZddgZdS )zJModule holding utility and convenience functions for zmq event monitoring.    N)	AwaitableListUnionoverload)	TypedDict)_check_versionc                   @   s&   e Zd ZU eed< eed< eed< dS )_MonitorMessageeventvalueendpointN)__name__
__module____qualname__int__annotations__bytes r   r   L/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/zmq/utils/monitor.pyr      s   
 r   msgreturnc                 C   s\   t | dkst | d dkrtd|  td| d \}}t|t|| 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	   r   r   r   parse_monitor_message   s   r    awaitable_msgc                    s   | I dH }t |S )zyLike parse_monitor_msg, but awaitable

    Given awaitable message, return awaitable for the parsed monitor message.
    N)r    )r!   r   r   r   r   _parse_monitor_msg_async5   s   
r"   socketzzmq.asyncio.Socketflagsc                 C      d S Nr   r#   r$   r   r   r   recv_monitor_messageB      r(   c                 C   r%   r&   r   r'   r   r   r   r(   J   r)   c                 C   s.   t dd | |}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   r   r   r   r(   R   s
   


)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   r   <module>   sR     

	
,