HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib64/python3.6/site-packages/zmq/sugar/__pycache__/socket.cpython-36.opt-1.pyc
3

VS�_;l�@s*dZddlZddlZddlZddlZddlmZddlZddlm	Z
ddlmZddl
mZddlmZdd	lmZmZdd
lmZddlmZmZmZddlmZmZmZmZmZmZm Z yddl!Z!e!Z"WndZ!ddl"Z"YnXy
e"j#Z#Wne$k
�re"j%Z#YnXGd
d�de
e�Z	dgZ&dS)z0MQ Socket pure Python methods.�N)�contextmanager)�Socket�)�Poller)�	constants)�AttributeSetter)�ZMQError�ZMQBindError)�jsonapi)�bytes�unicode�
basestring)�SNDMORE�ENOTSUP�POLLIN�int64_sockopt_names�int_sockopt_names�bytes_sockopt_names�fd_sockopt_namescs�eZdZdZdZdZ�fdd�Zdd�Zdd	�Zd
d�Z	dUdd
�Z
e
Zedd��Z
dV�fdd�	Zedd��Zedd��Z�fdd�Z�fdd�Zedd��Zdd�ZejZejZ�fdd�Zd d!�Zd"d#�Zd$d%�ZdWd'd(�Z e Z!Z"dXd)d*�Z#e#Z$Z%dYd.d/�Z&d0d1�Z'd2d3�Z(ee'e(d4�Z)dZ�fd7d8�	Z*d[d9d:�Z+d\d;d<�Z,d=d>�Z-d]d?d@�Z.d^dAdB�Z/d_dCdD�Z0e0Z1d`dEdF�Z2e2Z3d5e4fdGdH�Z5dadIdJ�Z6dbdKdL�Z7dcdMdN�Z8e9Z:de;fdOdP�Z<dddQdR�Z=dSdT�Z>�Z?S)erz�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)

    FNcs,tt|�j||�d|kr"d|_nd|_dS)N�shadowTF)�superr�__init__�_shadow)�self�a�kw)�	__class__��/usr/lib64/python3.6/socket.pyr;szSocket.__init__cCs|js|j�dS)N)r�close)rrrr�__del__BszSocket.__del__cCs|S)zMSockets are context managers
        
        .. versionadded:: 14.4
        r)rrrr�	__enter__GszSocket.__enter__cOs|j�dS)N)r)r�args�kwargsrrr�__exit__NszSocket.__exit__cCs|jj|j�S)z&Copying a Socket creates a shadow copy)rrZ
underlying)r�memorrr�__copy__UszSocket.__copy__cCsddlm}||�}||d�S)z�Shadow an existing libzmq socket

        address is the integer address of the libzmq socket
        or an FFI pointer to it.

        .. versionadded:: 14.1
        r)�
cast_int_addr)r)Zzmq.utils.interopr')�clsZaddressr'rrrr[s	z
Socket.shadowcs(|jr|jj|�tt|�j|d�dS)a8
        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.
        )�lingerN)�contextZ
_rm_socketrrr)rr))rrrrhszSocket.closeccsz
dVWd|j|�XdS)zVContext manager to disconnect on exit
        
        .. versionadded:: 20.0
        N)Z
disconnect)r�addrrrr�_connect_cm�s
zSocket._connect_cmccsz
dVWd|j|�XdS)zRContext manager to unbind on exit
        
        .. versionadded:: 20.0
        N)Zunbind)rr+rrr�_bind_cm�s
zSocket._bind_cmcst�j|�|j|�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.

        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.
            
        )r�bindr-)rr+)rrrr.�szSocket.bindcst�j|�|j|�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, upd, pgm, inproc and ipc. If the address is unicode, it is
            encoded to utf-8 first.
            
        )r�connectr,)rr+)rrrr/�szSocket.connectcCstjdt�|jS)Nz1Socket.socket_type is deprecated, use Socket.type)�warnings�warn�DeprecationWarning�type)rrrr�socket_type�szSocket.socket_typecCs.t|j�}xttttfD]}|j|�qW|S)N)�dirrrrrr�extend)r�keysZ
collectionrrr�__dir__�s

zSocket.__dir__cs�||jkrtj|||�dS|j�}|dkrjt|t�r@|jd�}|dkrX|jtj	|�n|jtj
|�dStt|�j||�dS)zROverride to allow setting zmq.[UN]SUBSCRIBE even though we have a subscribe methodN�	subscribe�unsubscribe�utf8)r9r:)
�__dict__�object�__setattr__�lower�
isinstancer�encode�set�zmq�	SUBSCRIBE�UNSUBSCRIBErr)r�key�valueZ_key)rrrr>�s


