
    vKg@P                    (   S r SSKJ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  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.                  (       a  SSKr\R4                  " S\R6                  S\R8                  4   S9r\R4                  " S5      r\R>                  " S5      r \R6                  \R6                  \ \RB                  \   4   /\R6                  \ \4   4   r"\R6                  \R6                  \ \4   /\R6                  \ \RB                  \   4   4   r#\" S5      r$S\$l         Sr%\RL                  r& " S S5      r'\'" S5      r( " S S\'5      r) " S S\*5      r+ " S S\5      r,\+" 5       RZ                  r-g) a+  Signals and events.

A small implementation of signals, inspired by a snippet of Django signal
API client code seen in a blog post.  Signals are first-class objects and
each manages its own receivers and message emission.

The :func:`signal` function provides singleton behavior for named signals.

    )annotationsN)defaultdict)contextmanager)iscoroutinefunction)warn)WeakValueDictionary)annotatable_weakref)hashable_identity)IdentityType)lazy_property)	reference)symbol)	WeakTypes
T_callable.)boundTPANYzToken for "any sender".c                     \ 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\4     S%S jjrSS.       S&S jjrSS.       S'S jjrS(S 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)0Signal/   zA notification emitter.z	type[set]	set_classc                    [        SS9$ )zEmitted after each :meth:`connect`.

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    L/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/blinker/base.pyreceiver_connectedSignal.receiver_connected8   s     >??    c                    [        SS9$ )a  Emitted after :meth:`disconnect`.

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

Note, this signal is emitted **only** when :meth:`disconnect` is
called explicitly.

The disconnect signal can not be emitted by an automatic disconnect
(due to a weakly referenced receiver or sender going out of scope),
as the receiver and/or sender instances are no longer available for
use at the time this signal would be emitted.

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_disconnectedD   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)z\
:param doc: optional.  If provided, will be assigned to the signal's
  __doc__ attribute.

