§
    ï)JfAC  ã                   ó:  — d Z ddlZddlZ G d„ dej        j        ¦  «        Z G d„ dej        j        ¦  «        Z G d„ dej        j        ¦  «        Z G d	„ d
ej        j        ¦  «        Z	 G d„ dej        j        ¦  «        Z
 G d„ dej        j        ¦  «        ZdS )a  Non-blocking I/O interface for pika connection adapters.

I/O interface expected by `pika.adapters.base_connection.BaseConnection`

NOTE: This API is modeled after asyncio in python3 for a couple of reasons
    1. It's a sensible API
    2. To make it easy to implement at least on top of the built-in asyncio

Furthermore, the API caters to the needs of pika core and lack of generalization
is intentional for the sake of reducing complexity of the implementation and
testing and lessening the maintenance burden.

é    Nc                   óB  — e Zd ZdZej        d„ ¦   «         Zej        d„ ¦   «         Zej        d„ ¦   «         Zej        d„ ¦   «         Z	ej        d„ ¦   «         Z
ej        d„ ¦   «         Zej        	 	 	 	 dd	„¦   «         Zej        d
„ ¦   «         Zej        	 	 dd„¦   «         ZdS )ÚAbstractIOServicesa:  Interface to I/O services required by `pika.adapters.BaseConnection` and
    related utilities.

    NOTE: This is not a public API. Pika users should rely on the native I/O
    loop APIs (e.g., asyncio event loop, tornado ioloop, twisted reactor, etc.)
    that corresponds to the chosen Connection adapter.

    c                 ó   — t           ‚)zrReturns the native I/O loop instance, such as Twisted reactor,
        asyncio's or tornado's event loop

        ©ÚNotImplementedError©Úselfs    úe/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/pika/adapters/utils/nbio_interface.pyÚget_native_ioloopz$AbstractIOServices.get_native_ioloop   ó
   € õ "Ð!ó    c                 ó   — t           ‚)a  Release IOLoop's resources.

        the `close()` method is intended to be called by Pika's own test
        code only after `start()` returns. After calling `close()`, no other
        interaction with the closed instance of `IOLoop` should be performed.

        NOTE: This method is provided for Pika's own test scripts that need to
        be able to run I/O loops generically to test multiple Connection Adapter
        implementations. Pika users should use the native I/O loop's API
        instead.

        r   r   s    r
   ÚclosezAbstractIOServices.close%   ó
   € õ "Ð!r   c                 ó   — t           ‚)a   Run the I/O loop. It will loop until requested to exit. See `stop()`.

        NOTE: the outcome or restarting an instance that had been stopped is
        UNDEFINED!

        NOTE: This method is provided for Pika's own test scripts that need to
        be able to run I/O loops generically to test multiple Connection Adapter
        implementations (not all of the supported I/O Loop frameworks have
        methods named start/stop). Pika users should use the native I/O loop's
        API instead.

        r   r   s    r
   ÚrunzAbstractIOServices.run5   r   r   c                 ó   — t           ‚)aß  Request exit from the ioloop. The loop is NOT guaranteed to
        stop before this method returns.

        NOTE: The outcome of calling `stop()` on a non-running instance is
        UNDEFINED!

        NOTE: This method is provided for Pika's own test scripts that need to
        be able to run I/O loops generically to test multiple Connection Adapter
        implementations (not all of the supported I/O Loop frameworks have
        methods named start/stop). Pika users should use the native I/O loop's
        API instead.

        To invoke `stop()` safely from a thread other than this IOLoop's thread,
        call it via `add_callback_threadsafe`; e.g.,

            `ioloop.add_callback_threadsafe(ioloop.stop)`

        r   r   s    r
   ÚstopzAbstractIOServices.stopE   s
   € õ( "Ð!r   c                 ó   — t           ‚)ao  Requests a call to the given function as soon as possible. It will be
        called from this IOLoop's thread.

        NOTE: This is the only thread-safe method offered by the IOLoop adapter.
              All other manipulations of the IOLoop adapter and objects governed
              by it must be performed from the IOLoop's thread.

        NOTE: if you know that the requester is running on the same thread as
              the connection it is more efficient to use the
              `ioloop.call_later()` method with a delay of 0.

        :param callable callback: The callback method; must be callable.
        r   )r	   Úcallbacks     r
   Úadd_callback_threadsafez*AbstractIOServices.add_callback_threadsafe[   ó
   € õ "Ð!r   c                 ó   — t           ‚)a   Add the callback to the IOLoop timer to be called after delay seconds
        from the time of call on best-effort basis. Returns a handle to the
        timeout.

        If two are scheduled for the same time, it's undefined which one will
        be called first.

        :param float delay: The number of seconds to wait to call callback
        :param callable callback: The callback method
        :returns: A handle that can be used to cancel the request.
        :rtype: AbstractTimerReference

        r   )r	   Údelayr   s      r
   Ú
