
    !ni                     :    d dl Z d dlmZ ddlmZ  G d de      Zy)    N)json   )PubSubManagerc                   B     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 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())
    zmqc                    	 ddl m} t	        j
                  d      }|j                  d      r|j                  |      st        d|z         t        | %  |||       |j                  dd	      }|j                  d
      \  }}|j                  d      d   }	|j                  |	|      }
|j                         j                  |j                        }|j                  |       |j                         j                  |j                         }|j#                  |j$                  d	       |j                  |
       || _        || _        || _        y # t        $ r t        d      w xY w)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loggerz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sink_urlsub_port	sink_portsub_urlr#   r$   	__class__s                T/home/homepc/tiktok-worker/venv/lib/python3.12/site-packages/socketio/zmq_manager.pyr   zZmqManager.__init__-   s5   	/* JJ}%|,#?#EFFZOkk&"%"yy~8NN3'+	""9h7{{}##CHH-Xkkm""377+cmmR0G	1  	/  . / /	/s   E E'c                     t        j                  d| j                  |d      j                         }| j                  j                  |      S )Nmessage)typer
   data)r   dumpsr
   encoder#   send)r%   r1   packed_datas      r-   _publishzZmqManager._publishM   sC    jj!<<
 &( 	 yy~~k**    c              #   N   K   	 | j                   j                         }|| !w)N)r$   recv)r%   responses     r-   
zmq_listenzZmqManager.zmq_listenW   s(     xx}}H# s   #%c              #     K   | j                         D ]a  }t        |t              r	 t        j                  |      }t        |t              s:|d   dk(  sC|d   | j                  k(  sVd|v s[|d    c y # t
        $ r Y Gw xY ww)Nr0   r/   r
   r1   )r;   
isinstancebytesr   loads	Exceptiondictr
   )r%   r/   s     r-   _listenzZmqManager._listen]   s     ( 
	&G'5)"jj1G '4(FOy0I&$,,6g%fo%
	& 	 ! s?   $BA8BBB)B.
B8	BBBB)zzmq+tcp://localhost:5555+5556socketioFN)
__name__
__module____qualname____doc__namer   r6   r;   rB   __classcell__)r,   s   @r-   r   r      s1    "F D:#!@+r7   r   )r   engineior   pubsub_managerr   r    r7   r-   <module>rM      s    	  )b br7   