
    hjA                     >   S r SSKrSSKJrJrJr   " S S5      r " S S\5      r\" 5       r " S S	\5      r	\	" 5       r
\R                  \R                  4r0 r0 r0 r\\S
4S jr\\S
4S jr\\4S jrS r\\4S jr\\
4S jr\\
4S jrS rS rS rS rS rS rg)a  Multiple-producer-multiple-consumer signal-dispatching

dispatcher is the core of the PyDispatcher system,
providing the primary API and the core logic for the
system.

Module attributes of note:

    Any -- Singleton used to signal either "Any Sender" or
        "Any Signal".  See documentation of the _Any class.
    Anonymous -- Singleton used to signal "Anonymous Sender"
        See documentation of the _Anonymous class.

Internal attributes:
    WEAKREF_TYPES -- tuple of types/classes which represent
        weak references to receivers, and thus must be de-
        referenced on retrieval to retrieve the callable
        object
    connections -- { senderkey (id) : { signal : [receivers...]}}
    senders -- { senderkey (id) : weakref(sender) }
        used for cleaning up sender references on sender
        deletion
    sendersBack -- { receiverkey (id) : [senderkey (id)...] }
        used for cleaning up receiver references on receiver
        deletion, (considerably speeds up the cleanup process
        vs. the original code.)
    N)saferefrobustapplyerrorsc                       \ rS rSrSrS rSrg)
_Parameter   z+Used to represent default parameter values.c                 .    U R                   R                  $ N)	__class____name__)selfs    \/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/pydispatch/dispatcher.py__repr___Parameter.__repr__!   s    ~~&&&     N)r   
__module____qualname____firstlineno____doc__r   __static_attributes__r   r   r   r   r      s
    5'r   r   c                       \ rS rSrSrSrg)_Any$   zSingleton used to signal either "Any Sender" or "Any Signal"

The Any object can be used with connect, disconnect,
send, or sendExact to signal that the parameter given
Any should react to all senders/signals, not just
a particular sender/signal.
r   Nr   r   r   r   r   r   r   r   r   r   r   $   s    r   r   c                       \ rS rSrSrSrg)
_Anonymous.   a  Singleton used to signal "Anonymous Sender"

The Anonymous object is used to signal that the sender
of a message is not specified (as distinct from being
"any sender").  Registering callbacks for Anonymous
will only receive messages sent without senders.  Sending
with anonymous will only send messages to those receivers
registered for Any or Anonymous.

Note:
    The default sender for connect is Any, while the
    default sender for send is Anonymous.  This has
    the effect that if you do not specify any senders
    in either function then all messages are routed
    as though there was a single sender (Anonymous)
    being used everywhere.