call_laterzAbstractIOServices.call_laterl   r   r   r   c                 ó   — t           ‚)aÊ  Perform the equivalent of `socket.getaddrinfo()` asynchronously.

        See `socket.getaddrinfo()` for the standard args.

        :param callable on_done: user callback that takes the return value of
            `socket.getaddrinfo()` upon successful completion or exception upon
            failure (check for `BaseException`) as its only arg. It will not be
            called if the operation was cancelled.
        :rtype: AbstractIOReference
        r   )r	   ÚhostÚportÚon_doneÚfamilyÚsocktypeÚprotoÚflagss           r
   ÚgetaddrinfozAbstractIOServices.getaddrinfo}   ó
   € õ& "Ð!r   c                 ó   — t           ‚)a&  Perform the equivalent of `socket.connect()` on a previously-resolved
        address asynchronously.

        IMPLEMENTATION NOTE: Pika's connection logic resolves the addresses
            prior to making socket connections, so we don't need to burden the
            implementations of this method with the extra logic of asynchronous
            DNS resolution. Implementations can use `socket.inet_pton()` to
            verify the address.

        :param socket.socket sock: non-blocking socket that needs to be
            connected via `socket.socket.connect()`
        :param tuple resolved_addr: resolved destination address/port two-tuple
            as per `socket.socket.connect()`, except that the first element must
            be an actual IP address that's consistent with the given socket's
            address family.
        :param callable on_done: user callback that takes None upon successful
            completion or exception (check for `BaseException`) upon error as
            its only arg. It will not be called if the operation was cancelled.

        :rtype: AbstractIOReference
        :raises ValueError: if host portion of `resolved_addr` is not an IP
            address or is inconsistent with the socket's address family as
            validated via `socket.inet_pton()`
        r   )r	   ÚsockÚresolved_addrr   s       r
   Úconnect_socketz!AbstractIOServices.connect_socket’   s
   € õ4 "Ð!r   Nc                 ó   — t           ‚)a¼  Perform SSL session establishment, if requested, on the already-
        connected socket and link the streaming transport/protocol pair.

        NOTE: This method takes ownership of the socket.

        :param callable protocol_factory: called without args, returns an
            instance with the `AbstractStreamProtocol` interface. The protocol's
            `connection_made(transport)` method will be called to link it to
            the transport after remaining connection activity (e.g., SSL session
            establishment), if any, is completed successfully.
        :param socket.socket sock: Already-connected, non-blocking
            `socket.SOCK_STREAM` socket to be used by the transport. We take
            ownership of this socket.
        :param callable on_done: User callback
            `on_done(BaseException | (transport, protocol))` to be notified when
            the asynchronous operation completes. An exception arg indicates
            failure (check for `BaseException`); otherwise the two-tuple will
            contain the linked transport/protocol pair having
            AbstractStreamTransport and AbstractStreamProtocol interfaces
            respectively.
        :param None | ssl.SSLContext ssl_context: if None, this will proceed as
            a plaintext connection; otherwise, if not None, SSL session
            establishment will be performed prior to linking the transport and
            protocol.
        :param str | None server_hostname: For use during SSL session
            establishment to match against the target server's certificate. The
            value `None` disables this check (which is a huge security risk)
        :rtype: AbstractIOReference
        r   )r	   Úprotocol_factoryr'   r   Ússl_contextÚserver_hostnames         r
   Úcreate_streaming_connectionz.AbstractIOServices.create_streaming_connection®   s   € õH "Ð!r   )r   r   r   r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚabcÚabstractmethodr   r   r   r   r   r   r$   r)   r.   © r   r
   r   r      sU  € € € € € ðð ð 	Ôð"ð "ñ Ôð"ð 	Ôð"ð "ñ Ôð"ð 	Ôð"ð "ñ Ôð"ð 	Ôð"ð "ñ Ôð"ð* 	Ôð"ð "ñ Ôð"ð  	Ôð"ð "ñ Ôð"ð  	Ôð
 ØØØð"ð "ð "ñ Ôð"ð( 	Ôð"ð "ñ Ôð"ð6 	Ôð
 15Ø48ð#"ð #"ð #"ñ Ôð#"ð #"ð #"r   r   c                   ó’   — e Zd ZdZej        d„ ¦   «         Zej        d„ ¦   «         Zej        d„ ¦   «         Zej        d„ ¦   «         Z	dS )ÚAbstractFileDescriptorServicesaM  Interface definition of common non-blocking file descriptor services
    required by some utility implementations.

    NOTE: This is not a public API. Pika users should rely on the native I/O
    loop APIs (e.g., asyncio event loop, tornado ioloop, twisted reactor, etc.)
    that corresponds to the chosen Connection adapter.

    c                 ó   — t           ‚)a$  Call the given callback when the file descriptor is readable.
        Replace prior reader, if any, for the given file descriptor.

        :param fd: file descriptor
        :param callable on_readable: a callback taking no args to be notified
            when fd becomes readable.

        r   )r	   ÚfdÚon_readables      r
   Ú