zSocket.__setattr__cCs|jS)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
        )�FD)rrrr�fileno�s	z
Socket.filenocCs&t|t�r|jd�}|jtj|�dS)z\Subscribe to a topic

        Only for SUB sockets.

        .. versionadded:: 15.3
        r;N)r@rrArBrCrD)r�topicrrrr9s

zSocket.subscribecCs&t|t�r|jd�}|jtj|�dS)z`Unsubscribe from a topic

        Only for SUB sockets.

        .. versionadded:: 15.3
        r;N)r@rrArBrCrE)rrJrrrr:
s

zSocket.unsubscribe�utf-8cCs$t|t�std��|j||j|��S)a4Set 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 : unicode string (unicode on py2, str on py3)
            The value of the option to set.
        encoding : str
            The encoding to be used, default is utf8
        zunicode strings only)r@r�	TypeErrorrBrA)r�optionZoptval�encodingrrr�
set_strings
zSocket.set_stringcCs&|tjkrtd|��|j|�j|�S)aeGet the value of a socket option.

        See the 0MQ documentation for details on specific options.

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

        Returns
        -------
        optval : unicode string (unicode on py2, str on py3)
            The value of the option as a unicode string.
        z0option %i will not return a string to be decoded)rZbytes_sockoptsrL�
getsockopt�decode)rrMrNrrr�
get_string/s
zSocket.get_string����dcCs�ttd�rN|dkrN|dkrN|jd|�|jjdd�}|jdd�\}}t|�Sx�t|�D]|}y"tj	||�}	|jd	||	f�WnPt
k
r�}
z4|
j}|tj
kr�wXntjd
kr�|tjkr�wXn�WYdd}
~
XqXX|	SqXWtd��dS)
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
        Z
LAST_ENDPOINTi�iz%s:*�ascii�replace�:rz%s:%sZwin32Nz%Could not bind socket to random port.)�hasattrrr.Z
last_endpointrQ�rsplit�int�range�randomZ	randranger�errnorCZ
EADDRINUSE�sys�platformZEACCESr	)rr+Zmin_portZmax_portZ	max_triesZurl�_Zport_s�iZportZ	exceptionZenrrr�bind_to_random_portEs$
zSocket.bind_to_random_portcCsTtj�d}|dkrDy|jtj�Stjk
r6YnX|jtj�S|jtj�SdS)usGet the High Water Mark.
        
        On libzmq ≥ 3, this gets SNDHWM if available, otherwise RCVHWM
        r�N)rC�zmq_version_inforPZSNDHWMrZRCVHWM�HWM)r�majorrrr�get_hwmwszSocket.get_hwmcCs�tj�d}|dkr�d}y
||_Wn&tk
rH}z
|}WYdd}~XnXy
||_Wn&tk
rz}z
|}WYdd}~XnX|r�|�n|jtj|�SdS)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.
        rrdN)rCreZsndhwm�	ExceptionZrcvhwm�
setsockoptrf)rrGrgZraised�errr�set_hwm�s

zSocket.set_hwmz�Property for High Water Mark.
        
        Setting hwm sets both SNDHWM and RCVHWM as appropriate.
        It gets SNDHWM if available, otherwise RCVHWM.
        rTcs||dk	r2t|tj�s,tj|||p"d|jd�}||_|dk	rdt|tj�s^tj|||pTd|jd�}||_tt|�j||||d�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 `pending` property will
            be True 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)�track�copy�copy_threshold)�flagsrnrm)	r@rC�Framero�
routing_id�grouprr�send)r�datarprnrmrrrs)rrrrt�s1

zSocket.sendc	Ks�x~t|�D]r\}}t|tjttf�r&q
yt|�Wq
tk
rzt|�}t|�dkrf|dd�d}t	d||f��Yq
Xq
Wx*|dd�D]}|j
|t|B||d�q�W|j
|d|||d�S)	a]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 `pending` property will
            be True until the last send is completed.
        � Nz...z4Frame %i (%s) does not support the buffer interface.r)rnrm���rw)�	enumerater@rCrqr�
memoryviewri�repr�lenrLrtr)	rZ	msg_partsrprnrmr#rb�msgZrmsgrrr�send_multipart�szSocket.send_multipartcCsB|j|||d�g}x*|jtj�r<|j|||d�}|j|�qW|S)a�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
        )rnrm)�recvrPrCZRCVMORE�append)rrprnrm�parts�partrrr�recv_multiparts
zSocket.recv_multipartcCs||�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)rZrecvd�loadrrr�_deserialize>szSocket._deserializecKs ||�}|j|f||d�|��S)aWSend 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.

        )rprn)r})rr|Z	serializerprnr#�framesrrr�send_serializedPszSocket.send_serializedcCs|j||d�}|j||�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
        )rprn)r�r�)rZdeserializerprnr�rrr�recv_serializedeszSocket.recv_serializedcKs0t|t�std��|j|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 (unicode on py2, str on py3) around 0MQ.
        
        Parameters
        ----------
        u : Python unicode string (unicode on py2, str on py3)
            The unicode string to send.
        flags : int, optional
            Any valid flags for :func:`Socket.send`.
        encoding : str [default: 'utf-8']
            The encoding to be used
        zunicode/str objects only)rprn)r@r
rLrtrA)r�urprnrNr#rrr�send_string�s
zSocket.send_stringcs |j|d�}|j|�fdd��S)a
Receive a unicode string, as sent by send_string.
    
        Parameters
        ----------
        flags : int
            Any valid flags for :func:`Socket.recv`.
        encoding : str [default: 'utf-8']
            The encoding to be used

        Returns
        -------
        s : unicode string (unicode on py2, str on py3)
            The Python unicode string that arrives as encoded bytes.

        Raises
        ------
        ZMQError
            for any of the reasons :func:`~Socket.recv` might fail
        )rpcs
|j��S)N)rQ)�buf)rNrr�<lambda>�sz$Socket.recv_string.<locals>.<lambda>)r~r�)rrprNr|r)rNr�recv_string�szSocket.recv_stringcKs"tj||�}|j|fd|i|��S)a�Send a Python object as a message using pickle to serialize.

        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.
        rp)�pickle�dumpsrt)r�objrpZprotocolr#r|rrr�
send_pyobj�s
zSocket.send_pyobjcCs|j|�}|j|tj�S)a�Receive a Python object as a message using pickle to serialize.

        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�r��loads)rrpr|rrr�
recv_pyobj�s
zSocket.recv_pyobjcKsLi}x"dD]}||kr
|j|�||<q
Wtj|f|�}|j|fd|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`
        rrrsrp)rrrs)�popr