FN)__doc__	receiversis_mutedr   r   _by_receiver
_by_sender_weak_senders)r   r   s     r   __init__Signal.__init__\   sW     L PRCNNND
 BMNNB
 GIr"   Tc                   [        U5      nU(       a  [        XR                  5      nXEl        OUnU[        L a  [
        nO[        U5      nU R                  R                  XE5        U R                  U   R                  U5        U R                  U   R                  U5        AU[        LaG  X`R                  ;  a8   [        X R                  5      nXgl        U R                  R                  Xg5        ASU R                  ;   a6  U R                   R                  (       a   U R                   R#                  XX#S9  [         R                  (       a   U [         La   [         R#                  XX#S9  U$ U$ ! [         a     Nf = f! [         a  nU R%                  X5        UeSnAff = f! [         a  nU R%                  X5        UeSnAff = f)a  Connect *receiver* to signal events sent by *sender*.

:param receiver: A callable.  Will be invoked by :meth:`send` with
  `sender=` as a single positional argument and any ``kwargs`` that
  were provided to a call to :meth:`send`.

:param sender: Any object or :obj:`ANY`, defaults to ``ANY``.
  Restricts notifications delivered to *receiver* to only those
  :meth:`send` emissions sent by *sender*.  If ``ANY``, the receiver
  will always be notified.  A *receiver* may be connected to
  multiple *sender* values on the same Signal through multiple calls
  to :meth:`connect`.

:param weak: If true, the Signal will hold a weakref to *receiver*
  and automatically disconnect when *receiver* goes out of scope or
  is garbage collected.  Defaults to True.

r    )receiversenderweakN)receiver_arg
sender_argweak_arg)r
   r   _cleanup_receiverreceiver_idr   ANY_IDr(   
setdefaultr+   addr*   r,   _cleanup_sender	sender_id	TypeError__dict__r    send
disconnect)	r   r0   r1   r2   r7   receiver_refr<   
sender_refes	            r   connectSignal.connectt   s   * (1 $X/E/EFL'2$#LS=I)&1I!!+<	"&&{3+&**952D2D!D&v/C/CD
'0$ ""--iD  4==0T5L5L5V5V'',,F -  ''D8J,J"''F (  x/    1  1sB   =E1  F F& 1
E>=E>
F#FF#&
G0GGc                    ^ ^^ SU UU4S jjnU$ )a  Connect the decorated function as a receiver for *sender*.

:param sender: Any object or :obj:`ANY`.  The decorated function
  will only receive :meth:`send` emissions sent by *sender*.  If
  ``ANY``, the receiver will always be notified.  A function may be
  decorated multiple times with differing *sender* values.

:param weak: If true, the Signal will hold a weakref to the
  decorated function and automatically disconnect when *receiver*
  goes out of scope or is garbage collected.  Unlike
  :meth:`connect`, this defaults to False.

The decorated function will be invoked by :meth:`send` with
  `sender=` as a single positional argument and any ``kwargs`` that
  were provided to the call to :meth:`send`.


.. versionadded:: 1.1

c                .   > TR                  U TT5        U $ N)rD   )fnr   r1   r2   s    r   	decorator%Signal.connect_via.<locals>.decorator   s    LLVT*Ir"   )rI   r   returnr    )r   r1   r2   rJ   s   ``` r   connect_viaSignal.connect_via   s    0	 	 r"   c              #     #    U R                  XSS9   Sv   U R                  U5        g! U R                  U5        f = f7f)a  Execute a block with the signal temporarily connected to *receiver*.

:param receiver: a receiver callable
:param sender: optional, a sender to filter on

This is a context manager for use in the ``with`` statement.  It can
be useful in unit tests.  *receiver* is connected to the signal for
the duration of the ``with`` block, and will be disconnected
automatically when exiting the block:

.. code-block:: python

  with on_ready.connected_to(receiver):
     # do stuff
     on_ready.send(123)

.. versionadded:: 1.1

F)r1   r2   N)rD   r@   r   r0   r1   s      r   connected_toSignal.connected_to   s9     . 	X59	&JOOH%DOOH%s   A * A =A c              #  t   #    SU l          Sv    SU l         g! [         a  nUeSnAff = f! SU l         f = f7f)zLContext manager for temporarily disabling signal.
Useful for test purposes.
TNF)r)   	Exception)r   rC   s     r   mutedSignal.muted   sA     
 	"J "DM  	G	 "DMs$   8 8
)$), 	58c                D    [        S[        5        U R                  X5      $ )a/  An alias for :meth:`connected_to`.

:param receiver: a receiver callable
:param sender: optional, a sender to filter on

.. versionadded:: 0.9

.. versionchanged:: 1.1
  Renamed to :meth:`connected_to`.  ``temporarily_connected_to`` was
  deprecated in 1.2 and will be removed in a subsequent version.

zAtemporarily_connected_to is deprecated; use connected_to instead.)r   DeprecationWarningrR   rQ   s      r   temporarily_connected_toSignal.temporarily_connected_to  s%     	O	
   22r"   )_async_wrapperc                  U R                   (       a  / $ U R                  U5      n/ nU R                  U5       HD  n[        U5      (       a  Uc  [	        S5      eU" U5      nU" U40 UD6nUR                  XV45        MF     U$ )a  Emit this signal on behalf of *sender*, passing on ``kwargs``.

Returns a list of 2-tuples, pairing receivers with their return
value. The ordering of receiver notification is undefined.

:param sender: Any object or ``None``.  If omitted, synonymous
  with ``None``.  Only accepts one positional argument.
:param _async_wrapper: A callable that should wrap a coroutine
  receiver and run it when called synchronously.

:param kwargs: Data to be sent to receivers.
z#Cannot send to a coroutine functionr)   _extract_senderreceivers_forr   RuntimeErrorappend)r   r\   r1   kwargsresultsr0   results          r   r?   Signal.send  s    $ ==I%%f-**62H"8,,!)&'LMM)(3f//FNNH-. 3 r"   )_sync_wrapperc                  #    U R                   (       a  / $ U R                  U5      n/ nU R                  U5       HL  n[        U5      (       d  Uc  [	        S5      eU" U5      nU" U40 UD6I Sh  vN nUR                  XV45        MN     U$  N7f)a  Emit this signal on behalf of *sender*, passing on ``kwargs``.

Returns a list of 2-tuples, pairing receivers with their return
value. The ordering of receiver notification is undefined.

:param sender: Any object or ``None``.  If omitted, synonymous
  with ``None``. Only accepts one positional argument.
:param _sync_wrapper: A callable that should wrap a synchronous
  receiver and run it when awaited.