set_readerz)AbstractFileDescriptorServices.set_readerß   s
   € õ "Ð!r   c                 ó   — t           ‚)zÆStop watching the given file descriptor for readability

        :param fd: file descriptor
        :returns: True if reader was removed; False if none was registered.
        :rtype: bool

        r   ©r	   r9   s     r
   Úremove_readerz,AbstractFileDescriptorServices.remove_readerë   ó
   € õ "Ð!r   c                 ó   — t           ‚)az  Call the given callback whenever the file descriptor is writable.
        Replace prior writer callback, if any, for the given file descriptor.

        IMPLEMENTATION NOTE: For portability, implementations of
            `set_writable()` should also watch for indication of error on the
            socket and treat it as equivalent to the writable indication (e.g.,
            also adding the socket to the `exceptfds` arg of `socket.select()`
            and calling the `on_writable` callback if `select.select()`
            indicates that the socket is in error state). Specifically, Windows
            (unlike POSIX) only indicates error on the socket (but not writable)
            when connection establishment fails.

        :param fd: file descriptor
        :param callable on_writable: a callback taking no args to be notified
            when fd becomes writable.

        r   )r	   r9   Úon_writables      r
   Ú
set_writerz)AbstractFileDescriptorServices.set_writerö   r%   r   c                 ó   — t           ‚)zÆStop watching the given file descriptor for writability

        :param fd: file descriptor
        :returns: True if reader was removed; False if none was registered.
        :rtype: bool

        r   r=   s     r
   Úremove_writerz,AbstractFileDescriptorServices.remove_writer  r?   r   N)
r/   r0   r1   r2   r3   r4   r;   r>   rB   rD   r5   r   r
   r7   r7   Õ   sš   € € € € € ðð ð 	Ôð	"ð 	"ñ Ôð	"ð 	Ôð"ð "ñ Ôð"ð 	Ôð"ð "ñ Ôð"ð( 	Ôð"ð "ñ Ôð"ð "ð "r   r7   c                   ó2   — e Zd ZdZej        d„ ¦   «         ZdS )ÚAbstractTimerReferencez#Reference to asynchronous operationc                 ó   — t           ‚)z>Cancel callback. If already cancelled, has no affect.
        r   r   s    r
   ÚcancelzAbstractTimerReference.cancel  s
   € õ "Ð!r   N©r/   r0   r1   r2   r3   r4   rH   r5   r   r
   rF   rF     s7   € € € € € Ø-Ð-àÔð"ð "ñ Ôð"ð "ð "r   rF   c                   ó2   — e Zd ZdZej        d„ ¦   «         ZdS )ÚAbstractIOReferencez'Reference to asynchronous I/O operationc                 ó   — t           ‚)z€Cancel pending operation

        :returns: False if was already done or cancelled; True otherwise
        :rtype: bool
        r   r   s    r
   rH   zAbstractIOReference.cancel$  ó
   € õ "Ð!r   NrI   r5   r   r
   rK   rK   !  s7   € € € € € Ø1Ð1àÔð"ð "ñ Ôð"ð "ð "r   rK   c                   ó’   — e Zd ZdZej        d„ ¦   «         Zej        d„ ¦   «         Zej        d„ ¦   «         Zej        d„ ¦   «         Z	dS )ÚAbstractStreamProtocolz°Stream protocol interface. It's compatible with a subset of
    `asyncio.protocols.Protocol` for compatibility with asyncio-based
    `AbstractIOServices` implementation.

    c                 ó   — t           ‚)z¸Introduces transport to protocol after transport is connected.

        :param AbstractStreamTransport transport:
        :raises Exception: Exception-based exception on error
        r   )r	   Ú	transports     r
   Úconnection_madez&AbstractStreamProtocol.connection_made5  rM   r   c                 ó   — t           ‚)ac  Called upon loss or closing of connection.

        NOTE: `connection_made()` and `connection_lost()` are each called just
        once and in that order. All other callbacks are called between them.

        :param BaseException | None error: An exception (check for
            `BaseException`) indicates connection failure. None indicates that
            connection was closed on this side, such as when it's aborted or
            when `AbstractStreamProtocol.eof_received()` returns a result that
            doesn't evaluate to True.
        :raises Exception: Exception-based exception on error
        r   )r	   Úerrors     r
   Úconnection_lostz&AbstractStreamProtocol.connection_lost>  r   r   c                 ó   — t           ‚)aÓ  Called after the remote peer shuts its write end of the connection.

        :returns: A falsy value (including None) will cause the transport to
            close itself, resulting in an eventual `connection_lost()` call
            from the transport. If a truthy value is returned, it will be the
            protocol's responsibility to close/abort the transport.
        :rtype: falsy|truthy
        :raises Exception: Exception-based exception on error
        r   r   s    r
   Úeof_receivedz#AbstractStreamProtocol.eof_receivedN  s
   € õ "Ð!r   c                 ó   — t           ‚)z£Called to deliver incoming data to the protocol.

        :param data: Non-empty data bytes.
        :raises Exception: Exception-based exception on error
        r   ©r	   Údatas     r
   Údata_receivedz$AbstractStreamProtocol.data_received[  rM   r   N)
