
    +h*                     >   d Z ddlmZ ddlZddlmZ ddlmZ ddlmZ dd	lm	Z	  e	j                  e      Zd
 Z G d de      Z G d de      Z G d de      Zd Zd Z G d d e	j*                  ee            Z G d de      Z G d de      Z G d de      Zy)a  Base implementation classes.

The public-facing ``Events`` serves as the base class for an event interface;
its public attributes represent different kinds of events.   These attributes
are mirrored onto a ``_Dispatch`` class, which serves as a container for
collections of listener functions.   These collections are represented both
at the class level of a particular ``_Dispatch`` class as well as within
instances of ``_Dispatch``.

    )absolute_importN   )_ClsLevelDispatch)_EmptyListener)_JoinedListener   )utilc                 Z    | j                  d       xr | dk7  xs | j                  d      S )N_dispatch	_sa_event)
startswith)names    H/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/event/base.py_is_event_namer      s3     OOC  7TZ%7&		%&    c                       e Zd ZdZd Zy)_UnpickleDispatchzSerializable callable that re-generates an instance of
    :class:`_Dispatch` given a particular :class:`.Events` subclass.

    c                     |j                   D ]:  }d|j                  v s|j                  d   j                  j                  |      c S  t	        d      )Nr   z*No class with a 'dispatch' member present.)__mro____dict__r   
_for_classAttributeError)self_instance_clsclss      r   __call__z_UnpickleDispatch.__call__/   sX     (( 	OCS\\)||J/88CC! 	O !!MNNr   N)__name__
__module____qualname____doc__r    r   r   r   r   )   s    
Or   r   c                       e Zd ZdZdZ ej                         ZddZd Z	e
d        Ze
d        Zd Zd	 Zd
 Zd ZddZd Zy)	_Dispatcha;  Mirror the event listening definitions of an Events class with
    listener collections.

    Classes which define a "dispatch" member will return a
    non-instantiated :class:`._Dispatch` subclass when the member
    is accessed at the class level.  When the "dispatch" member is
    accessed at the instance level of its owner, an instance
    of the :class:`._Dispatch` class is returned.

    A :class:`._Dispatch` class is generated for each :class:`.Events`
    class defined, by the :func:`._create_dispatcher_class` function.
    The original :class:`.Events` classes remain untouched.
    This decouples the construction of :class:`.Events` subclasses from
    the implementation used by the event internals, and allows
    inspecting tools like Sphinx to work in an unsurprising
    way against the public API.

    )_parentr   r   _empty_listenersNc           	         || _         || _        |r	 | j                  |   | _        y i | _        y # t        $ rL |j
                  D ci c]  }|j                  t        ||       nc c}w c}x| _        | j                  |<   Y y w xY wN)r%   r   _empty_listener_regr&   KeyError_event_descriptorsr   r   )r   parentinstance_clslss       r   __init__z_Dispatch.__init__S   s    )(,(@(@(N% %'D!  
 %77 GG^B== %(@(@ )s   / BA%$BBc                     	 | j                   |   }t        | |j                  |       |S # t        $ r t	        |      w xY wr(   )r&   setattrr   r*   r   )r   r   r.   s      r   __getattr__z_Dispatch.__getattr__d   sJ    	&&t,B D"''2&I	  	' &&	's   * ?c              #   J   K   | j                   D ]  }t        | |        y wr(   )_event_namesgetattr)r   ks     r   r+   z_Dispatch._event_descriptorso   s*     "" 	#A $""	#s   !#c                 .    | j                   j                  S r(   )_events_listenr   s    r   r9   z_Dispatch._listenv   s    ||###r   c                 &    | j                  | |      S r(   )	__class__)r   r-   s     r   r   z_Dispatch._for_classz   s    ~~dL11r   c                 <    |j                   }| j                  |      S r(   )r<   r   )r   instancer-   s      r   _for_instancez_Dispatch._for_instance}   s    ))|,,r   c                     d| j                   j                  vrFt        d| j                   j                  z  t        fd| j
                  i      }|| j                   _        | j                  | |      S )zCreate a 'join' of this :class:`._Dispatch` and another.

        This new dispatcher will dispatch events to both
        :class:`._Dispatch` objects.

        _joined_dispatch_clszJoined%s	__slots__)r<   r   typer   _JoinedDispatcherr4   rA   )r   otherr   s      r   _joinz_Dispatch._join   sg     ")@)@@T^^444"$d//0C 36DNN/((u55r   c                 0    t               | j                  ffS r(   )r   r   r:   s    r   
