Ë
    >Øïi$  ã                   óª  — 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j0                  «      Zy)z#Use pika with the Asyncio EventLoopé    N)Úbase_connection)Únbio_interfaceÚio_services_utilsÚwin32c                   óF   ‡ — 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.

    c                 ó€   •— t        |t        j                  «      r|}nt        |«      }t        ‰| �  ||||||¬«       y)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	           €úZ/var/www/html/aiagents/fe/lib/python3.12/site-packages/pika/adapters/asyncio_connection.pyr   zAsyncioConnection.__init__   sI   ø€ ô< �m¤^×%FÑ%FÔGØ ‰Dä,¨]Ó;ˆDä‰ÑØØØ"ØØØ)Eð 	õ 	Gó    c                 óT   ‡ ‡— t        |«      Šˆ ˆfd„}‰ j                  ||‰||¬«      S )z`Implement
        :py:classmethod::`pika.adapters.BaseConnection.create_connection()`.

        c                 ó4   •— | €t        d«      ‚ ‰| ‰d¬«      S )zConnection factory.zIExpected 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   s3   ø€ àˆ~Ü ð "Ió Jð JáØ!Ø"Ø-2ô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ˆõ	4ð ×-Ñ-Ø1Ø1ØØØð .ó ð 	r   )NNNNNT)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr$   Ú__classcell__)r   s   @r   r   r      s?   ø„ ñð
 !Ø"&Ø(,Ø#'Ø#Ø.2õ)GðV ð )-Ø#'ò	ó ôr   r   c                   ój   — 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y)r   zêImplements
    :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                 ó>   — |xs t        j                  «       | _        y)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   € ð Ò5œW×3Ñ3Ó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‰zÐr   c                 ó8   — | j                   j                  «        y)zXImplement
        :py:meth:`.utils.nbio_interface.AbstractIOServices.close()`.

        N)r/   Úcloser2   s    r   r5   z_AsyncioIOServicesAdapter.close|   s   € ð
 	�
‰
×ÑÕr   c                 ó8   — | j                   j                  «        y)zNImplement :py:meth:`.utils.nbio_interface.AbstractIOServices.run()`.

        N)r/   Úrun_foreverr2   s    r   Úrunz_AsyncioIOServicesAdapter.runƒ   s   € ð 	�
‰
×ÑÕ r   c                 ó8   — | j                   j                  «        y)zOImplement :py:meth:`.utils.nbio_interface.AbstractIOServices.stop()`.

        N)r/   Ústopr2   s    r   r:   z_AsyncioIOServicesAdapter.stop‰   s   € ð 	�
‰
�‰Õr   c                 ó:   — | j                   j                  |«       y)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   € ð
 	�
‰
×'Ñ'¨Õ1r   c                 óL   — t        | j                  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    € ô
 ˜DŸJ™J×1Ñ1°%¸ÓBÓCÐCr   c           
      ód   — | j                  | 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�   sE   € ð ×0Ñ0Ø�J‰J×"Ñ"ØØØØØØð #ó ð &ó'ð 	'r   c                 óh   — | j                   j                  ||«       t        j                  d|«       y)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²   ó'   € ð
 	�
‰
×Ñ˜b +Ô.Ü�‰Ð(¨"Õ-r   c                 ód   — t         j                  d|«       | j                  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‰z×'Ñ'¨Ó+Ð+r   c                 óh   — | j                   j                  ||«       t        j                  d|«       y)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                 ód   — t         j                  d|«       | j                  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j                  |«      «      ‚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Ò   sP   € ô ˜Ô ÜØ<×CÑCÀGÓLóNð Nô #Ü×!Ñ! $¨T¯Z©ZÔ8¸'ó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   _   sX   „ ñó6òòò!òò2òDð ØØØó'ò*.ò,ò.ò,óCr   r   c                   ó   — e Zd ZdZd„ Zd„ Zy)r@   zJThis module's adaptation of `nbio_interface.AbstractTimerReference`.

    c                 ó   — || _         y)z0

        :param asyncio.Handle handle:
        N)Ú_handle)r   Úhandles     r   r   z_TimerHandle.__init__ê   s   € ð
 ˆ�r   c                 ó`   — | j                   �"| j                   j                  «        d | _         y y rg   )rk   Úcancelr2   s    r   rn   z_TimerHandle.cancelñ   s(   € Ø�<‰<Ð#Ø�L‰L×ÑÔ!ØˆD�Lð $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y)rd   zGThis module's adaptation of `nbio_interface.AbstractIOReference`.

    c                 óŠ   ‡— t        ‰«      st        dj                  ‰«      «      ‚|| _        ˆfd„}|j	                  |«       y)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                 óx   •— | j                  «       s) ‰| j                  «       xs | j                  «       «       yy)z3Handle completion callback from the future instanceN)Ú	cancelledÚ	exceptionÚresult)Úfuturer"   s    €r   Úon_done_adapterz5_AsyncioIOReference.__init__.<locals>.on_done_adapter
  s2   ø€ ð
 ×#Ñ#Ô%Ù˜×(Ñ(Ó*Ò=¨f¯m©m«oÕ>ð &r   N)ra   rb   rc   Ú_futureÚadd_done_callback)r   rv   r"   rw   s     ` r   r   z_AsyncioIOReference.__init__ü   sH   ø€ ô ˜Ô ÜØ<×CÑCÀGÓLóNð Nð ˆŒô	?ð 	× Ñ  Õ1r   c                 ó6   — | j                   j                  «       S )z�Cancel 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ó0%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à	ˆ×	Ñ	˜8Ó	$€ð ‡<�<�7ÒØ!€G×!Ñ!Ð"H '×"HÑ"HÓ"JÔKôK˜×6Ñ6ô Kô\CCÐ 1× GÑ GØ 1× JÑ JØ .× AÑ AØ .× MÑ MôCCôL �>×8Ñ8ô  ô$$%˜.×<Ñ<õ $%r   