
    Mh"                       U d Z ddlmZ ddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZmZmZmZmZmZ ddlmZ ddlZddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lm Z  ddl!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z( 	 ej)        Z)n# e*$ r
 ej+        Z)Y nw xY w edd          Z,dZ-de.d<    G d de
e,                   Z/ ed          Z0 G d dee&e
e0                   Zee1         Z2de.d<   ddgZ3dS )z0MQ Socket pure Python methods.    )annotationsN)
AnyCallableGenericListLiteralSequenceTypeVarUnioncastoverload)warn)	TypeAlias)Socket)ZMQBindErrorZMQError)jsonapi)cast_int_addr   )SocketOption
SocketType_OptType   )AttributeSetter)Poller_SocketTyper   )boundz9int | str | bool | list[_JSONType] | dict[str, _JSONType]r   	_JSONTypec                  N    e Zd ZU dZded<   ded<   ded<   d Zdd
ZddZd ZdS )_SocketContextz&Context Manager for socket bind/unbindr   socketstrkindaddrc                (    d| j          d| j        dS )Nz<SocketContext(=z)>)r#   r$   selfs    P/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/zmq/sugar/socket.py__repr__z_SocketContext.__repr__6   s    <<<TY<<<<    r(   _SocketContext[_SocketType]c                <    |dv sJ || _         || _        || _        d S )N>   bindconnect)r!   r#   r$   )r(   r!   r#   r$   s       r)   __init__z_SocketContext.__init__9   s/     *****				r+   returnc                    | j         S N)r!   r'   s    r)   	__enter__z_SocketContext.__enter__A   s
    {r+   c                    | j         j        rd S | j        dk    r!| j                             | j                   d S | j        dk    r!| j                             | j                   d S d S )Nr.   r/   )r!   closedr#   unbindr$   
disconnect)r(   argss     r)   __exit__z_SocketContext.__exit__D   sr    ; 	F9Kty)))))Y)##K""49----- $#r+   N)r(   r,   r!   r   r#   r"   r$   r"   )r(   r,   r1   r   )	__name__
__module____qualname____doc____annotations__r*   r0   r4   r:    r+   r)   r    r    /   s         00IIIIII= = =      . . . . .r+   r    SocketReturnTypec                      e Zd ZdZdZdZdZdZedddd            Z	edddd            Z	edd            Z		 	 ddddd fdZ	d Z
dZd ZddZd ZdddZeZedd#            Zdd fd%Zdd)Zdd*Zd fd+Zd fd,Zedd-            Zd. Zej        Zej        Z fd/Z dd0Z!dd3Z"dd4Z#ddd8Z$e$xZ%Z&ddd9Z'e'xZ(Z)	 	 	 ddd@Z*ddAZ+ddCZ, ee+e,ddD          Z-e	 	 ddEdEdFddR            Z.e	 	 ddEdEdFddT            Z.e	 ddEdEdEdUddV            Z.e	 	 	 	 	 dddX            Z.	 	 	 	 	 dd fdZZ.	 	 	 ddd]Z/e	 ddEd^dd`            Z0e	 ddEd^ddb            Z0eddEd^ddc            Z0e	 ddde            Z0	 dddfZ0ddkZ1ddlZ2ddmZ3	 	 	 dddqZ4e4Z5dddrZ6e6Z7de8fdduZ9dddvZ:dddwZ;dddyZ<e=Z>de?j@        fdd{ZA	 ddd}ZBdd~ZC xZDS )r   a  The ZMQ socket object

    To create a Socket, first create a Context::

        ctx = zmq.Context.instance()

    then call ``ctx.socket(socket_type)``::

        s = ctx.socket(zmq.ROUTER)

    .. versionadded:: 25

        Sockets can now be shadowed by passing another Socket.
        This helps in creating an async copy of a sync socket or vice versa::

            s = zmq.Socket(async_socket)

        Which previously had to be::

            s = zmq.Socket.shadow(async_socket.underlying)
    FNUNKNOWN)copy_thresholdr(   Socket[bytes]ctx_or_socketzmq.Contextsocket_typeintrD   
int | Nonec                   d S r3   r@   )r(   rF   rH   rD   s       r)   r0   zSocket.__init__l   s	     sr+   shadowSocket | intc                   d S r3   r@   )r(   rL   rD   s      r)   r0   zSocket.__init__u   s	     sr+   c                    d S r3   r@   )r(   rF   s     r)   r0   zSocket.__init__}   s	     sr+   r   rL   rD   zmq.Context | Socket | Nonec                  d }t          |t          j                  r|}d }d}|rd| _        || _        t          |t
                    sMt          |t          j                  r|j        }	 t          t
          |j                  }n# t          $ r Y nw xY wt          |          }nd| _        t                                          ||||           | j        r	|r|| _        	 t          t
          |                     t          j                            }	 t          |          x| j        d<   }|j        | _        d S # t&          $ r t)          |          | _        Y d S w xY w# t*          $ r Y d S w xY w)Nr   TFrP   type)
