
    ,hJ                       % S SK Jr  S SKJr  S SKrS SKrS SKrS SK	J
r
  S SKJr  S SKJr  S SKJr  SSKJr  SS	KJr  SS
KJr  \R*                  " S\R,                  S\R.                  4   S9r\" S5      r S r " S S5      r " S S\5      r " S S\\\4   5      r " S S\R@                  5      r!\" 5       r"S\#S'    \"RH                  r$S\#S'   g)    )annotationsN)defaultdict)contextmanager)cached_property)iscoroutinefunction   )make_id)make_ref)SymbolF.)boundANYc                  x   \ rS rSr% Sr\r \rS\S'    \	SS j5       r
\	SS j5       rSSS jjr\S	4SS
 jjrSS S jjr\\4     S!S jj5       r\S"S j5       r SSS.       S#S jjjr SSS.       S$S jjjrS%S jr    S&S jr\4S'S jjrS(S jr    S)S jr    S*S jrS+S jrS+S jrSrg),Signal   zCA notification emitter.

:param doc: The docstring for the signal.
ztype[set[t.Any]]	set_classc                    [        SS9$ )zEmitted at the end of each :meth:`connect` call.

The signal sender is the signal instance, and the :meth:`connect`
arguments are passed through: ``receiver``, ``sender``, and ``weak``.

.. versionadded:: 1.2
z"Emitted after a receiver connects.docr   selfs    D/var/www/auris/envauris/lib/python3.13/site-packages/blinker/base.pyreceiver_connectedSignal.receiver_connected)   s     >??    c                    [        SS9$ )a  Emitted at the end of each :meth:`disconnect` call.

The sender is the signal instance, and the :meth:`disconnect` arguments
are passed through: ``receiver`` and ``sender``.

This signal is emitted **only** when :meth:`disconnect` is called
explicitly. This signal cannot be emitted by an automatic disconnect
when a weakly referenced receiver or sender goes out of scope, as the
instance is no longer be available to be used as the sender for this
signal.

An alternative approach is available by subscribing to
:attr:`receiver_connected` and setting up a custom weakref cleanup
callback on weak receivers and senders.