r/   r0   r1   r2   r3   r4   rR   rU   rW   r[   r5   r   r
   rO   rO   .  sš   € € € € € ðð ð 	Ôð"ð "ñ Ôð"ð 	Ôð"ð "ñ Ôð"ð 	Ôð
"ð 
"ñ Ôð
"ð 	Ôð"ð "ñ Ôð"ð "ð "r   rO   c                   ó’   — e Zd ZdZej        d„ ¦   «         Zej        d„ ¦   «         Zej        d„ ¦   «         Zej        d„ ¦   «         Z	dS )ÚAbstractStreamTransportz³Stream transport interface. It's compatible with a subset of
    `asyncio.transports.Transport` for compatibility with asyncio-based
    `AbstractIOServices` implementation.

    c                 ó   — t           ‚)a  Close connection abruptly without waiting for pending I/O to
        complete. Will invoke the corresponding protocol's `connection_lost()`
        method asynchronously (not in context of the abort() call).

        :raises Exception: Exception-based exception on error
        r   r   s    r
   ÚabortzAbstractStreamTransport.abort  ó
   € õ "Ð!r   c                 ó   — t           ‚)zœReturn the protocol linked to this transport.

        :rtype: AbstractStreamProtocol
        :raises Exception: Exception-based exception on error
        r   r   s    r
   Úget_protocolz$AbstractStreamTransport.get_protocol‰  rM   r   c                 ó   — t           ‚)zÓBuffer the given data until it can be sent asynchronously.

        :param bytes data:
        :raises ValueError: if called with empty data
        :raises Exception: Exception-based exception on error
        r   rY   s     r
   ÚwritezAbstractStreamTransport.write’  r`   r   c                 ó   — t           ‚)ze
        :returns: Current size of output data buffered by the transport
        :rtype: int
        r   r   s    r
   Úget_write_buffer_sizez-AbstractStreamTransport.get_write_buffer_sizeœ  r   r   N)
r/   r0   r1   r2   r3   r4   r_   rb   rd   rf   r5   r   r
   r]   r]   x  sš   € € € € € ðð ð 	Ôð"ð "ñ Ôð"ð 	Ôð"ð "ñ Ôð"ð 	Ôð"ð "ñ Ôð"ð 	Ôð"ð "ñ Ôð"ð "ð "r   r]   )r2   r3   Úpika.compatÚpikaÚcompatÚAbstractBaser   r7   rF   rK   rO   r]   r5   r   r
   ú<module>rk      sU  ððð ð €
€
€
à Ð Ð Ð ð"ð "ð "ð "ð "˜œÔ1ñ "ô "ð "ðD?"ð ?"ð ?"ð ?"ð ?" T¤[Ô%=ñ ?"ô ?"ð ?"ðD"ð "ð "ð "ð "˜Tœ[Ô5ñ "ô "ð "ð
"ð 
"ð 
"ð 
"ð 
"˜$œ+Ô2ñ 
"ô 
"ð 
"ð4"ð 4"ð 4"ð 4"ð 4"˜Tœ[Ô5ñ 4"ô 4"ð 4"ðT*"ð *"ð *"ð *"ð *"˜dœkÔ6ñ *"ô *"ð *"ð *"ð *"r   