isinstancezmqr   _shadow_shadow_objrI   contextr   
underlyingAttributeErrorr   superr0   getTYPEr   __dict__name
_type_name
ValueErrorr"   	Exception)	r(   rF   rH   rL   rD   shadow_contextshadow_addressstype	__class__s	           r)   r0   zSocket.__init__   s    .2mSZ00 	!"F M 	!DL%Dfc** fcj11 4%+^N!#v'899FF%   D*622NN DL!)	 	 	
 	
 	
  	* 	*)DL
	-sDHHSX$6$677K-0:;0G0GGf% #(*  3 3 3"%k"2"23  	 	 	DD	s6   +B 
BB#2E" D= =EE"
E0/E0c                    | j         s?| j        s:t          t          d|  t          d|            |                                  d S d S d S )NzUnclosed socket r   )
stacklevelsource)rV   r6   r   ResourceWarningcloser'   s    r)   __del__zSocket.__del__   sm    | 		DK 		-t--# 	    JJLLLLL		 		 		 		r+   z
zmq.Socketc           
         | j         }|j                            dd           }||j         d|j         }| j        rdnd}d| d| j         dt          t          |                      | dS )	N	_repr_cls.z closed <z(zmq.z) at >)	rf   r^   r\   r<   r;   _closedr`   hexid)r(   clsrn   r6   s       r)   r*   zSocket.__repr__   s    nL$$[$77	>::CL::I"l2Q9QQ4?QQRXXQQQQQr+   r   r1   c                    | S )zESockets are context managers

        .. versionadded:: 14.4
        r@   r'   s    r)   r4   zSocket.__enter__   s	    
 r+   c                .    |                                   d S r3   )rk   )r(   r9   kwargss      r)   r:   zSocket.__exit__   s    

r+   c                @    | j                             | j                  S )z&Copying a Socket creates a shadow copy)rf   rL   rY   )r(   memos     r)   __copy__zSocket.__copy__   s    ~$$T_555r+   rv   type[_SocketType]addressint | zmq.Socketc                     | |          S )aE  Shadow an existing libzmq socket

        address is a zmq.Socket or an integer (or FFI pointer)
        representing the address of the libzmq socket.

        .. versionadded:: 14.1

        .. versionadded:: 25
            Support for shadowing `zmq.Socket` objects,
            instead of just integer addresses.
        )rL   r@   )rv   r~   s     r)   rL   zSocket.shadow   s     s'""""r+   Nonec                    | j         r| j                             |            t                                          |           dS )a  
        Close the socket.

        If linger is specified, LINGER sockopt will be set prior to closing.

        Note: closing a zmq Socket may not close the underlying sockets
        if there are undelivered messages.
        Only after all messages are delivered or discarded by reaching the socket's LINGER timeout
        (default: forever)
        will the underlying sockets be closed.

        This can be called to close the socket by hand. If this is not
        called, the socket will automatically be closed when it is
        garbage collected,
        in which case you may see a ResourceWarning about the unclosed socket.
        )lingerN)rX   
_rm_socketr[   rk   )r(   r   rf   s     r)   rk   zSocket.close   sC    " < 	*L##D)))V$$$$$r+   r$   r"   r,   c                $    t          | d|          S )zNContext manager to disconnect on exit

        .. versionadded:: 20.0
        r/   )r    r(   r$   s     r)   _connect_cmzSocket._connect_cm  s    
 dIt444r+   c                    	 t          t          |                     t          j                                                d          }n# t          t          t          f$ r Y nw xY wt          | d|          S )zJContext manager to unbind on exit

        .. versionadded:: 20.0
        utf8r.   )
r   bytesr\   rU   LAST_ENDPOINTdecoderZ   r   UnicodeDecodeErrorr    r   s     r)   _bind_cmzSocket._bind_cm  sq    
	 txx(9::;;BB6JJDD*<= 	 	 	D	dFD111s   AA A"!A"c                    	 t                                          |           n'# t          $ r}|xj        d|dz  c_         d}~ww xY w|                     |          S )a  s.bind(addr)

        Bind the socket to an address.

        This causes the socket to listen on a network port. Sockets on the
        other side of this connection will use ``Socket.connect(addr)`` to
        connect to this socket.

        Returns a context manager which will call unbind on exit.

        .. versionadded:: 20.0
            Can be used as a context manager.

        .. versionadded:: 26.0
            binding to port 0 can be used as a context manager
            for binding to a random port.
            The URL can be retrieved as `socket.last_endpoint`.

        Parameters
        ----------
        addr : str
            The address string. This has the form 'protocol://interface:port',
            for example 'tcp://127.0.0.1:5555'. Protocols supported include
            tcp, udp, pgm, epgm, inproc and ipc. If the address is unicode, it is
            encoded to utf-8 first.

         (addr=)N)r[   r.   r   strerrorr   r(   r$   erf   s      r)   r.   zSocket.bind#  ss    8	GGLL 	 	 	JJ-D----JJ	 }}T"""   !% 
A	AA	c                    	 t                                          |           n'# t          $ r}|xj        d|dz  c_         d}~ww xY w|                     |          S )a  s.connect(addr)

        Connect to a remote 0MQ socket.

        Returns a context manager which will call disconnect on exit.

        .. versionadded:: 20.0
            Can be used as a context manager.

        Parameters
        ----------
        addr : str
            The address string. This has the form 'protocol://interface:port',
            for example 'tcp://127.0.0.1:5555'. Protocols supported are
            tcp, udp, pgm, inproc and ipc. If the address is unicode, it is
            encoded to utf-8 first.

        r   r   N)r[   r/   r   r   r   r   s      r)   r/   zSocket.connectF  su    &	GGOOD!!!! 	 	 	JJ-D----JJ	 %%%r   c                `    t          dt                     t          t          | j                  S )Nz1Socket.socket_type is deprecated, use Socket.type)r   DeprecationWarningr   rI   rS   r'   s    r)   rH   zSocket.socket_typed  s&    @BTUUUC###r+   c                l    t          | j                  }|                    t          j                   |S r3   )dirrf   extendr   __members__)r(   keyss     r)   __dir__zSocket.__dir__m  s+    4>""L,---r+   c                   || j         v rt                              | ||           dS |                                }|dv rst	          |t
                    r|                    d          }|dk    r!|                     t          j	        |           n |                     t          j
        |           dS t                                          ||           dS )zROverride to allow setting zmq.[UN]SUBSCRIBE even though we have a subscribe methodN)	subscribeunsubscriber   r   )r^   object__setattr__lowerrT   r"   encodesetrU   	SUBSCRIBEUNSUBSCRIBEr[   )r(   keyvalue_keyrf   s       r)   r   zSocket.__setattr__x  s    $-tS%000Fyy{{///%%% -V,,{""....%000FC'''''r+   c                    | j         S )a\  Return edge-triggered file descriptor for this socket.

        This is a read-only edge-triggered file descriptor for both read and write events on this socket.
        It is important that all available events be consumed when an event is detected,
        otherwise the read event will not trigger again.

        .. versionadded:: 17.0
        )FDr'   s    r)   filenozSocket.fileno  s     wr+   topicstr | bytesc                    t          |t                    r|                    d          }|                     t          j        |           dS )z\Subscribe to a topic

        Only for SUB sockets.

        .. versionadded:: 15.3
        r   N)rT   r"   r   r   rU   r   r(   r   s     r)   r   zSocket.subscribe  sC     eS!! 	)LL((E&&&&&r+   c                    t          |t                    r|                    d          }|                     t          j        |           dS )z`Unsubscribe from a topic

        Only for SUB sockets.

        .. versionadded:: 15.3
        r   N)rT   r"   r   r   rU   r   r   s     r)   r   zSocket.unsubscribe  sC     eS!! 	)LL((E%(((((r+   utf-8optionoptvalc                    t          |t                    s"t          dt          |           d|          |                     ||                    |                    S )a  Set socket options with a unicode object.

        This is simply a wrapper for setsockopt to protect from encoding ambiguity.

        See the 0MQ documentation for details on specific options.

        Parameters
        ----------
        option : int
            The name of the option to set. Can be any of: SUBSCRIBE,
            UNSUBSCRIBE, IDENTITY
        optval : str
            The value of the option to set.
        encoding : str
            The encoding to be used, default is utf8
        zstrings only, not z: )rT   r"   	TypeErrorrS   r   r   )r(   r   r   encodings       r)   