__reduce__z_Dispatch.__reduce__   s     "T%7%7$999r   c                     |j                   D ]I  }t        |t              rt        | |j                        j                  |       j                  ||       K y)zIPopulate from the listeners in another :class:`_Dispatch`
        object.)only_propagateN)r+   
isinstancer   r5   r   
for_modify_update)r   rE   rJ   r.   s       r   rM   z_Dispatch._update   sT     ** 	B"n-D"''"--d3;;> < 	r   c                 d    | j                   D ]!  }|j                  |       j                          # y r(   )r+   rL   clear)r   r.   s     r   _clearz_Dispatch._clear   s,    )) 	(BMM$%%'	(r   r(   )T)r   r   r    r!   rB   weakrefWeakKeyDictionaryr)   r/   r2   propertyr+   r9   r   r?   rF   rH   rM   rP   r"   r   r   r$   r$   9   sp    * KI3'335'"	 # # $ $2-6":(r   r$   c                       e Zd ZdZd Zy)
_EventMetazKIntercept new Event subclasses and create
    associated _Dispatch classes.c                 P    t        | |||       t        j                  | |||       y r(   )_create_dispatcher_classrC   r/   )r   	classnamebasesdict_s       r   r/   z_EventMeta.__init__   s"     i>c9eU3r   N)r   r   r    r!   r/   r"   r   r   rU   rU      s    %4r   rU   c           
      ^   t        | d      r| j                  j                  }nt        }|D cg c]  }t	        |      s| }}t        d|z  |fd|i      }||_        | j                  | |      }|j                  D ]4  }t        ||t        | ||                t        |   j                  |        6 |j                  D ]}  }	t        |	t              s|	t        us|	j                  j                  j                  D ]>  }
t        ||
j                   |
       |j                  j                  |
j                          @  t#        | dd      r\| j$                  }t        |d      r)d|j&                  v rt)        |       | j$                  _        yt+        |       | j$                  _        yyc c}w )zRCreate a :class:`._Dispatch` class corresponding to an
    :class:`.Events` class.r   z
%sDispatchrB   _dispatch_targetN_slots_dispatch)hasattrr   r<   r$   r   rC   r4   _set_dispatchr1   r   _registrarsappend	__bases__
issubclassr8   r+   r   r5   r\   rB   slots_dispatcher
dispatcher)r   rX   rY   rZ   dispatch_baser6   event_namesdispatch_clsdispatch_instsuper_r.   the_clss               r   rW   rW      s    sJ..!#9~a'819K9y ="2[+4NL !,L%%c<8M&& #q"3Cq"BCAc"# (( :fi(V9-Dnn--@@ :rww3))009:: s&-&&G[)!W%6%66,<S,AC  ),6sOC  ) .% :s
   F*F*c                     | j                   j                  D ]+  }t        |   j                  |        t        |   r%t        |= - y r(   )r   r4   r`   remove)r   r6   s     r   _remove_dispatcherrn      s;    \\&& Ac"1~Ar   c                   j    e Zd ZdZed        Zed        Ze	 	 	 	 dd       Zed        Z	ed        Z
y)	Eventsz>Define event listening functions for a particular target type.c                 B     |d       | _         | |_        | j                   S r(   )r   r8   )r   rh   s     r   r_   zEvents._set_dispatch   s"     $D)"||r   c                    fd}fd}t        d      ri || j                  j                        sI |t        | j                  j                        s( |t              r || j                  j                        rS y y y )Nc                  ,    t        fd| D              S )Nc              3   J   K   | ]  }t        j                  |        y wr(   )rK   r   ).0ttargets     r   	<genexpr>z;Events._accept_with.<locals>.dispatch_is.<locals>.<genexpr>   s     E!z&//15Es    #)all)typesrw   s    r   dispatch_isz(Events._accept_with.<locals>.dispatch_is   s    EuEEEr   c                 D    t        j                  j                  |       S r(   )rK   r   r,   )rv   rw   s    r   dispatch_parent_isz/Events._accept_with.<locals>.dispatch_parent_is   s    foo44a88r   r   )r^   r   r<   rC   rD   )r   rw   r{   r}   s    `  r   _accept_withzEvents._accept_with   sr    	F	9
 6:&CLL223tS\\%;%;< 12*3<<+A+AB  C 3 'r   c                 .    |j                  ||||       y )N)	propagateinsertnamedasyncio)base_listen)r   	event_keyr   r   r   r   s         r   r9   zEvents._listen   s      	eW 	 	
