
    EvgqE                         d dl Z d dlZd dlZd dlZd dlmZmZmZ d dlm	Z	  ej
        d          Zd Z ed          Z e            Z G d d          Zd ZdS )	    N)async_to_synciscoroutinefunctionsync_to_async)func_accepts_kwargszdjango.dispatchc                     t          | d          r(t          | j                  t          | j                  fS t          |           S )N__func__)hasattrid__self__r   )targets    W/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/dispatch/dispatcher.py_make_idr      s?    vz"" :6?##R%8%899f::    c                   d    e Zd ZdZddZddZddZddZd	 Zd
 Z	d Z
d Zd Zd Zd ZddZdS )Signalz
    Base class for all signals

    Internal attributes:

        receivers
            { receiverkey (id) : weakref(receiver) }
    Fc                     g | _         t          j                    | _        || _        |rt          j                    ni | _        d| _        dS )z&
        Create a new signal.
        FN)		receivers	threadingLocklockuse_cachingweakrefWeakKeyDictionarysender_receivers_cache_dead_receivers)selfr   s     r   __init__zSignal.__init__#   sP     N$$	& FQ&Xg&?&A&A&AVX#$r   NTc                   	 ddl m} |j        rC|j        r<t	          |          st          d          t          |          st          d          |r|t          |          f	nt          |          t          |          f	t          |          }|rft          j        }|}t          |d          r#t          |d          rt          j        }|j        } ||          }t          j        || j                   | j        5  |                                  t'          	fd| j        D                       s| j                            	||f           | j                                         ddd           dS # 1 swxY w Y   dS )	a  
        Connect receiver to sender for signal.

        Arguments:

            receiver
                A function or an instance method which is to receive signals.
                Receivers must be hashable objects. Receivers can be
                asynchronous.

                If weak is True, then receiver must be weak referenceable.

                Receivers must be able to accept keyword arguments.

                If a receiver is connected with a dispatch_uid argument, it
                will not be added if another receiver was already connected
                with that dispatch_uid.

            sender
                The sender to which the receiver should respond. Must either be
                a Python object, or None to receive events from any sender.

            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.

            dispatch_uid
                An identifier used to uniquely identify a particular instance of
                a receiver. This will usually be a string, though it may be
                anything hashable.
        r   )settingsz"Signal receivers must be callable.z:Signal receivers must accept keyword arguments (**kwargs).r   r   c              3   ,   K   | ]\  }}}|k    V  d S N ).0r_key_