set_stringzSocket.set_string  s\    " &#&& 	MKfKKKKLLLxxh 7 7888r+   c                    t          |          j        t          j        k    rt	          d| d          t          t          |                     |                                        |          S )a=  Get the value of a socket option.

        See the 0MQ documentation for details on specific options.

        Parameters
        ----------
        option : int
            The option to retrieve.

        Returns
        -------
        optval : str
            The value of the option as a unicode string.
        zoption z' will not return a string to be decoded)r   	_opt_typer   r   r   r   r\   r   )r(   r   r   s      r)   
get_stringzSocket.get_string  s`     )X^;;UfUUUVVVE488F++,,33H===r+         d   min_portmax_port	max_triesc                F   |dk    rt|dk    rn|                      | d           t          t          | j                                      dd          }|                    dd          \  }}t          |          S t          |          D ]}	 t          j	        ||          }	|                      | d|	            |	c S # t          $ rG}
|
j        }|t          j        k    rY d}
~
\t          j        d	k    r|t          j        k    rY d}
~
 d}
~
ww xY wt#          d
          )a  Bind this socket to a random port in a range.

        If the port range is unspecified, the system will choose the port.

        Parameters
        ----------
        addr : str
            The address string without the port to pass to ``Socket.bind()``.
        min_port : int, optional
            The minimum port in the range of ports to try (inclusive).
        max_port : int, optional
            The maximum port in the range of ports to try (exclusive).
        max_tries : int, optional
            The maximum number of bind attempts to make.

        Returns
        -------
        port : int
            The port the socket was bound to.

        Raises
        ------
        ZMQBindError
            if `max_tries` reached before successful bind
        r   r   z:*asciireplace:r   Nwin32z%Could not bind socket to random port.)r.   r   r   last_endpointr   rsplitrI   rangerandom	randranger   errnorU   
EADDRINUSEsysplatformEACCESr   )r(   r$   r   r   r   url_port_siport	exceptionens               r)   bind_to_random_portzSocket.bind_to_random_port  sJ   @ uU!2!2 IIkkk"""ud01188)LLC

3**IAvv;;y!! 	 	A'(;;		T**D**+++     _''HHHH\W,,u|1C1CHHHH BCCCs$   /C  
D
D& DDDc                    	 t          t          |                     t          j                            S # t          j        $ r Y nw xY wt          t          |                     t          j                            S )uk   Get the High Water Mark.

        On libzmq ≥ 3, this gets SNDHWM if available, otherwise RCVHWM
        )r   rI   r\   rU   SNDHWMr   RCVHWMr'   s    r)   get_hwmzSocket.get_hwm  sg    	TXXcj11222| 	 	 	D	 C#*--...s   14 AAr   c                    d}	 || _         n# t          $ r}|}Y d}~nd}~ww xY w	 || _        n# t          $ r}|}Y d}~nd}~ww xY w|r|dS )u   Set the High Water Mark.

        On libzmq ≥ 3, this sets both SNDHWM and RCVHWM


        .. warning::

            New values only take effect for subsequent socket
            bind/connects.
        N)sndhwmrb   rcvhwm)r(   r   raisedr   s       r)   set_hwmzSocket.set_hwm  s     	DKK 	 	 	FFFFFF		DKK 	 	 	FFFFFF	  	L	 	s"    
"". 
A?AzProperty for High Water Mark.

        Setting hwm sets both SNDHWM and RCVHWM as appropriate.
        It gets SNDHWM if available, otherwise RCVHWM.
        .
routing_idgroupdatar   flagscopybooltrackLiteral[True]r   r   
str | Nonezmq.MessageTrackerc                   d S r3   r@   r(   r   r   r   r   r   r   s          r)   sendzSocket.sendA  s	     !Sr+   Literal[False]c                   d S r3   r@   r   s          r)   r   zSocket.sendM  s	     sr+   )r   r   r   c                   d S r3   r@   )r(   r   r   r   r   r   s         r)   r   zSocket.sendY  s	     sr+   zmq.MessageTracker | Nonec                    d S r3   r@   r   s          r)   r   zSocket.sendd  s	     %(Cr+   Tc                V   |@t          |t          j                  st          j        |||pd| j                  }||_        |@t          |t          j                  st          j        |||pd| j                  }||_        t                                          ||||          S )a  Send a single zmq message frame on this socket.

        This queues the message to be sent by the IO thread at a later time.

        With flags=NOBLOCK, this raises :class:`ZMQError` if the queue is full;
        otherwise, this waits until space is available.
        See :class:`Poller` for more general non-blocking I/O.

        Parameters
        ----------
        data : bytes, Frame, memoryview
            The content of the message. This can be any object that provides
            the Python buffer API (i.e. `memoryview(data)` can be called).
        flags : int
            0, NOBLOCK, SNDMORE, or NOBLOCK|SNDMORE.
        copy : bool
            Should the message be sent in a copying or non-copying manner.
        track : bool
            Should the message be tracked for notification that ZMQ has
            finished with it? (ignored if copy=True)
        routing_id : int
            For use with SERVER sockets
        group : str
            For use with RADIO sockets

        Returns
        -------
        None : if `copy` or not track
            None if message was sent, raises an exception otherwise.
        MessageTracker : if track and not copy
            a MessageTracker object, whose `done` property will
            be False until the send is completed.

        Raises
        ------
        TypeError
            If a unicode object is passed
        ValueError
            If `track=True`, but an untracked Frame is passed.
        ZMQError
            If the send does not succeed for any reason (including
            if NOBLOCK is set and the outgoing queue is full).


        .. versionchanged:: 17.0

            DRAFT support for routing_id and group arguments.
        N)r   r   rD   )r   r   r   )rT   rU   FramerD   r   r   r[   r   )r(   r   r   r   r   r   r   rf   s          r)   r   zSocket.sendo  s    r !dCI.. y#'#6	   )DOdCI.. y#'#6	   DJww||DD|FFFr+   	msg_partsr	   c           	        t          |          D ]\  }}t          |t          j        t          t
          f          r-	 t          |           ># t          $ rF t          |          }t          |          dk    r|dd         dz   }t          d| d| d          w xY w|dd         D ](}| 
                    |t          j        |z  ||           )| 
                    |d         |||          S )	aW  Send a sequence of buffers as a multipart message.

        The zmq.SNDMORE flag is added to all msg parts before the last.

        Parameters
        ----------
        msg_parts : iterable
            A sequence of objects to send as a multipart message. Each element
            can be any sendable object (Frame, bytes, buffer-providers)
        flags : int, optional
            Any valid flags for :func:`Socket.send`.
            SNDMORE is added automatically for frames before the last.
        copy : bool, optional
            Should the frame(s) be sent in a copying or non-copying manner.
            If copy=False, frames smaller than self.copy_threshold bytes
            will be copied anyway.
        track : bool, optional
            Should the frame(s) be tracked for notification that ZMQ has
            finished with it (ignored if copy=True).

        Returns
        -------
        None : if copy or not track
        MessageTracker : if track and not copy
            a MessageTracker object, whose `done` property will
            be False until the last send is completed.
            Nz...zFrame z (z() does not support the buffer interface.r   r   )	enumeraterT   rU   r   r   
memoryviewrb   reprlenr   r   SNDMORE)	r(   r   r   r   r   ry   r   msgrmsgs	            r)   send_multipartzSocket.send_multipart  s   H  	** 	 	FAs#	5*=>> 3   Cyyt99r>>9u,DPQPP$PPP  	 SbS> 	H 	HCIIc3;.TIGGGGyy2DyFFFs   AAB)r   list[bytes]c                   d S r3   r@   r(   r   r   r   s       r)   recv_multipartzSocket.recv_multipart  s	     cr+   list[zmq.Frame]c                   d S r3   r@   r  s       r)   r	  zSocket.recv_multipart  s	     #r+   c                   d S r3   r@   )r(   r   r   s      r)   r	  zSocket.recv_multipart  s    UXUXr+   list[zmq.Frame] | list[bytes]c                    d S r3   r@   r  s       r)   r	  zSocket.recv_multipart  s	     ),r+   c                   |                      |||          g}|                     t          j                  rL|                      |||          }|                    |           |                     t          j                  Lt          t          t          t          j                 t          t                   f         |          S )ay  Receive a multipart message as a list of bytes or Frame objects

        Parameters
        ----------
        flags : int, optional
            Any valid flags for :func:`Socket.recv`.
        copy : bool, optional
            Should the message frame(s) be received in a copying or non-copying manner?
            If False a Frame object is returned for each part, if True a copy of
            the bytes is made for each frame.
        track : bool, optional
            Should the message frame(s) be tracked for notification that ZMQ has
            finished with it? (ignored if copy=True)

        Returns
        -------
        msg_parts : list
            A list of frames in the multipart message; either Frames or bytes,
            depending on `copy`.

        Raises
        ------
        ZMQError
            for any of the reasons :func:`~Socket.recv` might fail
        r   )
recv
getsockoptrU   RCVMOREappendr   r   r   r   r   )r(   r   r   r   partsparts         r)   r	  zSocket.recv_multipart  s    8 5t599:oock** 	99UU9;;DLL oock** 	
 E$sy/4;67???r+   recvdr   loadCallable[[bytes], Any]c                     ||          S )a  Deserialize a received message

        Override in subclass (e.g. Futures) if recvd is not the raw bytes.

        The default implementation expects bytes and returns the deserialized message immediately.

        Parameters
        ----------

        load: callable
            Callable that deserializes bytes
        recvd:
            The object returned by self.recv

        r@   )r(   r  r  s      r)   _deserializezSocket._deserialize(  s    ( tE{{r+   c                :     ||          } | j         |f||d|S )aW  Send a message with a custom serialization function.

        .. versionadded:: 17

        Parameters
        ----------
        msg : The message to be sent. Can be any object serializable by `serialize`.
        serialize : callable
            The serialization function to use.
            serialize(msg) should return an iterable of sendable message frames
            (e.g. bytes objects), which will be passed to send_multipart.
        flags : int, optional
            Any valid flags for :func:`Socket.send`.
        copy : bool, optional
            Whether to copy the frames.

        r   r   )r  )r(   r  	serializer   r   ry   framess          r)   send_serializedzSocket.send_serialized>  s3    $ 3"t"6LTLLVLLLr+   c                \    |                      ||          }|                     ||          S )a  Receive a message with a custom deserialization function.

        .. versionadded:: 17

        Parameters
        ----------
        deserialize : callable
            The deserialization function to use.
            deserialize will be called with one argument: the list of frames
            returned by recv_multipart() and can return any object.
        flags : int, optional
            Any valid flags for :func:`Socket.recv`.
        copy : bool, optional
            Whether to recv bytes or Frame objects.

        Returns
        -------
        obj : object
            The object returned by the deserialization function.

        Raises
        ------
        ZMQError
            for any of the reasons :func:`~Socket.recv` might fail
        r  )r	  r  )r(   deserializer   r   r  s        r)   recv_serializedzSocket.recv_serializedS  s2    4 $$5t$<<  555r+   ur   zmq.Frame | Nonec                    t          |t                    st          d           | j        |                    |          f||d|S )a  Send a Python unicode string as a message with an encoding.

        0MQ communicates with raw bytes, so you must encode/decode
        text (str) around 0MQ.

        Parameters
        ----------
        u : str
            The unicode string to send.
        flags : int, optional
            Any valid flags for :func:`Socket.send`.
        encoding : str
            The encoding to be used
        zstr objects onlyr  )rT   r"   r   r   r   )r(   r#  r   r   r   ry   s         r)   send_stringzSocket.send_stringp  sR    , !S!! 	0.///ty(++N5tNNvNNNr+   c                b    |                      |          }|                     |fd          S )a  Receive a unicode string, as sent by send_string.

        Parameters
        ----------
        flags : int
            Any valid flags for :func:`Socket.recv`.
        encoding : str
            The encoding to be used

        Returns
        -------
        s : str
            The Python unicode string that arrives as encoded bytes.

        Raises
        ------
        ZMQError
            for any of the reasons :func:`Socket.recv` might fail
        )r   c                .    |                                S r3   )r   )bufr   s    r)   <lambda>z$Socket.recv_string.<locals>.<lambda>  s    #**X2F2F r+   r  r  )r(   r   r   r  s     ` r)   recv_stringzSocket.recv_string  s8    ( iiei$$  &F&F&F&FGGGr+   objprotocolc                L    t          j        ||          } | j        |fd|i|S )a  
        Send a Python object as a message using pickle to serialize.

        .. warning::

            Never deserialize an untrusted message with pickle,
            which can involve arbitrary code execution.
            Make sure to authenticate the sources of messages
            before unpickling them, e.g. with transport-level security
            (e.g. CURVE, ZAP, or IPC permissions)
            or signed messages.

        Parameters
        ----------
        obj : Python object
            The Python object to send.
        flags : int
            Any valid flags for :func:`Socket.send`.
        protocol : int
            The pickle protocol number to use. The default is pickle.DEFAULT_PROTOCOL
            where defined, and pickle.HIGHEST_PROTOCOL elsewhere.
        r   )pickledumpsr   )r(   r-  r   r.  ry   r  s         r)   