.. versionadded:: 1.2
z%Emitted after a receiver disconnects.r   r   r   s    r   receiver_disconnectedSignal.receiver_disconnected4   s    & ABBr   Nc                    U(       a  Xl         0 U l         SU l        [        U R                  5      U l        [        U R                  5      U l        0 U l        g )NF)__doc__	receiversis_mutedr   r   _by_receiver
_by_sender_weak_senders)r   r   s     r   __init__Signal.__init__I   sM    L  		 $5@5P3>t~~3N>@r   Tc                   [        U5      nU[        L a  [        O
[        U5      nU(       a(  [        XR	                  U5      5      U R
                  U'   OXR
                  U'   U R                  U   R                  U5        U R                  U   R                  U5        U[        La7  XPR                  ;  a(   [        X R                  U5      5      U R                  U'   SU R                  ;   a8  U R                  R
                  (       a   U R                  R                  XX#S9  U$ U$ ! [         a     NVf = f! [         a    U R                  X5        e f = f)a4  Connect ``receiver`` to be called when the signal is sent by
``sender``.

:param receiver: The callable to call when :meth:`send` is called with
    the given ``sender``, passing ``sender`` as a positional argument
    along with any extra keyword arguments.
:param sender: Any object or :data:`ANY`. ``receiver`` will only be
    called when :meth:`send` is called with this sender. If ``ANY``, the
    receiver will be called for any sender. A receiver may be connected
    to multiple senders by calling :meth:`connect` multiple times.
:param weak: Track the receiver with a :mod:`weakref`. The receiver will
    be automatically disconnected when it is garbage collected. When
    connecting a receiver defined within a function, set to ``False``,
    otherwise it will be disconnected when the function scope ends.
r   )receiversenderweak)r	   r   ANY_IDr
   _make_cleanup_receiverr"   r%   addr$   r&   _make_cleanup_sender	TypeError__dict__r   send
disconnect)r   r*   r+   r,   receiver_id	sender_ids         r   connectSignal.connect[   s9     h'$mF	*255kB+DNN;' +3NN;'	"&&{3+&**952D2D!D0855i@1""9-  4==0T5L5L5V5V'',,F -  x    1s   8'D) D9 )
D65D69Ec                    ^ ^^ SU UU4S jjnU$ )aO  Connect the decorated function to be called when the signal is sent
by ``sender``.

The decorated function will be called when :meth:`send` is called with
the given ``sender``, passing ``sender`` as a positional argument along
with any extra keyword arguments.

:param sender: Any object or :data:`ANY`. ``receiver`` will only be
    called when :meth:`send` is called with this sender. If ``ANY``, the
    receiver will be called for any sender. A receiver may be connected
    to multiple senders by calling :meth:`connect` multiple times.
:param weak: Track the receiver with a :mod:`weakref`. The receiver will
    be automatically disconnected when it is garbage collected. When
    connecting a receiver defined within a function, set to ``False``,
    otherwise it will be disconnected when the function scope ends.=

.. versionadded:: 1.1
c                .   > TR                  U TT5        U $ N)r7   )fnr   r+   r,   s    r   	decorator%Signal.connect_via.<locals>.decorator   s    LLVT*Ir   )r<   r   returnr    )r   r+   r,   r=   s   ``` r   connect_viaSignal.connect_via   s    (	 	 r   c              #     #    U R                  XSS9   Sv   U R                  U5        g! U R                  U5        f = f7f)a8  A context manager that temporarily connects ``receiver`` to the
signal while a ``with`` block executes. When the block exits, the
receiver is disconnected. Useful for tests.

:param receiver: The callable to call when :meth:`send` is called with
    the given ``sender``, passing ``sender`` as a positional argument
    along with any extra keyword arguments.
:param sender: Any object or :data:`ANY`. ``receiver`` will only be
    called when :meth:`send` is called with this sender. If ``ANY``, the
    receiver will be called for any sender.

.. versionadded:: 1.1
F)r+   r,   N)r7   r4   )r   r*   r+   s      r   connected_toSignal.connected_to   s9     " 	X59	&JOOH%DOOH%s   A * A =A c              #  J   #    SU l          Sv   SU l         g! SU l         f = f7f)zA context manager that temporarily disables the signal. No receivers
will be called if the signal is sent, until the ``with`` block exits.
Useful for tests.
TNF)r#   r   s    r   mutedSignal.muted   s&      	"J!DMEDMs   # #	 #)_async_wrapperc                  U R                   (       a  / $ / nU R                  U5       HL  n[        U5      (       a  Uc  [        S5      eU" U5      " U40 UD6nO	U" U40 UD6nUR	                  XV45        MN     U$ )a  Call all receivers that are connected to the given ``sender``
or :data:`ANY`. Each receiver is called with ``sender`` as a positional
argument along with any extra keyword arguments. Return a list of
``(receiver, return value)`` tuples.

The order receivers are called is undefined, but can be influenced by
setting :attr:`set_class`.

If a receiver raises an exception, that exception will propagate up.
This makes debugging straightforward, with an assumption that correctly
implemented receivers will not raise.

:param sender: Call receivers connected to this sender, in addition to
    those connected to :data:`ANY`.
:param _async_wrapper: Will be called on any receivers that are async
    coroutines to turn them into sync callables. For example, could run
    the receiver with an event loop.
:param kwargs: Extra keyword arguments to pass to each receiver.

.. versionchanged:: 1.7
    Added the ``_async_wrapper`` argument.
z$Cannot send to a coroutine function.r#   receivers_forr   RuntimeErrorappend)r   r+   rI   kwargsresultsr*   results          r   r3   Signal.send   s    B ==I**62H"8,,!)&'MNN'1&CFC!&3F3NNH-. 3 r   )_sync_wrapperc              "  #    U R                   (       a  / $ / nU R                  U5       H\  n[        U5      (       d&  Uc  [        S5      eU" U5      " U40 UD6I Sh  vN nOU" U40 UD6I Sh  vN nUR	                  XV45        M^     U$  N. N7f)at  Await all receivers that are connected to the given ``sender``
or :data:`ANY`. Each receiver is called with ``sender`` as a positional
argument along with any extra keyword arguments. Return a list of
``(receiver, return value)`` tuples.

The order receivers are called is undefined, but can be influenced by
setting :attr:`set_class`.

If a receiver raises an exception, that exception will propagate up.
This makes debugging straightforward, with an assumption that correctly
implemented receivers will not raise.

:param sender: Call receivers connected to this sender, in addition to
    those connected to :data:`ANY`.
:param _sync_wrapper: Will be called on any receivers that are sync
    callables to turn them into async coroutines. For example,
    could call the receiver in a thread.
:param kwargs: Extra keyword arguments to pass to each receiver.

.. versionadded:: 1.7
Nz(Cannot send to a non-coroutine function.rK   )r   r+   rS   rO   rP   r*   rQ   s          r   
send_asyncSignal.send_async   s     @ ==I**62H&x00 (&'QRR,X6vHHH'9&99NNH-. 3  I9s$   ABBB.B/BBc                    U R                   (       d  gU R                  [           (       a  gU[        L a  g[	        U5      U R                  ;   $ )a  Check if there is at least one receiver that will be called with the
given ``sender``. A receiver connected to :data:`ANY` will always be
called, regardless of sender. Does not check if weakly referenced
receivers are still live. See :meth:`receivers_for` for a stronger
search.

:param sender: Check for receivers connected to this sender, in addition
    to those connected to :data:`ANY`.
FT)r"   r%   r-   r   r	   )r   r+   s     r   has_receivers_forSignal.has_receivers_for1  s:     ~~??6"S=v$//11r   c              #    #    U R                   (       d  g[        U5      nX R                  ;   a$  U R                  [           U R                  U   -  nO!U R                  [           R	                  5       nU Hn  nU R                   R                  U5      nUc  M#  [        U[        R                  5      (       a(  U" 5       nUc  U R                  U[        5        Md  Uv   Mj  Uv   Mp     g7f)a!  Yield each receiver to be called for ``sender``, in addition to those
to be called for :data:`ANY`. Weakly referenced receivers that are not
live will be disconnected and skipped.

:param sender: Yield receivers connected to this sender, in addition
    to those connected to :data:`ANY`.
N)
r"   r	   r%   r-   copyget
isinstanceweakrefref_disconnect)r   r+   r6   idsr5   r*   strongs          r   rL   Signal.receivers_forF  s      ~~FO	'//&)DOOI,FFC//&)..0CK~~))+6H(GKK00!>$$[&9 s   C'C)c                    U[         L a  [        nO[        U5      n[        U5      nU R                  XC5        SU R                  ;   a7  U R
                  R                  (       a  U R
                  R                  XUS9  ggg)zDisconnect ``receiver`` from being called when the signal is sent by
``sender``.

:param receiver: A connected receiver callable.
:param sender: Disconnect from only this sender. By default, disconnect
    from all senders.
r   )r*   r+   N)r   r-   r	   r`   r2   r   r"   r3   )r   r*   r+   r6   r5   s        r   r4   Signal.disconnectl  sq     S=IIh'0 $t}}4**44&&++DF+S 5 5r   c                h   U[         :X  al  U R                  R                  US 5      b2  U R                  R	                  5        H  nUR                  U5        M     U R                  R                  US 5        g U R                  U   R                  U5        U R                  U   R                  U5        g r;   )r-   r$   popr%   valuesdiscardr"   )r   r5   r6   buckets       r   r`   Signal._disconnect  s      $$[$7C"oo446FNN;/ 7 NN{D1OOI&..{;k*229=r   c                   ^ ^ SUU 4S jjnU$ )zdCreate a callback function to disconnect a weakly referenced
receiver when it is garbage collected.
c                h   > [         R                  " 5       (       d  TR                  T[        5        g g r;   )sysis_finalizingr`   r-   )r_   r5   r   s    r   cleanup.Signal._make_cleanup_receiver.<locals>.cleanup  s)     $$&&  f5 'r   )r_   z#weakref.ref[c.Callable[..., t.Any]]r?   Noner@   )r   r5   rp   s   `` r   r.   Signal._make_cleanup_receiver  s    	6 	6 r   c                4   ^ ^ T[         :w  d   eSU U4S jjnU$ )ztCreate a callback function to disconnect all receivers for a weakly
referenced sender when it is garbage collected.
c                   > TR                   R                  TS 5        TR                  R                  TS5       H!  nTR                  U   R	                  T5        M#     g )Nr@   )r&   rg   r%   r$   ri   )r_   r5   r   r6   s     r   rp   ,Signal._make_cleanup_sender.<locals>.cleanup  sN    ""9d3#229bA!!+.66yA  Br   )r_   zweakref.ref[t.Any]r?   rr   )r-   )r   r6   rp   s   `` r   r0   Signal._make_cleanup_sender  s&     F"""	B 	B r   c                    U R                   U R                  4 H@  n[        UR                  5       5       H   u  p#U(       a  M  UR	                  US5        M"     MB     g)a  Prune unused sender/receiver bookkeeping. Not threadsafe.