r   Nr   r   r   r   r   r   .   s    r   r   Tc                 J   Uc  [         R                  " SU < SU< S35      eU(       a  [        R                  " U [        S9n [        U5      nU[        ;   a
  [        U   nO0 =[        U'   nUS[        [        4;  a&  U4S jn [        R                  " X&5      nU[        U'   [        U 5      nX;   a  XQ   n	[        XAX	5        O/ =oU'    [        R                  U5      n
U
c  / =[        U'   n
XJ;  a  U
R                  U5        U	R                  U 5        g!    Nw= f!    N= f)a3  Connect receiver to sender for signal

receiver -- a callable Python object which is to receive
    messages/signals/events.  Receivers must be hashable
    objects.

    if weak is True, then receiver must be weak-referencable
    (more precisely saferef.safeRef() must be able to create
    a reference to the receiver).

    Receivers are fairly flexible in their specification,
    as the machinery in the robustApply module takes care
    of most of the details regarding figuring out appropriate
    subsets of the sent arguments to apply to a given
    receiver.

    Note:
        if receiver is itself a weak reference (a callable),
        it will be de-referenced by the system's machinery,
        so *generally* weak references are not suitable as
        receivers, though some use might be found for the
        facility whereby a higher-level library passes in
        pre-weakrefed receiver references.

signal -- the signal to which the receiver should respond

    if Any, receiver will receive any signal from the
    indicated sender (which might also be Any, but is not
    necessarily Any).
    
    Otherwise must be a hashable Python object other than
    None (DispatcherError raised on None).
    
sender -- the sender to which the receiver should respond

    if Any, receiver will receive the indicated signals
    from any sender.
    
    if Anonymous, receiver will only receive indicated
    signals from send/sendExact which do not specify a
    sender, or specify Anonymous explicitly as the sender.

    Otherwise can be any python object.
    
weak -- whether to use weak references to the receiver
    By default, the module will attempt to use weak
    references to the receiver objects.  If this parameter
    is false, then strong references will be used.

returns None, may raise DispatcherTypeError
N Signal cannot be None (receiver= sender=))onDeletec                     [        US9  g )N	senderkey)_removeSender)objectr&   s     r   removeconnect.<locals>.remove   s
    I.r   )r   DispatcherTypeErrorr   safeRef_removeReceiveridconnections	AnonymousAnyweakrefrefsenders_removeOldBackRefssendersBackgetappend)receiversignalsenderweakr&   signalsr)   
weakSender
receiverID	receiverscurrents              r   connectrB   I   s&   h ~((>FvN
 	
 ??8oF6
IKi(+--I dIs++%. 	/	 V4J!+GI HJ O	9hB&((	FO//:/?244K%#NN9% X)	 s   D 9D DD"c           	         Uc  [         R                  " SU < SU< S35      eU(       a  [        R                  " U 5      n [	        U5      n [
        U   nXQ   n [        XAX5        [        XA5        g! [         a    [         R                  " SU< SU< 35      ef = f! [         a#    [         R                  " SU < SU< SU< 35      ef = f)	aa  Disconnect receiver from sender for signal

receiver -- the registered receiver to disconnect
signal -- the registered signal to disconnect
sender -- the registered sender to disconnect
weak -- the weakref state to disconnect

disconnect reverses the process of connect,
the semantics for the individual elements are
logically equivalent to a tuple of
(receiver, signal, sender, weak) used as a key
to be deleted from the internal routing tables.
(The actual process is slightly more complex
but the semantics are basically the same).

Note:
    Using disconnect is not required to cleanup
    routing when an object is deleted, the framework
    will remove routes for deleted objects
    automatically.  It's only necessary to disconnect
    if you want to stop routing to a live object.
    
returns None, may raise DispatcherTypeError or
    DispatcherKeyError
Nr    r!   r"   zNo receivers found for signal z from sender zNo connection to receiver z for signal )r   r+   r   r,   r.   r/   KeyErrorDispatcherKeyErrorr5   
ValueError_cleanupConnections)r9   r:   r;   r<   r&   r=   r@   s          r   
disconnectrH      s    4 ~((>FvN
 	
 1X6
I	
i(O	

9hB 	*%  
''
 	

  
''
 	

s   A2 B 2)B-Cc                 R     [         [        U 5         U   $ ! [         a    / s $ f = f)a#  Get list of receivers from global tables

This utility function allows you to retrieve the
raw list of receivers from the connections table
for the given sender and signal pair.

Note:
    there is no guarantee that this is the actual list
    stored in the connections table, so the value
    should be treated as a simple iterable/truth value
    rather than, for instance a list to which you
    might append new records.

Normally you would use liveReceivers( getReceivers( ...))
to retrieve the actual receiver objects as an iterable
object.
)r/   r.   rD   )r;   r:   s     r   getReceiversrJ      s/    $2f:&v.. 	s    &&c              #   t   #    U  H.  n[        U[        5      (       a  U" 5       nUb  Uv   M(  M*  Uv   M0     g7f)zFilter sequence of receivers to get resolved, live receivers

This is a generator which will iterate over
the passed sequence, checking for weak references
and resolving them, then returning all live
receivers.
N)
isinstanceWEAKREF_TYPES)r@   r9   s     r   liveReceiversrN      s<      x//zH# $ N s   68c              #      #    0 n[        X5      [        U [        5      [        [        U5      [        [        [        5      4 H%  nU H  nU(       d  M   XB;  a
  SX$'   Uv   M  M     M'     g! [         a     M2  f = f7f)zGet list of all receivers from global tables

This gets all receivers which should receive
the given signal from sender, each receiver should
be produced only once by the resulting generator
   N)rJ   r1   	TypeError)r;   r:   r@   setr9   s        r   getAllReceiversrS     s      I 	f&fc#c6#c3 	 Hx0./	+& 1 	  ! s*   AA=A,!A=,
A:6A=9A::A=c                     / n[        [        X5      5       H2  n[        R                  " U/UQ7U US.UD6nUR	                  XV45        M4     U$ )ay  Send signal from sender to all connected receivers.

signal -- (hashable) signal value, see connect for details

sender -- the sender of the signal

    if Any, only receivers registered for Any will receive
    the message.

    if Anonymous, only receivers registered to receive
    messages from Anonymous or Any will receive the message

    Otherwise can be any python object (normally one
    registered with a connect if you actually want
    something to occur).

arguments -- positional arguments which will be passed to
    *all* receivers. Note that this may raise TypeErrors
    if the receivers do not allow the particular arguments.
    Note also that arguments are applied before named
    arguments, so they should be used with care.

named -- named arguments which will be filtered according
    to the parameters of the receivers to only provide those
    acceptable to the receiver.

Return a list of tuple pairs [(receiver, response), ... ]

if any receiver raises an error, the error propagates back
through send, terminating the dispatch loop, so it is quite
possible to not have all receivers called if a raises an
error.
r:   r;   )rN   rS   r   robustApplyr8   r:   r;   	argumentsnamed	responsesr9   responses          r   sendr\   '  sl    H I!/&"AB**
 	


 
 	(-. C r   c                     / n[        [        X5      5       H2  n[        R                  " U/UQ7U US.UD6nUR	                  XV45        M4     U$ )zSend signal only to those receivers registered for exact message

sendExact allows for avoiding Any/Anonymous registered
handlers, sending only to those receivers explicitly
registered for a particular signal on a particular
sender.
rU   )rN   rJ   r   rV   r8   rW   s          r   	sendExactr^   V  sk     I!,v">?**
 	


 
 	(-. @ r   c                    [         (       d  g[        U 5      n [         R                  U5      nU HW  n [        [        U   R                  5       5      nU H-  n [        U   U   n UR                  U 5        [        X55        M/     MY     g! [         a     N f = f! [         a     N0f = f! [         a     M  f = f! [         a     gf = f)z!Remove receiver from connections.FN)
r6   r.   poplistr/   keysr)   	ExceptionrD   rG   )r9   backKeybackSetr&   r=   r:   r@   s          r   r-   r-   k  s    ;lG;//'* !I;{95::<= &F!$/	$:6$B	!%,,h8 (	: & !  ) ! ! $     sF   B=  B,B'B
BB
B)(B),
B:9B:=
C
	C
c                      [         U    U   nU(       d    [         U    nX1	 U(       d  [        U 5        ggg! [         a     gf = f!    g= f)zBDelete any empty signals for senderkey. Delete senderkey if empty.N)r/   r'   rD   )r&   r:   r@   r=   s       r   rG   rG     sc    -	*62	 -%i0 O!),    s   A 	6 
AAA
c                 h    [        U 5         [        U 	  [        U 	 g! [         a     Nf = f!    g= f)z"Remove senderkey from connections.N)_removeBackrefsr/   rD   r4   r%   s    r   r'   r'     sA    I	"
I  s    - 
**1c                    ^  [         U    nUR                  5       mU4S jnU" 5        H  n[        X05        M     g! [         a    Sn gf = f)z,Remove all back-references to this senderkeyc               3   >   >#    T H  u  pU H  nUv   M	     M     g 7fr
   r   )r:   rR   itemitemss      r   allReceivers%_removeBackrefs.<locals>.allReceivers  s!     #
DJ   $s   N)r/   rl   _killBackrefrD   )r&   r=   rm   r9   rl   s       @r   rh   rh     sP    0i( 	 %H(/ '  s   	< A
Ac                 :    UR                  U5      nX4   nX4	 Sn[        R                  U5      nUbF  [        R                  U0 5      R                  5        H  u  pX:w  d  M  U	 H  n
XL d  M	  Sn  M     M      U(       d  [	        XP5        gg! [
         a     gf = f)zKill old sendersBack references from receiver

This guards against multiple registration of the same
receiver for a given signal and sender leaking memory
as old back reference records build up.

Also removes old receiver instance from receivers
r   rP   TF)indexr/   r7   rl   ro   rF   )r&   r:   r9   r@   rq   oldReceiverfoundr=   sigrecsrecs              r   r5   r5     s    )
  &//&)'OOF26<<>=#-$%E!  $ ? +2#  s   B 
BBc                     [        U 5      n[        R                  US5      nX;   a   UR                  U5        X;   a  M  U(       d	   [        U	 gg!    M  = f! [         a     gf = f)zBDo the actual removal of back reference from receiver to senderkeyr   T)r.   r6   r7   r)   rD   )r9   r&   receiverkeyrR   s       r   ro   ro     sq    X,K
//;
,C

	JJ	# 

 	[* 	  		s   A A A
A&%A&)r   r2   
pydispatchr   r   r   r   r   r1   r   r0   ReferenceTypeBoundMethodWeakrefrM   r/   r4   r6   rB   rH   rJ   rN   rS   r\   r^   r-   rG   r'   rh   r5   ro   r   r   r   <module>r|      s   6  3 3' '
:  f $ L	&&(B(BC
 !4 ]B !$Cd 5+n  .& "C 8 I .^ ) *;:-&0@r   