
    )Jf$                     j   d Z ddlZddlZddlZddlmZ ddlmZmZ  ej	        e
          Zej        dk    r ej         ej                                G d dej                  Z G d d	ej        ej        ej        ej                  Z G d
 dej                  Z G d dej                  ZdS )z#Use pika with the Asyncio EventLoop    N)base_connection)nbio_interfaceio_services_utilswin32c                   L     e Zd ZdZ	 	 	 	 	 	 d fd	Ze	 	 dd            Z xZS )AsyncioConnectionz; The AsyncioConnection runs on the Asyncio EventLoop.

    NTc                     t          |t          j                  r|}nt          |          }t	                                          ||||||           dS )a   Create a new instance of the AsyncioConnection class, connecting
        to RabbitMQ automatically

        :param pika.connection.Parameters parameters: Connection parameters
        :param callable on_open_callback: The method to call when the connection
            is open
        :param None | method 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 None | method 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 None | asyncio.AbstractEventLoop |
            nbio_interface.AbstractIOServices custom_ioloop:
                Defaults to asyncio.get_event_loop().
        :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   AbstractIOServices_AsyncioIOServicesAdaptersuper__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/asyncio_connection.pyr   zAsyncioConnection.__init__   sp    < m^%FGG 	< DD,];;D")E 	 	G 	G 	G 	G 	G    c                 d     t          |           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?AsyncioConnection.create_connection.<locals>.connection_factoryM   sE    ~  "I J J J3!"-24 4 4 4r   )connection_configsr   r   workflowon_done)r   _start_connection_workflow)r   r    r"   r   r!   r   r   s   `     @r   create_connectionz#AsyncioConnection.create_connectionA   s_     )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V  )-#'	   [    r   r   c                   l    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
	 	 	 	 ddZd Zd Zd Zd Zd ZdS )r   zImplements
    :py:class:`.utils.nbio_interface.AbstractIOServices` interface
    on top of `asyncio`.

    NOTE:
    :py:class:`.utils.nbio_interface.AbstractFileDescriptorServices`
    interface is only required by the mixins.

    Nc                 :    |pt          j                    | _        dS )z{
        :param asyncio.AbstractEventLoop | None loop: If None, gets default
            event loop from asyncio.

        N)asyncioget_event_loop_loop)r   loops     r   r   z"_AsyncioIOServicesAdapter.__init__m   s     5W355


r   c                     | j         S )zdImplement
        :py:meth:`.utils.nbio_interface.AbstractIOServices.get_native_ioloop()`.

        )r/   r   s    r   get_native_ioloopz+_AsyncioIOServicesAdapter.get_native_ioloopu   s    
 zr   c                 8    | j                                          dS )zXImplement
        :py:meth:`.utils.nbio_interface.AbstractIOServices.close()`.

        N)r/   closer2   s    r   r5   z_AsyncioIOServicesAdapter.close|   s    
 	
r   c                 8    | j                                          dS )zNImplement :py:meth:`.utils.nbio_interface.AbstractIOServices.run()`.

        N)r/   run_foreverr2   s    r   runz_AsyncioIOServicesAdapter.run   s     	
     r   c                 8    | j                                          dS )zOImplement :py:meth:`.utils.nbio_interface.AbstractIOServices.stop()`.

        N)r/   stopr2   s    r   r:   z_AsyncioIOServicesAdapter.stop   s     	
r   c                 :    | j                             |           dS )zjImplement
        :py:meth:`.utils.nbio_interface.AbstractIOServices.add_callback_threadsafe()`.

        N)r/   call_soon_threadsafe)r   callbacks     r   add_callback_threadsafez1_AsyncioIOServicesAdapter.add_callback_threadsafe   s     
 	
''11111r   c                 R    t          | j                            ||                    S )z]Implement
        :py:meth:`.utils.nbio_interface.AbstractIOServices.call_later()`.

        )_TimerHandler/   
call_later)r   delayr=   s      r   rA   z$_AsyncioIOServicesAdapter.call_later   s$    
 DJ11%BBCCCr   r   c           
      j    |                      | j                            ||||||          |          S )z^Implement
        :py:meth:`.utils.nbio_interface.AbstractIOServices.getaddrinfo()`.

        )familytypeprotoflags)_schedule_and_wrap_in_io_refr/   getaddrinfo)r   hostportr"   rD   socktyperF   rG   s           r   rI   z%_AsyncioIOServicesAdapter.getaddrinfo   sM     00J"" #   &' ' 	'r   c                 r    | j                             ||           t                              d|           dS )ziImplement
        :py:meth:`.utils.nbio_interface.AbstractFileDescriptorServices.set_reader()`.

        zset_reader(%s, _)N)r/   
add_readerLOGGERdebug)r   fdon_readables      r   
set_readerz$_AsyncioIOServicesAdapter.set_reader   7    
 	
b+...("-----r   c                 l    t                               d|           | j                            |          S )zlImplement
        :py:meth:`.utils.nbio_interface.AbstractFileDescriptorServices.remove_reader()`.

        zremove_reader(%s))rO   rP   r/   remove_readerr   rQ   s     r   rV   z'_AsyncioIOServicesAdapter.remove_reader   /    
 	("---z''+++r   c                 r    | j                             ||           t                              d|           dS )ziImplement
        :py:meth:`.utils.nbio_interface.AbstractFileDescriptorServices.set_writer()`.

        zset_writer(%s, _)N)r/   
add_writerrO   rP   )r   rQ   on_writables      r   
set_writerz$_AsyncioIOServicesAdapter.set_writer   rT   r   c                 l    t                               d|           | j                            |          S )zlImplement
        :py:meth:`.utils.nbio_interface.AbstractFileDescriptorServices.remove_writer()`.

        zremove_writer(%s))rO   rP   r/   remove_writerrW   s     r   r^   z'_AsyncioIOServicesAdapter.remove_writer   rX   r   c                     t          |          s"t          d                    |                    t          t	          j        || j                  |          S )a  Schedule the coroutine to run and return _AsyncioIOReference

        :param coroutine-obj coro:
        :param callable on_done: user callback that takes the completion result
            or exception as its only arg. It will not be called if the operation
            was cancelled.
        :rtype: _AsyncioIOReference which is derived from
            nbio_interface.AbstractIOReference

        *on_done arg must be callable, but got {!r})r0   )callable	TypeErrorformat_AsyncioIOReferencer-   ensure_futurer/   )r   coror"   s      r   rH   z6_AsyncioIOServicesAdapter._schedule_and_wrap_in_io_ref   si        	N<CCGLLN N N #!$TZ888'C C 	Cr   N)r   r   r   r   )r%   r&   r'   r(   r   r3   r5   r8   r:   r>   rA   rI   rS   rV   r\   r^   rH    r   r   r   r   _   s        6 6 6 6    ! ! !  2 2 2D D D ' ' ' '*. . ., , ,. . ., , ,C C C C Cr   r   c                       e Zd ZdZd Zd ZdS )r@   zJThis module's adaptation of `nbio_interface.AbstractTimerReference`.

    c                     || _         dS )z0

        :param asyncio.Handle handle:
        N)_handle)r   handles     r   r   z_TimerHandle.__init__   s    
 r   c                 X    | j         "| j                                          d | _         d S d S rg   )rk   cancelr2   s    r   rn   z_TimerHandle.cancel   s1    <#L!!!DLLL $#r   Nr%   r&   r'   r(   r   rn   rh   r   r   r@   r@      s<                    r   r@   c                       e Zd ZdZd Zd ZdS )rd   zGThis module's adaptation of `nbio_interface.AbstractIOReference`.

    c                     t                    s"t          d                                        || _        fd}|                    |           dS )z
        :param asyncio.Future future:
        :param callable on_done: user callback that takes the completion result
            or exception as its only arg. It will not be called if the operation
            was cancelled.

        r`   c                     |                                  s3 |                                 p|                                            dS dS )z3Handle completion callback from the future instanceN)	cancelled	exceptionresult)futurer"   s    r   on_done_adapterz5_AsyncioIOReference.__init__.<locals>.on_done_adapter
  sR    
 ##%% ?((**=fmmoo>>>>>? ?r   N)ra   rb   rc   _futureadd_done_callback)r   rv   r"   rw   s     ` r   r   z_AsyncioIOReference.__init__   sz        	N<CCGLLN N N 	? 	? 	? 	? 	? 	  11111r   c                 4    | j                                         S )zCancel pending operation

        :returns: False if was already done or cancelled; True otherwise
        :rtype: bool

        )rx   rn   r2   s    r   rn   z_AsyncioIOReference.cancel  s     |""$$$r   Nro   rh   r   r   rd   rd      s<         2 2 20% % % % %r   rd   )r(   r-   loggingsyspika.adaptersr   pika.adapters.utilsr   r   	getLoggerr%   rO   platformset_event_loop_policyWindowsSelectorEventLoopPolicyBaseConnectionr   SocketConnectionMixinStreamingConnectionMixinr   AbstractFileDescriptorServicesr   AbstractTimerReferencer@   AbstractIOReferencerd   rh   r   r   <module>r      s{   ) )   



 ) ) ) ) ) ) A A A A A A A A		8	$	$ <7!G!"H'"H"J"JKKKK K K K K6 K K K\CC CC CC CC CC 1 G 1 J . A . MCC CC CCL         >8      $$% $% $% $% $%.< $% $% $% $% $%r   