§
    qŠtj  ã                   óà   — U d Z ddlZddlZddlmZmZmZ ddlmZ ddl	m
Z
mZ  G d„ de¦  «        Zi Zeeef         ed<   i Zeee
f         ed	<   i Zeeef         ed
<   ddœd„Zd„ Zd„ Zd„ ZdS )a  Cross-process transport for callback messages.

When a callback is registered on an estimator that uses multiple worker processes, every
worker ends up with its own copy of the callback (sent there by pickling). However, the
user-visible state (e.g. logs being filled in or progress bars advancing) lives on the
main process. This module provides a way for the worker copies to ship their messages
back to the main process over a local endpoint (a UNIX socket on Unix, a Windows named
pipe on Windows).

Remark: we don't use a `multiprocessing.Manager` because its proxy objects become
unusable once the Manager subprocess is gone, e.g. after unpickling in a fresh
interpreter. The only ways to work around that either rely on multiprocessing private
API or give up cross-process capabilities.
é    N)ÚClientÚ
ConnectionÚListener)ÚThread)ÚCallableÚ
NamedTuplec                   ó(   — e Zd ZU dZeed<   eed<   dS )ÚListenerHandlea•  A picklable reference to a main-process listener.

    Attributes
    ----------
    address : str
        Address of the local endpoint the listener is bound to.
        Workers use this to connect, and the main process also uses it as a key into
        this module's registries to find the live listener.

    authkey : bytes
        Shared secret used to authenticate connections to the listener.
    ÚaddressÚauthkeyN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__Úbytes© ó    úY/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/callback/_transport.pyr
   r
      s.   € € € € € € ðð ð €L€L�LØ€N€N�N€N€Nr   r
   Ú
_listenersÚ_message_consumersÚ_worker_connections)Úownerc                óT  ‡ ‡‡— t          j        d¦  «        }t          |d¬¦  «        Št          ‰j        |¬¦  «        }‰t
          |j        <   ‰ t          |j        <   |�t          j        |t          |¦  «         ˆ fd„Šˆˆfd„}t          |d¬	¦  «                             ¦   «          |S )
aå  Create a listener for incoming messages on the main process.

    Also registers the listener and its message consumer in the module-level dicts.

    Parameters
    ----------
    message_consumer : callable
        A one-argument function, `message_consumer(message)`, that processes incoming
        message to update the callback's state. This callable may be called from
        multiple different threads, and must therefore behave in a thread-safe manner.

    owner : callback instance, default=None
        Optional owner callback. When provided, the listener is automatically closed
        when `owner` gets garbage-collected.

    Returns
    -------
    listener_handle : ListenerHandle
        A reference to the listener.
    é    é€   )r   Úbacklog)r   r   Nc                 óž   •— 	 	  ‰|                       ¦   «         ¦  «         |                      d ¦  «         Œ3# t          t          f$ r Y d S w xY w)N)ÚrecvÚsendÚEOFErrorÚOSError)ÚconnÚmessage_consumers    €r   Ú_handlezopen_listener.<locals>._handlei   sc   ø€ ð	ð Ø Ð  §¢¡¤Ñ-Ô-Ð-Ø—	’	˜$‘”�ð øõ �'Ð"ð 	ð 	ð 	ØˆFˆFð	øøøs   ƒ47 ·AÁAc                  ó    •— 	 	 ‰                      ¦   «         } n# t          $ r Y d S w xY wt          ‰| fd¬¦  «                             ¦   «          ŒM)NT)ÚtargetÚargsÚdaemon)Úacceptr#   r   Ústart)r$   r&   Úlisteners    €€r   Ú_acceptzopen_listener.<locals>._acceptt   sj   ø€ ð	FðØ—’Ñ(Ô(��øÝð ð ð Ø��ðøøøå˜'¨¨¸Ð=Ñ=Ô=×CÒCÑEÔEÐEð	Fs   „ ™
