
    ؄_&                     F   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dS )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                 :    |                      d           o| dk    S )N_dispatch)
startswith)names    Z/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/sqlalchemy/event/base.py_is_event_namer      s!    s###:
(::    c                       e Zd ZdZd ZdS )_UnpickleDispatchzSerializable callable that re-generates an instance of
    :class:`_Dispatch` given a particular :class:`.Events` subclass.

    c                     |j         D ]2}d|j        v r'|j        d         j                            |          c S 3t	          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__)   sh     ( 	O 	OCS\))|J/8CC!     *
 !!MNNNr   N)__name__
__module____qualname____doc__r    r   r   r   r   #   s2         
O O O O 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dS )	_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                     || _         | _        rH	 | j                 | _        d S # t          $ r& fd|j        D             x| _        | j        <   Y d S w xY wi | _        d S )Nc                 <    i | ]}|j         t          |          S r!   )r   r   ).0lsinstance_clss     r   
<dictcomp>z&_Dispatch.__init__.<locals>.<dictcomp>W   s7        G^B==  r   )r$   r   _empty_listener_regr%   KeyError_event_descriptors)r   parentr*   s     `r   __init__z_Dispatch.__init__M   s    ) 	'(,(@(N%%%      $7  %(@ ) ) ) ) %'D!!!s   ' ,AAc                     	 | j         |         }t          | |j        |           |S # t          $ r t	          |          w xY wN)r%   setattrr   r-   r   )r   r   r)   s      r   __getattr__z_Dispatch.__getattr__^   sZ    	&t,B D"'2&&&I	  	' 	' 	' &&&	's	   ' Ac              #   B   K   | j         D ]}t          | |          V  d S r2   )_event_namesgetattr)r   ks     r   r.   z_Dispatch._event_descriptorsi   s=      " 	# 	#A $""""""	# 	#r   c                     | j         j        S r2   )_events_listenr   s    r   r;   z_Dispatch._listenp   s    |##r   c                 .    |                      | |          S r2   )	__class__)r   r*   s     r   r   z_Dispatch._for_classt   s    ~~dL111r   c                 :    |j         }|                     |          S r2   )r>   r   )r   instancer*   s      r   _for_instancez_Dispatch._for_instancew   s    )|,,,r   c                     d| j         j        vr7t          d| j         j        z  t          fd| j        i          }|| 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   _JoinedDispatcherr6   rC   )r   otherr   s      r   _joinz_Dispatch._join{   sc     ")@@@T^44"$d/0 C 36DN/((u555r   c                 .    t                      | j        ffS r2   )r   r   r<   s    r   
__reduce__z_Dispatch.__reduce__   s     ""T%7$999r   Tc                     |j         D ]U}t          |t                    rt          | |j                                      |                               ||           VdS )zIPopulate from the listeners in another :class:`_Dispatch`
        object.)only_propagateN)r.   
isinstancer   r7   r   
for_modify_update)r   rG   rL   r)   s       r   rO   z_Dispatch._update   sv     * 	 	B"n-- D"'""--d33;;> <    	 	r   c                 h    | j         D ])}|                    |                                            *d S r2   )r.   rN   clear)r   r)   s     r   _clearz_Dispatch._clear   s?    ) 	( 	(BMM$%%''''	( 	(r   r2   )T)r   r   r   r    rD   weakrefWeakKeyDictionaryr,   r0   r4   propertyr.   r;   r   rA   rH   rJ   rO   rR   r!   r   r   r#   r#   3   s         * KI3'355' ' ' '"	 	 	 # # X# $ $ X$2 2 2- - -6 6 6": : :   ( ( ( ( (r   r#   c                       e Zd ZdZd ZdS )
_EventMetazKIntercept new Event subclasses and create
    associated _Dispatch classes.c                 d    t          | |||           t                              | |||           d S r2   )_create_dispatcher_classrE   r0   )r   	classnamebasesdict_s       r   r0   z_EventMeta.__init__   s4     i>>>c9eU33333r   N)r   r   r   r    r0   r!   r   r   rW   rW      s-        % %4 4 4 4 4r   rW   c           
         t          | d          r| j        j        }nt          }d |D             }t	          d|z  |fd|i          }||_        |                     | |          }|j        D ]G}t          ||t          | ||                              t          |         
                    |            H|j        D ]i}	t          |	t                    rR|	t          urI|	j        j        j        D ]7}
t          ||
j        |
           |j        
                    |
j                   8jt!          | dd          rt#          |           | j        _        dS dS )zRCreate a :class:`._Dispatch` class corresponding to an
    :class:`.Events` class.r   c                 0    g | ]}t          |          |S r!   )r   )r(   r8   s     r   
<listcomp>z,_create_dispatcher_class.<locals>.<listcomp>   s%    999~a'8'891999r   z
%sDispatchrD   _dispatch_targetN)hasattrr   r>   r#   rE   r6   _set_dispatchr3   r   _registrarsappend	__bases__
issubclassr:   r.   r   r7   
dispatcherr`   )r   rZ   r[   r\   dispatch_baseevent_namesdispatch_clsdispatch_instr8   super_r)   s              r   rY   rY      sv    sJ ".!99e999Ky ="2[+4N L !,L%%c<88M& # #q"3Cq"B"BCCCAc""""( : :fi(( 	:V9-D-Dn-@ : :rw333)009999s&-- 8(23%%%8 8r   c                     | j         j        D ]7}t          |                             |            t          |         st          |= 8d S r2   )r   r6   rc   remove)r   r8   s     r   _remove_dispatcherro      sL    \&  Ac"""1~ 	A r   c                       e Zd ZdZed             Zed             Zed	d            Zed             Z	ed             Z
dS )
Eventsz>Define event listening functions for a particular target type.c                 >     |d           | _         | |_        | j         S r2   )r   r:   )r   rj   s     r   rb   zEvents._set_dispatch   s%     $|D))"|r   c                     fd}fd}t          d          rW || j        j                  s@ |t          | j        j                  s% |t                    r || j        j                  rS d S d S d S )Nc                  :    t          fd| D                       S )Nc              3   B   K   | ]}t          j        |          V  d S r2   )rM   r   )r(   ttargets     r   	<genexpr>z;Events._accept_with.<locals>.dispatch_is.<locals>.<genexpr>   s/      EE!z&/155EEEEEEr   )all)typesrw   s    r   dispatch_isz(Events._accept_with.<locals>.dispatch_is   s&    EEEEuEEEEEEr   c                 8    t          j        j        |           S r2   )rM   r   r/   )rv   rw   s    r   dispatch_parent_isz/Events._accept_with.<locals>.dispatch_parent_is   s    fo4a888r   r   )ra   r   r>   rE   rF   )r   rw   r{   r}   s    `  r   _accept_withzEvents._accept_with   s    	F 	F 	F 	F 	F	9 	9 	9 	9 	9
 6:&& 		CL233;tS\%;<<  K 122	
 +*3<+ABB 		 		   r   Fc                 6    |                     |||           d S )N)	propagateinsertnamed)base_listen)r   	event_keyr   r   r   s        r   r;   zEvents._listen   s#    	&NNNNNr   c                 .    |                                  d S r2   )rn   )r   r   s     r   _removezEvents._remove   s    r   c                 8    | j                                          d S r2   )r   rR   )r   s    r   rR   zEvents._clear   s    r   N)FFF)r   r   r   r    staticmethodrb   classmethodr~   r;   r   rR   r!   r   r   rq   rq      s        HH  \   [( O O O [O   [   [  r   rq   c                   N    e Zd ZdZdZd Zd Zed             Zed             Z	dS )rF   z5Represent a connection between two _Dispatch objects.localr/   r   c                 D    || _         || _        | j         j        | _        d S r2   r   )r   r   r/   s      r   r0   z_JoinedDispatcher.__init__  s#    