Connecting & disconnecting leaves behind a small amount of bookkeeping
data. Typical workloads using Blinker, for example in most web apps,
Flask, CLI scripts, etc., are not adversely affected by this
bookkeeping.

With a long-running process performing dynamic signal routing with high
volume, e.g. connecting to function closures, senders are all unique
object instances. Doing all of this over and over may cause memory usage
to grow due to extraneous bookkeeping. (An empty ``set`` for each stale
sender/receiver pair.)

This method will prune that bookkeeping away, with the caveat that such
pruning is not threadsafe. The risk is that cleanup of a fully
disconnected receiver/sender pair occurs while another thread is
connecting that same pair. If you are in the highly dynamic, unique
receiver/sender situation that has lead you to this method, that failure
mode is perhaps not a big deal for you.
N)r%   r$   listitemsrg   )r   mappingidentrj   s       r   _cleanup_bookkeepingSignal._cleanup_bookkeeping  sG    * ):):;G!%gmmo!6vKKt, "7 <r   c                    U R                   R                  5         U R                  R                  5         U R                  R                  5         U R                  R                  5         g)z7Disconnect all receivers and senders. Useful for tests.N)r&   clearr"   r%   r$   r   s    r   _clear_stateSignal._clear_state  sF      "!r   )r!   r$   r%   r&   r#   r"   )r?   r   r;   )r   
str | Noner?   rr   )r*   r   r+   t.Anyr,   boolr?   r   )F)r+   r   r,   r   r?   zc.Callable[[F], F])r*   c.Callable[..., t.Any]r+   r   r?   c.Generator[None, None, None])r?   r   )r+   t.Any | NonerI   z^c.Callable[[c.Callable[..., c.Coroutine[t.Any, t.Any, t.Any]]], c.Callable[..., t.Any]] | NonerO   r   r?   *list[tuple[c.Callable[..., t.Any], t.Any]])r+   r   rS   z^c.Callable[[c.Callable[..., t.Any]], c.Callable[..., c.Coroutine[t.Any, t.Any, t.Any]]] | NonerO   r   r?   r   )r+   r   r?   r   )r+   r   r?   z/c.Generator[c.Callable[..., t.Any], None, None])r*   r   r+   r   r?   rr   )r5   
c.Hashabler6   r   r?   rr   )r5   r   r?   z7c.Callable[[weakref.ref[c.Callable[..., t.Any]]], None])r6   r   r?   z&c.Callable[[weakref.ref[t.Any]], None])r?   rr   )__name__
__module____qualname____firstlineno__r!   r   setr   __annotations__r   r   r   r'   r7   rA   r   rD   rG   r3   rU   rX   rL   r4   r`   r.   r0   r}   r   __static_attributes__r@   r   r   r   r      s   
 C>"%I% @ @ C C(A$ 47T 0d4 @C&.&8=&	&& &. 