lookup_keys      r   	<genexpr>z!Signal.connect.<locals>.<genexpr>s   s.      MM{uau
*MMMMMMr   N)django.confr   
configuredDEBUGcallable	TypeErrorr   
ValueErrorr   r   r   refr	   
WeakMethodr   finalize_remove_receiverr   _clear_dead_receiversanyr   appendr   clear)
r   receiversenderweakdispatch_uidr   is_asyncr.   receiver_objectr&   s
            @r   connectzSignal.connect2   s   D 	)(((((  	8> 	H%% F DEEE&x00  P    	@&(8(89JJ"8,,hv.>.>?J&x00 	E+C&Ox,, 4:1N1N 4("*"3s8}}H_d.CDDDY 	0 	0&&(((MMMMdnMMMMM H%%z8X&FGGG'--///		0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s   A+E::E>E>c                    |r|t          |          f}nt          |          t          |          f}d}| j        5  |                                  t          t	          | j                            D ]#}| j        |         ^}}||k    rd}| j        |=  n$| j                                         ddd           n# 1 swxY w Y   |S )a  
        Disconnect receiver from sender for signal.

        If weak references are used, disconnect need not be called. The receiver
        will be removed from dispatch automatically.

        Arguments:

            receiver
                The registered receiver to disconnect. May be none if
                dispatch_uid is specified.

            sender
                The registered sender to disconnect

            dispatch_uid
                the unique identifier of the receiver to disconnect
        FTN)r   r   r2   rangelenr   r   r5   )	r   r6   r7   r9   r&   disconnectedindexr$   r%   s	            r   
disconnectzSignal.disconnectw   s#   &  	@&(8(89JJ"8,,hv.>.>?JY 	0 	0&&(((s4>2233   N51	J&&#'Lu-E ' '--///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 s   A3B;;B?B?c                 n    |                      |          \  }}t          |          pt          |          S r!   )_live_receiversbool)r   r7   sync_receiversasync_receiverss       r   has_listenerszSignal.has_listeners   s5    *.*>*>v*F*F'N##<tO'<'<<r   c                 L     j         r! j                                      t          u rg S g }                               \  }|D ]$} |d d}|                    ||f           %r2 fd}|                     t          |                                 |S )a  
        Send signal from sender to all connected receivers.

        If any receiver raises an error, the error propagates back through send,
        terminating the dispatch loop. So it's possible that all receivers
        won't be called if an error is raised.

        If any receivers are asynchronous, they are called after all the
        synchronous receivers via a single call to async_to_sync(). They are
        also executed concurrently with asyncio.gather().

        Arguments:

            sender
                The sender of the signal. Either a specific object or None.

            named
                Named arguments which will be passed to receivers.

        Return a list of tuple pairs [(receiver, response), ... ].
        signalr7   c                  l   K   t          j        fdD               d {V } t          |           S )Nc              3   .   K   | ]} |dd V  dS rJ   Nr"   r"   r#   r6   namedr   r7   s     r   r'   z-Signal.send.<locals>.asend.<locals>.<genexpr>   sN        $ !EVEEuEE     r   asynciogatherzip)async_responsesrG   rP   r   r7   s    r   asendzSignal.send.<locals>.asend   ss      (/     (7  ) # # # # # # ?O<<<r   r"   )r   r   getNO_RECEIVERSrD   r4   extendr   )	r   r7   rP   	responsesrF   r6   responserV   rG   s	   ```     @r   sendzSignal.send   s    . 	*..v66,FFI	*.*>*>v*F*F'& 	3 	3HxDtFDDeDDHh12222 	5= = = = = = = = 1]51133444r   c                    K    j         r! j                                      t          u rg S                                \  }rt
           fd            }nd }t          j         |            t          j         fd|D                         d{V \  }}|                    t          ||                     |S )a~  
        Send signal from sender to all connected receivers in async mode.

        All sync receivers will be wrapped by sync_to_async()
        If any receiver raises an error, the error propagates back through
        send, terminating the dispatch loop. So it's possible that all
        receivers won't be called if an error is raised.

        If any receivers are synchronous, they are grouped and called behind a
        sync_to_async() adaption before executing any asynchronous receivers.

        If any receivers are asynchronous, they are grouped and executed
        concurrently with asyncio.gather().

        Arguments:

            sender
                The sender of the signal. Either a specific object or None.

            named
                Named arguments which will be passed to receivers.

        Return a list of tuple pairs [(receiver, response), ...].
        c                  Z    g } D ]$} |dd}|                      ||f           %| S NrJ   r"   )r4   )rZ   r6   r[   rP   r   r7   rF   s      r   	sync_sendzSignal.asend.<locals>.sync_send   sU    	 . ; ;H'xLtFLLeLLH$$h%9::::  r   c                  
   K   g S r!   r"   r"   r   r   r`   zSignal.asend.<locals>.sync_send         	r   c              3   .   K   | ]} |dd V  dS rN   r"   rO   s     r   r'   zSignal.asend.<locals>.<genexpr>   sN          HADAA5AA     r   N
r   r   rW   rX   rD   r   rR   rS   rY   rT   )r   r7   rP   rG   r`   rZ   rU   rF   s   ```    @r   rV   zSignal.asend   s<     4 	*..v66,FFI*.*>*>v*F*F' 	! ! ! ! ! ! ! ]! !   ,3>IKKN     $3  ,
 ,
 &
 &
 &
 &
 &
 &
"	? 	_o>>???r   c                 L    t                               d|j        ||           d S )Nz-Error calling %s in Signal.send_robust() (%s))exc_info)loggererror__qualname__)r   r6   errs      r   _log_robust_failurezSignal._log_robust_failure  s6    ;!	 	 	
 	
 	
 	
 	
r   c                    	
  j         r! j                                      t          u rg S g }                               \  }
|D ]i}	  |d d}|                    ||f           &# t          $ r7}                     ||           |                    ||f           Y d}~bd}~ww xY w
r7 fd		
fd}|                     t          |                                 |S )a3  
        Send signal from sender to all connected receivers catching errors.

        If any receivers are asynchronous, they are called after all the
        synchronous receivers via a single call to async_to_sync(). They are
        also executed concurrently with asyncio.gather().

        Arguments:

            sender
                The sender of the signal. Can be any Python object (normally one
                registered with a connect if you actually want something to
                occur).

            named
                Named arguments which will be passed to receivers.

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

        If any receiver raises an error (specifically any subclass of
        Exception), return the error instance as the result for that receiver.
        rJ   Nc                    K   	  | dd d {V }n/# t           $ r"}                    | |           |cY d }~S d }~ww xY w|S r_   	Exceptionrk   r6   r[   rj   rP   r   r7   s      r   asend_and_wrap_exceptionz4Signal.send_robust.<locals>.asend_and_wrap_exception:  s      %-X%RT&%R%RE%R%RRRRRRRHH    ,,Xs;;;JJJJJJ      
A>AAc                  h   K   t          j        fdD               d {V } t          |           S )Nc              3   .   K   | ]} |          V  d S r!   r"   r#   r6   rq   s     r   r'   z4Signal.send_robust.<locals>.asend.<locals>.<genexpr>D  sB        $ 10::     r   rQ   )rU   rq   rG   s    r   rV   z!Signal.send_robust.<locals>.asendB  si      (/   (7  ) # # # # # # ?O<<<r   r"   )
r   r   rW   rX   rD   r4   ro   rk   rY   r   )r   r7   rP   rZ   rF   r6   r[   rj   rV   rq   rG   s   ```      @@r   send_robustzSignal.send_robust  sw   0 	*..v66,FFI 	*.*>*>v*F*F'& 	7 	7H7#8H4HH%HH
   (H!56666	  2 2 2((3777  (C111111112
  	5             = = = = = = 1]51133444s   A22
B3<-B..B3c                    K    j         r! j                                      t          u rg S                                \  }rt
           fd            }nd } fdt          j         |            t          j        fd|D                         d{V \  }}|                    t          ||                     |S )at  
        Send signal from sender to all connected receivers catching errors.

        If any receivers are synchronous, they are grouped and called behind a
        sync_to_async() adaption before executing any asynchronous receivers.

        If any receivers are asynchronous, they are grouped and executed
        concurrently with asyncio.gather.

        Arguments:

            sender
                The sender of the signal. Can be any Python object (normally one
                registered with a connect if you actually want something to
                occur).

            named
                Named arguments which will be passed to receivers.

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

        If any receiver raises an error (specifically any subclass of
        Exception), return the error instance as the result for that receiver.
        c                      g } D ]i}	  |dd}|                      ||f           &# t          $ r7}                    ||           |                      ||f           Y d }~bd }~ww xY w| S r_   )r4   ro   rk   )rZ   r6   r[   rj   rP   r   r7   rF   s       r   r`   z&Signal.asend_robust.<locals>.sync_sends  s    	 . ? ?H?#+8#P4#P#P%#P#P
 "(((H)=>>>>	 % : : :003???!(((C99999999:
 ! s   ,
