o
    =a*                     @   s   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	
eZd
d ZG dd deZG dd deZG dd deZdd Zdd ZG dd de	eeZG dd deZG dd deZG d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                 C   s   |  d o	| dkp|  dS )N_dispatch	_sa_event)
startswith)name r   K/var/www/html/gps/gps/lib/python3.10/site-packages/sqlalchemy/event/base.py_is_event_name   s   r   c                   @      e Zd ZdZdd ZdS )_UnpickleDispatchzSerializable callable that re-generates an instance of
    :class:`_Dispatch` given a particular :class:`.Events` subclass.

    c                 C   s4   |j D ]}d|jv r|jd j|  S qtd)Nr
   z*No class with a 'dispatch' member present.)__mro____dict__r
   
_for_classAttributeError)self_instance_clsclsr   r   r   __call__/   s   

z_UnpickleDispatch.__call__N)__name__
__module____qualname____doc__r   r   r   r   r   r   )   s    r   c                   @   sx   e Zd ZdZdZe ZdddZdd Z	e
dd	 Ze
d
d Zdd Zdd Zdd Zdd ZdddZd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                    sb   || _  | _ r,z	| j  | _W d S  ty+    fdd|jD  | _| j < Y d S w i | _d S )Nc                    s   i | ]	}|j t| qS r   )r   r   ).0lsinstance_clsr   r   
<dictcomp>]   s    z&_Dispatch.__init__.<locals>.<dictcomp>)r    r   _empty_listener_regr!   KeyError_event_descriptors)r   parentr%   r   r$   r   __init__S   s   


z_Dispatch.__init__c                 C   s8   z| j | }W n ty   t|w t| |j| |S N)r!   r(   r   setattrr   )r   r   r#   r   r   r   __getattr__d   s   z_Dispatch.__getattr__c                 c   s    | j D ]}t| |V  qd S r,   )_event_namesgetattr)r   kr   r   r   r)   o   s   
z_Dispatch._event_descriptorsc                 C      | j jS r,   )_events_listenr   r   r   r   r4   v      z_Dispatch._listenc                 C   s   |  | |S r,   )	__class__)r   r%   r   r   r   r   z   s   z_Dispatch._for_classc                 C   s   |j }| |S r,   )r7   r   )r   instancer%   r   r   r   _for_instance}   s   
z_Dispatch._for_instancec                 C   s<   d| j jvrtd| j j 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__)r7   r   typer   _JoinedDispatcherr/   r:   )r   otherr   r   r   r   _join   s   
z_Dispatch._joinc                 C   s   t  | jffS r,   )r   r   r5   r   r   r   
__reduce__      z_Dispatch.__reduce__Tc                 C   s8   |j D ]}t|trqt| |j| j||d qdS )zIPopulate from the listeners in another :class:`_Dispatch`
        object.)only_propagateN)r)   
isinstancer   r0   r   
for_modify_update)r   r>   rB   r#   r   r   r   rE      s   

z_Dispatch._updatec                 C   s   | j D ]	}||   qd S r,   )r)   rD   clear)r   r#   r   r   r   _clear   s   
z_Dispatch._clearr,   )T)r   r   r   r   r;   weakrefWeakKeyDictionaryr'   r+   r.   propertyr)   r4   r   r9   r?   r@   rE   rG   r   r   r   r   r   9   s     




r   c                   @   r   )
_EventMetazKIntercept new Event subclasses and create
    associated _Dispatch classes.c                 C   s"   t | ||| t| ||| d S r,   )_create_dispatcher_classr<   r+   )r   	classnamebasesdict_r   r   r   r+      s   z_EventMeta.__init__N)r   r   r   r   r+   r   r   r   r   rK      s    rK   c                 C   s  t | dr
| jj}nt}dd |D }td| |fd|i}||_| | |}|jD ]}t||t| ||  t	| 
|  q*|jD ]!}	t|	trc|	turc|	jjjD ]}
t||
j|
 |j
|
j qRqBt| ddr| j}t |drd|jv rt| | j_dS t| | j_dS dS )	zRCreate a :class:`._Dispatch` class corresponding to an
    :class:`.Events` class.r
   c                 S   s   g | ]}t |r|qS r   )r   )r"   r1   r   r   r   
<listcomp>   s    z,_create_dispatcher_class.<locals>.<listcomp>z
%sDispatchr;   _dispatch_targetN_slots_dispatch)hasattrr
   r7   r   r<   r/   _set_dispatchr-   r   _registrarsappend	__bases__