" 
"  $1 11
1 1 
41j  $0 00
0 0 
40d2*$$	8$L LO T0	>%	@#	/ -4"r   r   c                  D   ^  \ rS rSrSrSSU 4S jjjrSU 4S jjrSrU =r$ )	NamedSignali  zA named generic notification emitter. The name is not used by the signal
itself, but matches the key in the :class:`Namespace` that it belongs to.

:param name: The name of the signal within the namespace.
:param doc: The docstring for the signal.
c                0   > [         TU ]  U5        Xl        g r;   )superr'   name)r   r   r   	__class__s      r   r'   NamedSignal.__init__  s     	r   c                L   > [         TU ]  5       nUS S  SU R                  < S3$ )Nz; >)r   __repr__r   )r   baser   s     r   r   NamedSignal.__repr__  s-    w!s)Btyym1--r   )r   r;   )r   strr   r   r?   rr   )r?   r   )	r   r   r   r   r!   r'   r   r   __classcell__)r   s   @r   r   r     s     . .r   r   c                  &    \ rS rSrSrSSS jjrSrg)	Namespacei  z A dict mapping names to signals.Nc                .    X;  a  [        X5      X'   X   $ )zReturn the :class:`NamedSignal` for the given ``name``, creating it
if required. Repeated calls with the same name return the same signal.

:param name: The name of the signal.
:param doc: The docstring of the signal.
)r   r   r   r   s      r   signalNamespace.signal  s     $T/DJzr   r@   r;   r   r   r   r   r?   r   )r   r   r   r   r!   r   r   r@   r   r   r   r     s    *
 
r   r   c                  "    \ rS rSrSSS jjrSrg)_PNamespaceSignali  Nc                    g r;   r@   r   s      r   __call___PNamespaceSignal.__call__  s    #r   r@   r;   r   )r   r   r   r   r   r   r@   r   r   r   r     s    MMr   r   default_namespacer   )%
__future__r   collections.abcabccrn   typingtr^   collectionsr   
contextlibr   	functoolsr   inspectr   
_utilitiesr	   r
   r   TypeVarCallableAnyr   r   r-   r   r   dictr   r   Protocolr   r   r   r   r@   r   r   <module>r      s    "  
   # % % '    IIcCJ/0Um 	
u" u"p.& .&S+%&  N

 N  ){ 9 * .44 4r   