!Z5r   c                     t          | j        |          }t          | j        |j        |          }t          | |j        |           |S r2   )r7   r   r   r/   r   r3   )r   r   r)   jls       r   r4   z_JoinedDispatcher.__getattr__
  sC     TZ&&T["'266bgr"""	r   c                     | j         j        S r2   )r/   r;   r<   s    r   r;   z_JoinedDispatcher._listen      {""r   c                     | j         j        S r2   )r/   r:   r<   s    r   r:   z_JoinedDispatcher._events  r   r   N)
r   r   r   r    rD   r0   r4   rU   r;   r:   r!   r   r   rF   rF      ss        ??2I6 6 6
   # # X# # # X# # #r   rF   c                       e Zd ZdZd Zd ZdS )rg   zDescriptor used by target classes to
    deliver the _Dispatch class at the class level
    and produce new _Dispatch instances for target
    instances.

    c                 ,    |j         | _         || _        d S r2   )r   events)r   r   s     r   r0   zdispatcher.__init__#  s    r   c                 `    || j         S | j                             |          x|j        d<   }|S )Nr   )r   rA   r   )r   objr   disps       r   __get__zdispatcher.__get__'  s5    ;= *.-*E*Ec*J*JJZ 4r   N)r   r   r   r    r0   r   r!   r   r   rg   rg     s<               r   rg   )r    
__future__r   rS   attrr   r   r    r	   defaultdictlistrc   r   objectr   r#   rE   rW   rY   ro   with_metaclassrq   rF   rg   r!   r   r   <module>r      s  	 	 ' & & & & &  # # # # # #             ! ! ! ! ! !       dt$$; ; ;O O O O O O O O h( h( h( h( h( h( h( h(V4 4 4 4 4 4 4 48 8 8D  - - - - - T V44 - - -`# # # # # # # #6         r   