send_pyobjzSocket.send_pyobj  s4    2 l3))ty44E4V444r+   c                l    |                      |          }|                     |t          j                  S )a<  
        Receive a Python object as a message using UNSAFE pickle to serialize.

        .. warning::

            Never deserialize an untrusted message with pickle,
            which can involve arbitrary code execution.
            Make sure to authenticate the sources of messages
            before unpickling them, e.g. with transport-level security
            (such as CURVE or IPC permissions)
            or authenticating messages themselves before deserializing.

        Parameters
        ----------
        flags : int
            Any valid flags for :func:`Socket.recv`.

        Returns
        -------
        obj : Python object
            The Python object that arrives as a message.

        Raises
        ------
        ZMQError
            for any of the reasons :func:`~Socket.recv` might fail
        )r  r  r0  loads)r(   r   r  s      r)   
recv_pyobjzSocket.recv_pyobj  s-    8 ii  fl333r+   c                    i }dD ]}||v r|                     |          ||<   t          j        |fi |} | j        |fd|i|S )a+  Send a Python object as a message using json to serialize.

        Keyword arguments are passed on to json.dumps

        Parameters
        ----------
        obj : Python object
            The Python object to send
        flags : int
            Any valid flags for :func:`Socket.send`
        r   r   )popr   r1  r   )r(   r-  r   ry   send_kwargsr   r  s          r)   	send_jsonzSocket.send_json  sl     * 	3 	3Cf}}#)::c??C mC**6**ty99E9[999r+   r   c                `    |                      |          }|                     |fd          S )a  Receive a Python object as a message using json to serialize.

        Keyword arguments are passed on to json.loads

        Parameters
        ----------
        flags : int
            Any valid flags for :func:`Socket.recv`.

        Returns
        -------
        obj : Python object
            The Python object that arrives as a message.

        Raises
        ------
        ZMQError
            for any of the reasons :func:`~Socket.recv` might fail
        c                (    t          j        | fi S r3   )r   r4  )r)  ry   s    r)   r*  z"Socket.recv_json.<locals>.<lambda>  s    '-2N2Nv2N2N r+   r+  )r(   r   ry   r  s     ` r)   	recv_jsonzSocket.recv_json  s6    ( ii  &N&N&N&NOOOr+   timeoutc                   | j         rt          t          j                  |                                 }|                    | |           t          |                    |                    }|                    | d          S )aZ  Poll the socket for events.

        See :class:`Poller` to wait for multiple sockets at once.

        Parameters
        ----------
        timeout : int
            The timeout (in milliseconds) to wait for an event. If unspecified
            (or specified None), will wait forever for an event.
        flags : int
            default: POLLIN.
            POLLIN, POLLOUT, or POLLIN|POLLOUT. The event flags to poll for.

        Returns
        -------
        event_mask : int
            The poll event mask (POLLIN, POLLOUT),
            0 if the timeout was reached without an event.
        r   )	r6   r   rU   ENOTSUP_poller_classregisterdictpollr\   )r(   r=  r   pevtss        r)   rC  zSocket.poll  sn    * ; 	(3;'''  	

4AFF7OO$$xxa   r+   eventsc                   t          j                    dk     r#t          dt          j                               | j        r| j        j        rd| _        n| j        S |
d| j         }|t           j        }|                     ||           | j	        
                    t           j                  | _        | j                            |           | j        S )a  Return a connected PAIR socket ready to receive the event notifications.

        .. versionadded:: libzmq-4.0
        .. versionadded:: 14.0

        Parameters
        ----------
        events : int
            default: `zmq.EVENT_ALL`
            The bitmask defining which events are wanted.
        addr : str
            The optional endpoint for the monitoring sockets.

        Returns
        -------
        socket : zmq.Socket
            The PAIR socket, connected and ready to receive messages.
        )   z.get_monitor_socket requires libzmq >= 4, have Nzinproc://monitor.s-)rU   zmq_version_infoNotImplementedErrorzmq_version_monitor_socketr6   r   	EVENT_ALLmonitorrX   r!   PAIRr/   )r(   rF  r$   s      r)   get_monitor_socketzSocket.get_monitor_socket*  s    , !!D((%TARARTT  
  	,#* ,'+$$++<222D>]FT6"""#|2238<<$$T***##r+   c                @    d| _         |                     dd           dS )zShutdown the PAIR socket (created using get_monitor_socket)
        that is serving socket events.

        .. versionadded:: 14.4
        Nr   )rL  rN  r'   s    r)   disable_monitorzSocket.disable_monitorY  s&      $T1r+   )r(   rE   rF   rG   rH   rI   rD   rJ   )r(   rE   rL   rM   rD   rJ   )r(   rE   rF   r   )Nr   )
r(   rE   rF   rQ   rH   rI   rL   rM   rD   rJ   )r(   r   r1   r   r3   )rv   r}   r~   r   r1   r   )r1   r   )r(   r   r$   r"   r1   r,   )r1   rI   )r   r   r1   r   )r   )r   rI   r   r"   r1   r   )r   rI   r1   r"   )r   r   r   )r(   r   r$   r"   r   rI   r   rI   r   rI   r1   rI   )r   rI   r1   r   )..)r   r   r   rI   r   r   r   r   r   rJ   r   r   r1   r   )r   r   r   rI   r   r   r   r   r   rJ   r   r   r1   r   ).)r   r   r   rI   r   r   r   rJ   r   r   r1   r   ).....)r   r   r   rI   r   r   r   r   r   rJ   r   r   r1   r   )r   TFNN)r   TF)r   r	   r   rI   r   r   r   r   )r   rI   r   r   r   r   r1   r  )r   rI   r   r   r   r   r1   r
  )r   rI   r   r   r1   r  )r   rI   r   r   r   r   r1   r  )r  r   r  r  r1   r   )r   T)r   Tr   )
r#  r"   r   rI   r   r   r   r"   r1   r$  )r   r   )r   rI   r   r"   r1   r"   )r-  r   r   rI   r.  rI   r1   r$  )r   )r   rI   r1   r   )r-  r   r   rI   r1   r   )r   rI   r1   r   )r=  rJ   r   rI   r1   rI   )NN)r(   r   rF  rJ   r$   r   r1   r   )Er;   r<   r=   r>   rV   rW   rL  r`   r   r0   rl   rn   r*   r4   r:   r|   __deepcopy__classmethodrL   rk   r   r   r.   r/   propertyrH   r   
SocketBaser   
setsockoptr\   r  r   r   r   r   r   setsockopt_unicodesetsockopt_stringr   getsockopt_unicodegetsockopt_stringr   r   r   hwmr   r  r	  r  r  r"  r&  send_unicoder,  recv_unicodeDEFAULT_PROTOCOLr2  r5  r9  r<  r   r@  rU   POLLINrC  rP  rR  __classcell__)rf   s   @r)   r   r   P   s        , GKOJ &*     X 
 &*	     X    X 6:3-
  !%)3- 3- 3- 3- 3- 3- 3- 3-j
 
 
 I	R 	R 	R     6 6 6 6 6 L# # # [#% % % % % % %25 5 5 52 2 2 2!# !# !# !# !# !#F& & & & & &< $ $ $ X$   JJ( ( ( ( ( 	 	 	 		' 	' 	' 	'	) 	) 	) 	)9 9 9 9 9* .87*> > > > >& .87*
 6D 6D 6D 6D 6Dp/ / / /   0 (			 	C  		! "%	! 	! 	! 	! 	! X	!  		 "%	 	 	 	 	 X	  
 !$     X  !$( ( ( ( X( !% KG KG KG KG KG KG KG` 3G 3G 3G 3G 3Gj FI     X GJ     X XXXXXX XX?D, , , , X,
 @E#@ #@ #@ #@ #@J   ,M M M M*6 6 6 6@ O O O O O4 LH H H H H. L &'8H5 5 5 5 584 4 4 4 4>: : : : :&P P P P P. M)-CJ ! ! ! ! !> JN-$ -$ -$ -$ -$^       r+   
SyncSocket)4r>   
__future__r   r   r0  r   r   typingr   r   r   r   r   r	   r
   r   r   r   warningsr   rU   zmq._typingr   zmq.backendr   rV  	zmq.errorr   r   	zmq.utilsr   zmq.utils.interopr   	constantsr   r   r   	attrsettrr   rC  r   r_  rZ   HIGHEST_PROTOCOLr   r   r?   r    rA   r   rb  __all__r@   r+   r)   <module>ro     s   % % %
 # " " " " "    



                              



 ! ! ! ! ! ! , , , , , , , , , , , , , ,       + + + + + + : : : : : : : : : : & & & & & &      /. / / /./ gm8444R	 R R R R. . . . .W[) . . .< 7-.. P P P P PZ'2B*C P P Pf  u
 % % % %\
"s   3A; ;B
	B