r�rt)rr�rpr#Zsend_kwargsrFr|rrr�	send_json�s
zSocket.send_jsoncs|j|�}|j|�fdd��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
        cstj|f��S)N)r
r�)r�)r#rrr��sz"Socket.recv_json.<locals>.<lambda>)r~r�)rrpr#r|r)r#r�	recv_json�s
zSocket.recv_jsoncCs<|jrtt��|j�}|j||�t|j|��}|j|d�S)a^Poll the socket for events.
        See :class:`Poller` to wait for multiple sockets at once.

        Parameters
        ----------
        timeout : int [default: None]
            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)�closedrr�
_poller_class�register�dict�poll�get)rZtimeoutrp�pZevtsrrrr�szSocket.pollcCs�tj�dkrtdtj���|jr8|jjr2d|_n|jS|dkrJd|j}|dkrXtj}|j||�|j	j
tj�|_|jj|�|jS)aReturn 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 :  string [default: None]
            The optional endpoint for the monitoring sockets.

        Returns
        -------
        socket :  (PAIR)
            The socket is already connected and ready to receive messages.
        �z0get_monitor_socket requires libzmq >= 4, have %sNzinproc://monitor.s-%d)r�)
rCre�NotImplementedErrorZzmq_version�_monitor_socketr�rHZ	EVENT_ALL�monitorr*ZsocketZPAIRr/)rZeventsr+rrr�get_monitor_sockets
zSocket.get_monitor_socketcCsd|_|jdd�dS)z�Shutdown the PAIR socket (created using get_monitor_socket)
        that is serving socket events.
        
        .. versionadded:: 14.4
        Nr)r�r�)rrrr�disable_monitorGszSocket.disable_monitor)N)N)rK)rK)rSrTrU)rTFNN)rTF)rTF)rT)rT)rTrK)rrK)r)r)r)NN)@�__name__�
__module__�__qualname__�__doc__rr�rr r!r$r&�__deepcopy__�classmethodrrrr,r-r.r/�propertyr4r8�
SocketBaserBrjr�rPr>rIr9r:rOZsetsockopt_unicodeZsetsockopt_stringrRZgetsockopt_unicodeZgetsockopt_stringrcrhrlZhwmrtr}r�r�r�r�r�Zsend_unicoder�Zrecv_unicode�DEFAULT_PROTOCOLr�r�r�r�rr�rr�r�r��
__classcell__rr)rrr,sd




2=
/
"







*r)'r�r^r]r_r0�
contextlibrrCZzmq.backendrr�r�r�rZ	attrsettrrZ	zmq.errorrr	Z	zmq.utilsr
Zzmq.utils.strtypesrrr
rrrrrrrZcPickler�r��AttributeErrorZHIGHEST_PROTOCOL�__all__rrrr�<module>s@$
+