:param kwargs: Data to be sent to receivers.
Nz'Cannot send to a non-coroutine functionr^   )r   rg   r1   rc   rd   r0   re   s          r   
send_asyncSignal.send_async7  s     $ ==I%%f-**62H&x00 (&'PQQ(2#F5f55FNNH-. 3  6s   A-B/B0Bc                   U R                   (       d0  U(       a'  [        U5      S:  a  [        S[        U5       S35      e/ $ [        U5      S:X  a  S nU$ [        U5      S:  a  [        S[        U5       S35      eUS   nU$ )N   z-send() accepts only one positional argument, z givenr   )r(   lenr=   r   r1   s     r   r_   Signal._extract_senderW  s    ~~ $FaCCK=PVW  I
 v;!F  [1_?F}FS  AYFr"   c                    U R                   (       d  gU R                  [           (       a  gU[        L a  g[	        U5      U R                  ;   $ )zTrue if there is probably a receiver for *sender*.

Performs an optimistic check only.  Does not guarantee that all
weakly referenced receivers are still alive.  See
:meth:`receivers_for` for a stronger search.

FT)r(   r+   r8   r   r
   rn   s     r   has_receivers_forSignal.has_receivers_forn  s;     ~~??6"S= (DOO;;r"   c              #    #    U R                   (       a  [        U5      nX R                  ;   a$  U R                  [           U R                  U   -  nO!U R                  [           R	                  5       nU H`  nU R                   R                  U5      nUc  M#  [        U[        5      (       a$  U" 5       nUc  U R                  U[        5        MZ  UnUv   Mb     gg7f)z2Iterate all live receivers listening for *sender*.N)	r(   r
   r+   r8   copyget
isinstancer   _disconnect)r   r1   r<   idsr7   r0   strongs          r   r`   Signal.receivers_for~  s     
 >>)&1IOO+oof-	0JJoof-224">>--k:#h	22%ZF~((f= %H  # 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 this signal's events.

:param receiver: a previously :meth:`connected<connect>` callable

:param sender: a specific sender to disconnect from, or :obj:`ANY`
  to disconnect from all senders.  Defaults to ``ANY``.

r$   )r0   r1   N)r   r8   r
   rw   r>   r$   r(   r?   )r   r0   r1   r<   r7   s        r   r@   Signal.disconnect  sr     S=I)&1I'10 $t}}4**44&&++DF+S 5 5r"   c                p   U[         :X  ap  U R                  R                  US5      (       a2  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 )NF)r8   r*   popr+   valuesdiscardr(   )r   r7   r<   buckets       r   rw   Signal._disconnect  s      $$[%88"oo446FNN;/ 7NN{D1OOI&..{;k*229=r"   c                `    U R                  [        [        UR                  5      [        5        g)z'Disconnect a receiver from all senders.N)rw   castr   r7   r8   )r   rA   s     r   r6   Signal._cleanup_receiver  s    lL,D,DEvNr"   c                
   [        [        UR                  5      nU[        :w  d   eU R                  R                  US5        U R                  R                  US5       H!  nU R                  U   R                  U5        M#     g)z'Disconnect all receivers from a sender.NrM   )	r   r   r<   r8   r,   r~   r+   r*   r   )r   rB   r<   r7   s       r   r;   Signal._cleanup_sender  sl    z';';<	F"""y$/??..y"=Kk*229= >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 leave behind a small amount of bookkeeping
for the receiver and sender values. 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 Python process performing dynamic signal routing
with high volume- e.g. connecting to function closures, "senders" are
all unique object instances, and doing all of this over and over- you
may see memory usage will 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itemsr~   )r   mapping_idr   s       r   _cleanup_bookkeepingSignal._cleanup_bookkeeping  sG    * ):):;G#GMMO4vKKT*  5 <r"   c                    U R                   R                  5         U R                  R                  5         U R                  R                  5         U R                  R                  5         g)z4Throw away all signal state.  Useful for unit tests.N)r,   clearr(   r+   r*   r   s    r   _clear_stateSignal._clear_state  sF      "!r"   )r'   r*   r+   r,   r)   r(   )rL   r   rH   )r   
str | NonerL   None)r0   r   r1   t.Anyr2   boolrL   r   )F)r1   r   r2   r   rL   z$t.Callable[[T_callable], T_callable])r0   
t.Callabler1   r   rL   t.Generator[None, None, None])rL   r   )r0   r   r1   r   rL   zt.ContextManager[None])r1   r   r\   zAsyncWrapperType | Nonerc   r   rL   list[tuple[t.Callable, t.Any]])r1   r   rg   zSyncWrapperType | Nonerc   r   rL   r   )r1   r   rL   r   )r1   r   rL   r   )r1   r   rL   z3t.Generator[t.Callable[[t.Any], t.Any], None, None])r0   r   r1   r   rL   r   )r7   r   r<   r   rL   r   )rA   r	   rL   r   )rB   r	   rL   r   )rL   r   )__name__
__module____qualname____firstlineno__r'   r   setr   __annotations__r   r    r$   r-   rD   rN   r   rR   rV   rZ   r?   ri   r_   rq   r`   r@   rw   r6   r;   r   r   __static_attributes__rM   r"   r   r   r   /   s   ! CIy	@ 	@ C C.I2 58dD"D,1D?CD	DN +0#'	-< 47&"&,1&	&& &8 
" 
" 583"3,13	30 37 0 	
 