A--A((A-c                  
   K   g S r!   r"   r"   r   r   r`   z&Signal.asend_robust.<locals>.sync_send  rb   r   c                    K   	  | dd d {V }n/# t           $ r"}                    | |           |cY d }~S d }~ww xY w|S r_   rn   rp   s      r   rq   z5Signal.asend_robust.<locals>.asend_and_wrap_exception  s      !)!Nf!N!N!N!NNNNNNN   ((3777





 Orr   c              3   .   K   | ]} |          V  d S r!   r"   ru   s     r   r'   z&Signal.asend_robust.<locals>.<genexpr>  s/      UU**844UUUUUUr   Nrd   )	r   r7   rP   rG   r`   rZ   rU   rq   rF   s	   ```    @@r   asend_robustzSignal.asend_robustN  sI     4 	*..v66,FFI +/*>*>v*F*F' 	
! 
! 
! 
! 
! 
! 
! ]
! 
!  	 	 	 	 	 	 	 ,3>IKKNUUUU_UUU,
 ,
 &
 &
 &
 &
 &
 &
"	? 	_o>>???r   c                 R    | j         rd| _         d | j        D             | _        d S d S )NFc                 r    g | ]4}t          |d          t          j                  r |d                      2|5S )   )
isinstancer   ReferenceType)r#   rs     r   
<listcomp>z0Signal._clear_dead_receivers.<locals>.<listcomp>  sL       "1Q4)>?? EIAaDFFN DRNNr   )r   r   )r   s    r   r2   zSignal._clear_dead_receivers  sE     	#(D    DNNN	 	r   c                    d}| j         r.| j        s'| j                            |          }|t          u rg g fS || j        5  |                                  t          |          }g }| j        D ]1\  \  }}}}|t          k    s||k    r|
                    ||f           2| j         r|st          | j        |<   n
|| j        |<   ddd           n# 1 swxY w Y   g }g }	|D ]\  }}t          |t          j                  r: |            }|-|r|	
                    |           C|
                    |           Y|r|	
                    |           q|
                    |           ||	fS )z
        Filter sequence of receivers to get resolved, live receivers.

        This checks for weak references and resolves them, then returning only
        live receivers.
        N)r   r   r   rW   rX   r   r2   r   r   NONE_IDr4   r   r   r   )
r   r7   r   	senderkey_receiverkeyr_senderkeyr6   r:   non_weak_sync_receiversnon_weak_async_receiverss
             r   rD   zSignal._live_receivers  s"    	 	D$8 	377??I L((2v H H**,,,$V,,		GK~ ? ?C/\;8"g--	1I1I!(((H)=>>># H$ H>J3F;; ?H3F;H H H H H H H H H H H H H H H #%#% "+ 	= 	=Hh(G$9:: =#8::' A077AAAA/66x@@@ =,33H====+228<<<<&(@@@s   BCCCc                     d| _         d S )NT)r   )r   r6   s     r   r1   zSignal._remove_receiver  s      $r   )F)NTN)NNNr!   )__name__
__module__ri   __doc__r   r<   rB   rH   r\   rV   rk   rv   r|   r2   rD   r1   r"   r   r   r   r      s         % % % %C0 C0 C0 C0J" " " "H= = = =, , ,\8 8 8t
 
 
= = =~F F FP  ,A ,A ,A\$ $ $ $ $ $r   r   c                       fd}|S )a~  
    A decorator for connecting receivers to signals. Used by passing in the
    signal (or list of signals) and keyword arguments to connect::

        @receiver(post_save, sender=MyModel)
        def signal_receiver(sender, **kwargs):
            ...

        @receiver([post_save, post_delete], sender=MyModel)
        def signals_receiver(sender, **kwargs):
            ...
    c                     t          t          t          f          rD ]} |j        | fi  n j        | fi  | S r!   )r   listtupler<   )funcskwargsrK   s     r   
_decoratorzreceiver.<locals>._decorator  sk    ftUm,, 	+ * *	$))&))))* FN4**6***r   r"   )rK   r   r   s   `` r   r6   r6     s*          r   )rR   loggingr   r   asgiref.syncr   r   r   django.utils.inspectr   	getLoggerrg   r   r   objectrX   r   r6   r"   r   r   <module>r      s           J J J J J J J J J J 4 4 4 4 4 4		,	-	-   (4.. vxx|$ |$ |$ |$ |$ |$ |$ |$~    r   