
    )Jf                         d Z ddlZddlmZ ddlmZmZ ddlmZ  ej	        e
          Z G d dej                  ZdS )z"Use pika with the Tornado IOLoop

    N)ioloop)nbio_interfaceselector_ioloop_adapter)base_connectionc                   L     e Zd ZdZ	 	 	 	 	 	 d fd	Ze	 	 dd            Z xZS )TornadoConnectionz6The TornadoConnection runs on the Tornado IOLoop.
    NTc                    t          |t          j                  r|}n2t          j        |pt
          j                                                  }t          t          |           
                    ||||||           dS )a   Create a new instance of the TornadoConnection class, connecting
        to RabbitMQ automatically.

        :param pika.connection.Parameters|None parameters: The connection
            parameters
        :param callable|None on_open_callback: The method to call when the
            connection is open
        :param callable|None on_open_error_callback: Called if the connection
            can't be established or connection establishment is interrupted by
            `Connection.close()`:
            on_open_error_callback(Connection, exception)
        :param callable|None on_close_callback: Called when a previously fully
            open connection is closed:
            `on_close_callback(Connection, exception)`, where `exception` is
            either an instance of `exceptions.ConnectionClosed` if closed by
            user or broker or exception of another type that describes the
            cause of connection failure
        :param ioloop.IOLoop|nbio_interface.AbstractIOServices|None custom_ioloop:
            Override using the global IOLoop in Tornado
        :param bool internal_connection_workflow: True for autonomous connection
            establishment which is default; False for externally-managed
            connection workflow via the `create_connection()` factory

        )internal_connection_workflowN)
isinstancer   AbstractIOServicesr   SelectorIOServicesAdapterr   IOLoopinstancesuperr   __init__)	self
parameterson_open_callbackon_open_error_callbackon_close_callbackcustom_ioloopr
   nbio	__class__s	           c/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/pika/adapters/tornado_connection.pyr   zTornadoConnection.__init__   s    > m^%FGG 	< DD+E9!7!7!9!9; ;D&&//")E 	0 	G 	G 	G 	G 	G    c                      t          j        |pt          j                                                   fd}                     ||||          S )z`Implement
        :py:classmethod::`pika.adapters.BaseConnection.create_connection()`.

        c                 B    | t          d           | d          S )zConnection factory.NzIExpected pika.connection.Parameters instance, but got None in params arg.F)r   r   r
   )
ValueError)paramsclsr   s    r   connection_factoryz?TornadoConnection.create_connection.<locals>.connection_factoryK   sE    ~  "I J J J3!"-24 4 4 4r   )connection_configsr!   r   workflowon_done)r   r   r   r   r   _start_connection_workflow)r    r"   r$   r   r#   r!   r   s   `     @r   create_connectionz#TornadoConnection.create_connection>   sz     '@5V]33557 7	4 	4 	4 	4 	4 	4 --11 .   	r   )NNNNNT)NN)__name__
__module____qualname____doc__r   classmethodr&   __classcell__)r   s   @r   r   r      s          !"&(,#'#.2*G *G *G *G *G *GX  )-#'	   [    r   r   )r*   loggingtornador   pika.adapters.utilsr   r   pika.adaptersr   	getLoggerr'   LOGGERBaseConnectionr    r   r   <module>r5      s            G G G G G G G G ) ) ) ) ) )		8	$	$L L L L L6 L L L L Lr   