(F 15 . 	
 
(@.< 	<. @C T.>O>+4"r"   r   a  Sent by a :class:`Signal` after a receiver connects.

:argument: the Signal that was connected to
:keyword receiver_arg: the connected receiver
:keyword sender_arg: the sender to connect to
:keyword weak_arg: true if the connection to receiver_arg is a weak reference

.. deprecated:: 1.2

As of 1.2, individual signals have their own private
:attr:`~Signal.receiver_connected` and
:attr:`~Signal.receiver_disconnected` signals with a slightly simplified
call signature.  This global signal is planned to be removed in 1.6.

c                  0    \ rS rSrSrSSS jjrS	S jrSrg)
NamedSignali  z%A named generic notification emitter.Nc                :    [         R                  X5        Xl        g rH   )r   r-   name)r   r   r   s      r   r-   NamedSignal.__init__  s    " 	r"   c                X    [         R                  U 5      nUS S  SU R                  < S3$ )Nz; >)r   __repr__r   )r   bases     r   r   NamedSignal.__repr__  s-    t$s)Btyym1--r"   )r   rH   )r   strr   r   rL   r   )rL   r   )r   r   r   r   r'   r-   r   r   rM   r"   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 mapping of signal names to signals.Nc                f     X   $ ! [          a     U R                  U[        X5      5      nUs $ f = fzReturn the :class:`NamedSignal` *name*, creating it if required.

Repeated calls to this function will return the same signal object.

KeyErrorr9   r   r   r   r   re   s       r   signalNamespace.signal	  8    	: 	__T;t+ABFM	    '00rM   rH   r   r   r   r   rL   r   r   r   r   r   r'   r   r   rM   r"   r   r   r     s    /
 
r"   r   c                  &    \ rS rSrSrSSS jjrSrg)WeakNamespacei  a  A weak mapping of signal names to signals.

Automatically cleans up unused Signals when the last reference goes out
of scope.  This namespace implementation exists for a measure of legacy
compatibility with Blinker <= 1.2, and may be dropped in the future.

.. versionadded:: 1.3

Nc                f     X   $ ! [          a     U R                  U[        X5      5      nUs $ f = fr   r   r   s       r   r   WeakNamespace.signal!  r   r   rM   rH   r   r   rM   r"   r   r   r     s    
 
r"   r   ).r'   
__future__r   typingtcollectionsr   
contextlibr   inspectr   warningsr   weakrefr   blinker._utilitiesr	   r
   r   r   r   r   r   TYPE_CHECKINGtyping_extensionsteTypeVarCallableAnyr   r   	ParamSpecr   	AwaitableAsyncWrapperTypeSyncWrapperTyper   r8   r   r   r    r   dictr   r   r   rM   r"   r   <module>r      sc   #  # % '  ' 2 0 + , ( % (??"<qzz#quu*/EFJ			#A
SAzz1::aQ.?#@"A1::aQRdCS"STjj!**QT"2!3QZZ1;;q>@Q5R!RSOUm'	
 	vvr" r"j  (.& .  ' 0 
		r"   