ef?dZddlmZddlmZddlmZmZmZm Z m Z m Z m Z e dZ de _dZGddeZed ZGd d eZGd d eZGddeZejZdS)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. )warn)WeakValueDictionary) WeakTypescontextmanager defaultdicthashable_identity lazy_property referencesymbolANYzToken for "any sender".ceZdZdZeZedZedZddZedfdZ dd Z e efd Z efd Z d Zd ZdZefdZdZdZdZdZdZdS)SignalzA notification emitter.c"tdS)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.docrselfs l/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/blinker/base.pyreceiver_connectedzSignal.receiver_connected%s>????c"tdS)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.rrrs rreceiver_disconnectedzSignal.receiver_disconnected1s,ABBBBrNc|r||_i|_tt|_tt|_i|_dS)zt :param doc: optional. If provided, will be assigned to the signal's __doc__ attribute. N)__doc__ receiversrset _by_receiver _by_sender _weak_senders)rrs r__init__zSignal.__init__IsI  DL',,%c**rTcZt|}|rt||j}||_n|}|turt }nt|}|j|||j| ||j | |~|turS||j vrJ t||j }||_ |j ||~n#t$rYnwxYwd|jvrH|jjr< |j||||n#|||xYwt jrE|t ur< t ||||n#|||xYw|S)aaConnect *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)receiversenderweak) receiver_arg sender_argweak_arg)rr _cleanup_receiver receiver_idr ANY_IDr setdefaultraddrr _cleanup_sender sender_id TypeError__dict__rsend disconnect)rr#r$r%r* receiver_refr/ sender_refs rconnectzSignal.connect\s&(11  $$Xt/EFFL'2L $ $#L S==II)&11I !!+|<<<  "&&{333 +&**9555    $2D!D!D &vt/CDD '0 $"--iDDDJ      !DM 1 1  # - 2 ',,T6>4:26-8888 &111  ' D8J,J,J "''5=3915(7777 &111s*C99 DDD>>E0FF(Fcfd}|S)aKConnect 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 c6||SN)r6)fnrr$r%s r decoratorz%Signal.connect_via..decorators LLVT * * *Ir)rr$r%r;s``` r connect_viazSignal.connect_vias0*       rc#K|||d dV||dS#||xYw)aExecute 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: .. testsetup:: from __future__ import with_statement from blinker import Signal on_ready = Signal() receiver = lambda sender: None .. testcode:: with on_ready.connected_to(receiver): # do stuff on_ready.send(123) .. versionadded:: 1.1 F)r$r%N)r6r3rr#r$s r connected_tozSignal.connected_tosf8 Xf5 999 &JJJ OOH % % % % %   OOH % % % s 7AcXtdt|||S)agAn 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.)rDeprecationWarningr@r?s rtemporarily_connected_tozSignal.temporarily_connected_tos6 )  ! ! !  6222rctdkrdn:tdkrtdtzd|jsgSfd|DS)aEmit 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 \*\*kwargs: Data to be sent to receivers. rNz5send() accepts only one positional argument, %s givenc&g|] }||fifSr<r<).0r#kwargsr$s r zSignal.send.. sF@@@ xx99&99:@@@r)lenr0r receivers_for)rr$rHs ``rr2z Signal.sends v;;!  FF [[1__'),V566 6AYF~ @I@@@@@$($6$6v$>$>@@@ @rc~|jsdS|jtrdS|turdSt ||jvS)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)rrr+r r)rr$s rhas_receivers_forzSignal.has_receivers_for sJ~ 5 ?6 " 4 S==5 ((DO;;rc#K|jrt|}||jvr!|jt|j|z}n$|jt}|D]d}|j|}|t |tr*|}|||t\|}|VcdSdS)z2Iterate all live receivers listening for *sender*.N) rrrr+copyget isinstancer _disconnect)rr$r/idsr*r#strongs rrKzSignal.receivers_fors > )&11IDO++v.y12of-2244"   >--k::#h 22&%XZZF~((f=== %H#    rc|turt}nt|}t|}|||d|jvr+|jjr!|j|||dSdSdS)aDisconnect *receiver* from this signal's events. :param receiver: a previously :meth:`connected` callable :param sender: a specific sender to disconnect from, or :obj:`ANY` to disconnect from all senders. Defaults to ``ANY``. r)r#r$N)r r+rrRr1rrr2)rr#r$r/r*s rr3zSignal.disconnect3s S==II)&11I'11  i000 #t} 4 4  & 0 5  & + +D5=39 , ; ; ; ; ; 5 4 4 4rcn|tkri|j|dr1|jD]}|||j|ddS|j|||j||dS)NF)r+rpoprvaluesdiscardr)rr*r/buckets rrRzSignal._disconnectIs    $$[%88 0"o446600FNN;//// N  {D 1 1 1 1 1 OI & . .{ ; ; ;  k * 2 29 = = = = =rcF||jtdS)z'Disconnect a receiver from all senders.N)rRr*r+)rr4s rr)zSignal._cleanup_receiverSs! 16:::::rc|j}|tksJ|j|d|j|dD]"}|j||#dS)z'Disconnect all receivers from a sender.Nr<)r/r+r rWrrrY)rr5r/r*s rr.zSignal._cleanup_senderWs~( F"""" y$///?..y"== > >K  k * 2 29 = = = = > >rc|j|jfD]A}t|D]\}}|s||dBdS)anPrune unused sender/receiver bookeeping. Not threadsafe. Connecting & disconnecting leave behind a small amount of bookeeping 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 bookeeping. (An empty set() for each stale sender/receiver pair.) This method will prune that bookeeping 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)rrlistitemsrW)rmapping_idrZs r_cleanup_bookkeepingzSignal._cleanup_bookkeeping_sl*):; + +G#GMMOO44 + + V+KKT*** + + +rc|j|j|j|jdS)z4Throw away all signal state. Useful for unit tests.N)r clearrrrrs r _clear_statezSignal._clear_stateysZ   """   !!!!!rr9)F)__name__ __module__ __qualname__rr r rrr!r6r=rr@rCr2rMrKr3rRr)r.rbrer<rrrrst!! C @ @] @CC]C.    &(+BBBBH4,/"&"&"&^"&H9<3333$@@@8<<< ,+.;;;;,>>>;;;>>>+++4"""""rra 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 eZdZdZddZdZdS) NamedSignalz%A named generic notification emitter.NcJt||||_dSr9)rr!namerrlrs rr!zNamedSignal.__init__s#c""" rc`t|}|ddd|jdS)Nz; >)r__repr__rl)rbases rrqzNamedSignal.__repr__s0t$$ "IIItyyy11rr9)rfrgrhrr!rqr<rrrjrjs=// 22222rrjceZdZdZddZdS) Namespacez%A mapping of signal names to signals.Nc| ||S#t$r'||t||cYSwxYwzReturn the :class:`NamedSignal` *name*, creating it if required. Repeated calls to this function will return the same signal object. KeyErrorr,rjrms rsignalzNamespace.signalU  A:  A A A??4T3)?)?@@ @ @ @ A  .;;r9rfrgrhrryr<rrrtrts4// A A A A A ArrtceZdZdZddZdS) WeakNamespacea-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| ||S#t$r'||t||cYSwxYwrvrwrms rryzWeakNamespace.signalrzr{r9r|r<rrr~r~s8 A A A A A Arr~N)rwarningsrweakrefrblinker._utilitiesrrrrr r r r r+objectrrrjdictrtr~ryr<rrrs'''''' fUmm' `"`"`"`"`"V`"`"`"F V$ 2 2 2 2 2& 2 2 2 A A A A A A A AAAAAA'AAA.  r