'¦'T)r(   r*   )ÚosÚurandomr   r
   r   r   r   ÚweakrefÚfinalizeÚclose_listenerr   r,   )r%   r   r   Úlistener_handler.   r&   r-   s   `    @@r   Úopen_listenerr5   D   s×   øøø€ õ* Œj˜‰nŒn€Gõ  °Ð5Ñ5Ô5€HÝ$¨XÔ-=ÀwÐOÑOÔO€Oà*2…JˆÔ&Ñ'Ø2BÕ�Ô.Ñ/ØÐÝÔ˜¥°Ñ@Ô@Ð@ð	ð 	ð 	ð 	ð 	ðFð Fð Fð Fð Fð Fõ �' $Ð'Ñ'Ô'×-Ò-Ñ/Ô/Ð/ØÐr   c                 ó¶   — t                                | j        d¦  «         t                               | j        d¦  «        }|�|                     ¦   «          dS dS )zEStop listening for `listener_handle` and free its background threads.N)r   Úpopr   r   Úclose)r4   r-   s     r   r3   r3   €   sU   € å×Ò˜?Ô2°DÑ9Ô9Ð9Ý�~Š~˜oÔ5°tÑ<Ô<€HØÐØ�ŠÑÔÐÐÐð Ðr   c                 ó¦   — | j         t          v rdS 	 t          | j         | j        ¬¦  «                             ¦   «          n# t
          $ r Y dS w xY wdS )a´  Whether the listener at `listener_handle` is usable from this process.

    Helper for callbacks that open their listener eagerly (e.g. in `__init__`) and
    therefore have to decide, on unpickling, whether to keep the inherited handle
    or open a fresh listener. The listener is not reusable when:

    - We are the process that originally opened the listener. Reusing the handle
      would route messages through the in-process fast path of `send`, into the
      original instance's message consumer instead of the unpickled instance's.

    - The listener is no longer reachable, e.g. unpickling in a fresh interpreter,
      or on a host that cannot reach the original listener.
    F©r   T)r   r   r   r   r8   r#   )r4   s    r   Úcan_reuse_listenerr;   ˆ   sk   € ð Ô¥*Ð,Ð,ØˆuðÝˆÔ&°Ô0GÐHÑHÔH×NÒNÑPÔPÐPÐPøÝð ð ð Øˆuˆuðøøøàˆ4s   ’-A  Á 
AÁAc                 ó:  — t                                | j        ¦  «        }|� ||¦  «         dS | j        }t                               |¦  «        }|€ t	          || j        ¬¦  «        }|t          |<   |                     |¦  «         |                     ¦   «          dS )aä  Deliver `message` to whoever is listening on `listener_handle`.

    There are two possible delivery paths:

    - In-process fast path: `send` is called in the same process that called
      `open_listener` for this listener handle. The message consumer can directly be
      called without any serialization overhead.

    - Cross-process path: `send` is called in a different process. The worker opens
      a `Client` connection to the main-process listener on first use and caches it
      in `_worker_connections`, so all subsequent messages reuse the same socket.
      `send` then waits for an acknowledgement from the main process so that, by
      the time it returns, the message has actually been processed by the consumer.
    Nr:   )r   Úgetr   r   r   r   r!   r    )r4   Úmessager%   r   Ú
connections        r   r!   r!   Ÿ   s    € õ *×-Ò-¨oÔ.EÑFÔFÐØÐ#ØÐ˜Ñ!Ô!Ð!ØˆàÔ%€GÝ$×(Ò(¨Ñ1Ô1€JØÐÝ˜G¨_Ô-DÐEÑEÔEˆ
Ø'1Õ˜GÑ$Ø‡O‚O�GÑÔÐØ‡O‚OÑÔÐÐÐr   )r   r/   r1   Úmultiprocessing.connectionr   r   r   Ú	threadingr   Útypingr   r   r
   r   Údictr   r   r   r   r5   r3   r;   r!   r   r   r   ú<module>rD      sB  ððð ð ð 
€	€	€	Ø €€€Ø CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CØ Ð Ð Ð Ð Ð Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'ðð ð ð ð �Zñ ô ð ðB #%€
ˆD��h�ÔÐ $Ð $Ñ $Ø*,Ð �D˜˜h˜Ô'Ð ,Ð ,Ñ ,ð
 .0Ð �T˜#˜z˜/Ô*Ð /Ð /Ñ /ð .2ð 9ð 9ð 9ð 9ð 9ðxð ð ðð ð ð.ð ð ð ð r   