
    i                     6    d dl Z ddlmZ  G d de          ZdS )    N   )PubSubManagerc                   >     e Zd ZdZdZ	 	 d fd	Zd Zd	 Zd
 Z xZ	S )
ZmqManagera  zmq based client manager.

    NOTE: this zmq implementation should be considered experimental at this
    time. At this time, eventlet is required to use zmq.

    This class implements a zmq backend for event sharing across multiple
    processes. To use a zmq backend, initialize the :class:`Server` instance as
    follows::

        url = 'zmq+tcp://hostname:port1+port2'
        server = socketio.Server(client_manager=socketio.ZmqManager(url))

    :param url: The connection URL for the zmq message broker,
                which will need to be provided and running.
    :param channel: The channel name on which the server sends and receives
                    notifications. Must be the same in all the servers.
    :param write_only: If set to ``True``, only initialize to emit events. The
                       default of ``False`` initializes the class for emitting
                       and receiving. A write-only instance can be used
                       independently of the server to emit to clients from an
                       external process.
    :param logger: a custom logger to log it. If not given, the server logger
                   is used.
    :param json: An alternative JSON module to use for encoding and decoding
                 packets. Custom json modules must have ``dumps`` and ``loads``
                 functions that are compatible with the standard library
                 versions. This setting is only used when ``write_only`` is set
                 to ``True``. Otherwise the JSON module configured in the
                 server is used.

    A zmq message broker must be running for the zmq_manager to work.
    you can write your own or adapt one from the following simple broker
    below::

        import zmq

        receiver = zmq.Context().socket(zmq.PULL)
        receiver.bind("tcp://*:5555")

        publisher = zmq.Context().socket(zmq.PUB)
        publisher.bind("tcp://*:5556")

        while True:
            publisher.send(receiver.recv())
    zmqzmq+tcp://localhost:5555+5556socketioFNc                 ^   	 ddl m} n# t          $ r t          d          w xY wt	          j        d          }|                    d          r|                    |          st          d|z             t                      	                    ||||           |
                    dd	          }|                    d
          \  }}	|                    d          d         }
|
                    |
|	          }|                                                    |j                  }|                    |           |                                                    |j                  }|                    |j        d	           |                    |           || _        || _        || _        d S )Nr   )r   zJzmq package is not installed (Run "pip install pyzmq" in your virtualenv).z
:\d+\+\d+$z
zmq+tcp://zunexpected connection string: )channel
write_onlyloggerjsonzzmq+ +:)eventlet.greenr   ImportErrorRuntimeErrorrecompile
startswithsearchsuper__init__replacesplitContextsocketPUSHconnectSUBsetsockopt_string	SUBSCRIBEsinksubr   )selfurlr   r   r   r   r   rsink_urlsub_port	sink_portsub_urlr%   r&   	__class__s                 ?/usr/local/lib/python3.11/dist-packages/socketio/zmq_manager.pyr   zZmqManager.__init__6   s   	/******* 	/ 	/ 	/  . / / /	/
 J}%%|,, 	G# 	G?#EFFFZ" 	 	$ 	$ 	$kk&"%%"yy~~8NN3''+	""9h77{{}}##CH--Xkkmm""37++cmR000G	s   
 $c                     | j                             d| j        |d                                          }| j                            |          S )Nmessage)typer   data)r   dumpsr   encoder%   send)r'   r3   packed_datas      r/   _publishzZmqManager._publishU   sP    ioo!< 
 
 &(( 	 y~~k***    c              #   H   K   	 | j                                         }||V   )N)r&   recv)r'   responses     r/   
zmq_listenzZmqManager.zmq_listen_   s.      	x}}H#	r9   c              #   :  K   |                                  D ]}t          |t                    r,	 | j                            |          }n# t
          $ r Y nw xY wt          |t                    r+|d         dk    r|d         | j        k    rd|v r
|d         V  d S )Nr2   r1   r   r3   )r=   
isinstancebytesr   loads	Exceptiondictr   )r'   r1   s     r/   _listenzZmqManager._listene   s      (( 
	& 
	&G'5)) "ioog66GG    D'4(( &FOy00I&$,66g%%fo%%%s   A


AA)r   r	   FNN)
__name__
__module____qualname____doc__namer   r8   r=   rD   __classcell__)r.   s   @r/   r   r      s        , ,Z DDN59     >+ + +        r9   r   )r   pubsub_managerr   r    r9   r/   <module>rM      s^    				 ) ) ) ) ) )k k k k k k k k k kr9   