issubclassr3   r)   r   r0   rQ   r;   slots_dispatcher
dispatcher)r   rM   rN   rO   dispatch_baseevent_namesdispatch_clsdispatch_instr1   super_r#   the_clsr   r   r   rL      s6   



rL   c                 C   s.   | j jD ]}t| |  t| st|= qd S r,   )r
   r/   rU   remove)r   r1   r   r   r   _remove_dispatcher   s   rb   c                   @   sV   e Zd ZdZedd Zedd Ze				dddZed	d
 Z	edd Z
dS )Eventsz>Define event listening functions for a particular target type.c                 C   s   |d | _ | |_| j S r,   )r
   r3   )r   r]   r   r   r   rT      s   
zEvents._set_dispatchc                    s`    fdd} fdd}t  dr*|| jjs(|t| jjs(|tr,|| jjr. S d S d S d S )Nc                     s   t  fdd| D S )Nc                 3   s    | ]	}t  j|V  qd S r,   )rC   r
   )r"   ttargetr   r   	<genexpr>   s    z;Events._accept_with.<locals>.dispatch_is.<locals>.<genexpr>)all)typesre   r   r   dispatch_is   s   z(Events._accept_with.<locals>.dispatch_isc                    s   t  jj| S r,   )rC   r
   r*   )rd   re   r   r   dispatch_parent_is   rA   z/Events._accept_with.<locals>.dispatch_parent_isr
   )rS   r
   r7   r<   r=   )r   rf   rj   rk   r   re   r   _accept_with   s   


zEvents._accept_withFc                 C   s   |j ||||d d S )N)	propagateinsertnamedasyncio)base_listen)r   	event_keyrm   rn   ro   rp   r   r   r   r4      s   	
zEvents._listenc                 C   s   |   d S r,   )ra   )r   rr   r   r   r   _remove  s   zEvents._removec                 C   s   | j   d S r,   )r
   rG   )r   r   r   r   rG     s   zEvents._clearN)FFFF)r   r   r   r   staticmethodrT   classmethodrl   r4   rs   rG   r   r   r   r   rc      s     



rc   c                   @   s<   e Zd ZdZdZdd Zdd Zedd Zed	d
 Z	dS )r=   z5Represent a connection between two _Dispatch objects.localr*   r   c                 C   s   || _ || _| j j| _d S r,   rv   )r   rw   r*   r   r   r   r+     s   z_JoinedDispatcher.__init__c                 C   s.   t | j|}t| j|j|}t| |j| |S r,   )r0   rw   r   r*   r   r-   )r   r   r#   jlr   r   r   r.      s   z_JoinedDispatcher.__getattr__c                 C   r2   r,   )r*   r4   r5   r   r   r   r4   (  r6   z_JoinedDispatcher._listenc                 C   r2   r,   )r*   r3   r5   r   r   r   r3   ,  r6   z_JoinedDispatcher._eventsN)
r   r   r   r   r;   r+   r.   rJ   r4   r3   r   r   r   r   r=     s    
r=   c                   @   s    e Zd ZdZdd Zdd ZdS )rZ   zDescriptor used by target classes to
    deliver the _Dispatch class at the class level
    and produce new _Dispatch instances for target
    instances.

    c                 C   s   |j | _ || _d S r,   )r
   events)r   ry   r   r   r   r+   9  s   
zdispatcher.__init__c              
   C   sj   |d u r| j S | j |}z||jd< W |S  ty4 } ztjtd|f |d W Y d }~|S d }~ww )Nr
   zGtarget %r doesn't have __dict__, should it be defining _slots_dispatch?)replace_context)r
   r9   r   r   r   raise_	TypeError)r   objr   dispaer   r   r   __get__=  s$   	zdispatcher.__get__N)r   r   r   r   r+   r   r   r   r   r   rZ   1  s    rZ   c                   @   s   e Zd Zdd ZdS )rY   c                 C   s4   |d u r| j S t|dr|jS | j |}||_|S )NrR   )r
   rS   rR   r9   )r   r}   r   r~   r   r   r   r   P  s   
zslots_dispatcher.__get__N)r   r   r   r   r   r   r   r   rY   O  s    rY   )r   
__future__r   rH   attrr   r   r    r   defaultdictlistrU   r   objectr   r   r<   rK   rL   rb   with_metaclassrc   r=   rZ   rY   r   r   r   r   <module>   s$   


k	)9