r   c                 $    |j                          y r(   )rm   )r   r   s     r   _removezEvents._remove  s    r   c                 8    | j                   j                          y r(   )r   rP   )r   s    r   rP   zEvents._clear  s    r   N)FFFF)r   r   r    r!   staticmethodr_   classmethodr~   r9   r   rP   r"   r   r   rp   rp      su    H   (  

 

    r   rp   c                   @    e Zd ZdZdZd Zd Zed        Zed        Z	y)rD   z5Represent a connection between two _Dispatch objects.localr,   r   c                 V    || _         || _        | j                   j                  | _        y r(   r   )r   r   r,   s      r   r/   z_JoinedDispatcher.__init__  s"    
!ZZ55r   c                     t        | j                  |      }t        | j                  |j                  |      }t        | |j                  |       |S r(   )r5   r   r   r,   r   r1   )r   r   r.   jls       r   r2   z_JoinedDispatcher.__getattr__   s?     TZZ&T[["''26bggr"	r   c                 .    | j                   j                  S r(   )r,   r9   r:   s    r   r9   z_JoinedDispatcher._listen(      {{"""r   c                 .    | j                   j                  S r(   )r,   r8   r:   s    r   r8   z_JoinedDispatcher._events,  r   r   N)
r   r   r    r!   rB   r/   r2   rS   r9   r8   r"   r   r   rD   rD     s<    ?2I6
 # # # #r   rD   c                       e Zd ZdZd Zd Zy)re   zDescriptor used by target classes to
    deliver the _Dispatch class at the class level
    and produce new _Dispatch instances for target
    instances.

    c                 4    |j                   | _         || _        y r(   )r   events)r   r   s     r   r/   zdispatcher.__init__9  s    r   c                     || j                   S | j                   j                  |      }	 ||j                  d<   |S # t        $ r/}t	        j
                  t        d|d      |       Y d }~|S d }~ww xY w)Nr   ztarget z> doesn't have __dict__, should it be defining _slots_dispatch?)replace_context)r   r?   r   r   r	   raise_	TypeError)r   objr   dispaes        r   __get__zdispatcher.__get__=  s~    ;== }}**3/		'+CLL$   	KK369 !#  	s   < 	A4$A//A4N)r   r   r    r!   r/   r   r"   r   r   re   re   1  s    r   re   c                       e Zd Zd Zy)rd   c                     || j                   S t        |d      r|j                  S | j                   j                  |      }||_        |S )Nr]   )r   r^   r]   r?   )r   r   r   r   s       r   r   zslots_dispatcher.__get__P  sI    ;== 3)*&&&}}**3/"r   N)r   r   r    r   r"   r   r   rd   rd   O  s    	r   rd   )r!   
__future__r   rQ   attrr   r   r    r	   defaultdictlistr`   r   objectr   r$   rC   rU   rW   rn   with_metaclassrp   rD   re   rd   r"   r   r   <module>r      s   	 '  #   !  dt$&O O h( h(V4 4&<R6 T  V4 6r# #6 <
z 
r   