
    2Bf                     Z    d dl Z d dlZ	 d dlZddlmZ  G d de      Zy# e$ r dZY w xY w)    N   )PubSubManagerc                   d     e Zd ZdZdZ	 	 	 	 d fd	Z fdZd Zd Zd Z	d Z
d	 Zd
 Zd Z xZS )KombuManagera  Client manager that uses kombu for inter-process messaging.

    This class implements a client manager backend for event sharing across
    multiple processes, using RabbitMQ, Redis or any other messaging mechanism
    supported by `kombu <http://kombu.readthedocs.org/en/latest/>`_.

    To use a kombu backend, initialize the :class:`Server` instance as
    follows::

        url = 'amqp://user:password@hostname:port//'
        server = socketio.Server(client_manager=socketio.KombuManager(url))

    :param url: The connection URL for the backend messaging queue. Example
                connection URLs are ``'amqp://guest:guest@localhost:5672//'``
                and ``'redis://localhost:6379/'`` for RabbitMQ and Redis
                respectively. Consult the `kombu documentation
                <http://kombu.readthedocs.org/en/latest/userguide                /connections.html#urls>`_ for more on how to construct
                connection URLs.
    :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.
    :param connection_options: additional keyword arguments to be passed to
                               ``kombu.Connection()``.
    :param exchange_options: additional keyword arguments to be passed to
                             ``kombu.Exchange()``.
    :param queue_options: additional keyword arguments to be passed to
                          ``kombu.Queue()``.
    :param producer_options: additional keyword arguments to be passed to
                             ``kombu.Producer()``.
    kombuc	                     t         t        d      t        t        |   |||       || _        |xs i | _        |xs i | _        |xs i | _        |xs i | _	        | j                         | _        y )NzLKombu package is not installed (Run "pip install kombu" in your virtualenv).)channel
write_onlylogger)r   RuntimeErrorsuperr   __init__urlconnection_optionsexchange_optionsqueue_optionsproducer_options	_producerproducer)
selfr   r	   r
   r   r   r   r   r   	__class__s
            V/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/socketio/kombu_manager.pyr   zKombuManager.__init__0   s     =  . / / 	lD*76@28 	+ 	: "4": 0 6B*0b 0 6B(    c                    t         t        |           d}| j                  j                  dk(  rddlm}  |d      }n&d| j                  j                  v rddlm}  |d      }|s"t        d| j                  j                  z         y )	NTeventletr   )is_monkey_patchedsocketgevent)is_module_patchedz<Kombu requires a monkey patched socket library to work with )
r   r   
initializeserver
async_modeeventlet.patcherr   gevent.monkeyr   r   )r   monkey_patchedr   r   r   s       r   r    zKombuManager.initializeB   s    lD,.;;!!Z/:.x8N///7.x8N++0012 2 r   c                 V    t        j                  | j                  fi | j                  S )N)r   
Connectionr   r   r   s    r   _connectionzKombuManager._connectionQ   s"    DD,C,CDDr   c                     ddd}|j                  | j                         t        j                  | j                  fi |S )NfanoutF)typedurable)updater   r   Exchanger	   )r   optionss     r   	_exchangezKombuManager._exchangeT   s6    #6t,,-~~dll6g66r   c                     dt        t        j                               z   }dddid}|j                  | j                         t        j                  || j                         fi |S )Nzflask-socketio.Fz	x-expiresi )r-   queue_arguments)struuiduuid4r.   r   r   Queuer1   )r   
queue_namer0   s      r   _queuezKombuManager._queueY   sU    &TZZ\)::
#f8MNt))*{{:t~~'7C7CCr   c                 v     | j                         j                  dd| j                         i| j                  S )Nexchange )r)   Producerr1   r   r(   s    r   r   zKombuManager._producer_   s@    *t!** DDNN4D D-1-B-BD 	Dr   c                 `    | j                         j                  dj                  |             y )NzSleeping {}s)_get_logger	exceptionformat)r   r@   intervals      r   __error_callbackzKombuManager.__error_callbackc   s$    $$^%:%:8%DEr   c                     | j                         }|j                  | j                  | j                  j                  | j                        } |t        j                  |             y )Nerrback)r)   ensurer   publish_KombuManager__error_callbackpickledumps)r   data
connectionrH   s       r   _publishzKombuManager._publishf   sR    %%'
##DMM4==3H3H,0,A,A $ CT"#r   c              #     K   | j                         }	 | j                         j                  | j                        }	 |j	                  |      5 }	 |j                  d      }|j                          |j                   1# 1 sw Y   nxY wn4# |j                  $ r" | j                         j                  d       Y nw xY ww)NTrE   )blockz)Connection error while reading from queue)r9   r)   ensure_connectionrI   SimpleQueuegetackpayloadconnection_errorsr?   r@   )r   reader_queuerM   queuemessages        r   _listenzKombuManager._listenl   s     {{}))+==-- > /JI++L9 .U"'))$)"7%oo- . . .
 // I  ",, .H II s:   <CB 3BBB C.C>C CC)z#amqp://guest:guest@localhost:5672//socketioFNNNNN)__name__
__module____qualname____doc__namer   r    r)   r1   r9   r   rI   rN   rZ   __classcell__)r   s   @r   r   r      sN     B D@>B;?6:)$2E7
DDF$Ir   r   )rJ   r5   r   ImportErrorpubsub_managerr   r   r<   r   r   <module>rd      s>      *nI= nI  Es     **