HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/event/__pycache__/attr.cpython-310.pyc
o

���gQ�@s�dZddlmZddlZddlmZddlZddlmZddl	Z	ddl	m
Z
ddl	mZddl	mZdd	l	m
Z
dd
l	mZddl	mZddl	mZdd
l	mZddl	mZddl	mZddl	mZddl	mZddl	mZddl	mZddl	mZddl	mZddl	mZddlZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#dd l$m%Z%dd!l&m'Z'ed"e
d#�Z(e	j)r�dd$l*m+Z+dd%l*m,Z,dd&l*m-Z-Gd'd(�d(e#j.ee�Z/Gd)d*�d*ee(�Z0ee
e(e0e(fZ1Gd+d,�d,e/e�Z2Gd-d.�d.e/eee!�Z3Gd/d0�d0e3e�Z4Gd1d2�d2e'�Z5Gd3d4�d4e3e�Z6Gd5d6�d6e6e�Z7Gd7d8�d8e6e�Z8dS)9a�Attribute implementation for _Dispatch classes.

The various listener targets for a particular event class are represented
as attributes, which refer to collections of listeners to be fired off.
These collections can exist at the class level as well as at the instance
level.  An event is fired off using code like this::

    some_object.dispatch.first_connect(arg1, arg2)

Above, ``some_object.dispatch`` would be an instance of ``_Dispatch`` and
``first_connect`` is typically an instance of ``_ListenerCollection``
if event listeners are present, or ``_EmptyListener`` if none are present.

The attribute mechanics here spend effort trying to ensure listener functions
are available with a minimum of function call overhead, that unnecessary
objects aren't created (i.e. many empty per-instance listener collections),
as well as that everything is garbage collectable when owning references are
lost.  Other features such as "propagation" of listener functions across
many ``_Dispatch`` instances, "joining" of multiple ``_Dispatch`` instances,
as well as support for subclass propagation (e.g. events assigned to
``Pool`` vs. ``QueuePool``) are all implemented here.

�)�annotationsN)�chain)�
TracebackType)�Any)�cast)�
Collection)�Deque)�	FrozenSet)�Generic)�Iterator)�MutableMapping)�MutableSequence)�NoReturn)�Optional)�Sequence)�Set)�Tuple)�Type)�TypeVar)�Union�)�legacy)�registry)�_ET)�	_EventKey)�_ListenerFnType�)�exc)�util)�AsyncAdaptedLock)�Protocol�_T)�bound)�	_Dispatch)�_DispatchCommon)�_HasEventsDispatchc@s$eZdZUdZded<ddd�ZdS)	�
RefCollection)�ref�weakref.ref[RefCollection[_ET]]r'�returncCst�|tj�S�N)�weakrefr'r�_collection_gced��self�r/�@/usr/local/lib/python3.10/dist-packages/sqlalchemy/event/attr.py�_memoized_attr_refP�z RefCollection._memoized_attr_refN)r)r()�__name__�
__module__�__qualname__�	__slots__�__annotations__r1r/r/r/r0r&Ks
r&c@s\eZdZddd�Zddd�Zddd�Zdd
d�Zddd�Zddd�Zd dd�Z	d!dd�Z
dS)"�_empty_collection�elementr!r)�NonecC�dSr*r/�r.r9r/r/r0�appendU�z_empty_collection.appendcCr;r*r/r<r/r/r0�
appendleftXr>z_empty_collection.appendleft�other�Sequence[_T]cCr;r*r/)r.r@r/r/r0�extend[r>z_empty_collection.extendcCr;r*r/r<r/r/r0�remove^r>z_empty_collection.remover�boolcC�dS�NFr/r<r/r/r0�__contains__ar>z_empty_collection.__contains__�Iterator[_T]cCstg�Sr*)�iterr-r/r/r0�__iter__d�z_empty_collection.__iter__cCr;r*r/r-r/r/r0�cleargr>z_empty_collection.clear�intcCrE�Nrr/r-r/r/r0�__len__jr>z_empty_collection.__len__N)r9r!r)r:)r@rAr)r:)r9rr)rD)r)rH�r)r:�r)rM)r3r4r5r=r?rBrCrGrJrLrOr/r/r/r0r8Ts






r8c@s�eZdZUdZdZded<ded<ded<ded	<d
ed<ded
<d3dd�Zd4dd�Zd5dd�Zd6dd�Z	d7d!d"�Z
d7d#d$�Zd8d'd(�Zd9d)d*�Z
d:d+d,�Zd;d0d1�Zd2S)<�_ClsLevelDispatchz2Class-level events on :class:`._Dispatch` classes.)�clsname�name�	arg_names�has_kw�legacy_signatures�	_clslevel�__weakref__�strrSrTz
Sequence[str]rUrDrVz,MutableSequence[legacy._LegacySignatureType]rWzCMutableMapping[Type[_ET], _ListenerFnSequenceType[_ListenerFnType]]rX�parent_dispatch_cls�Type[_HasEventsDispatch[_ET]]�fnrcCsv|j|_|j|_t�|�}|jdd�|_t|j�|_	t
ttt
|dg�dd�d���|_t�|||�|_t��|_dS)Nr�_legacy_signaturescSs|dSrNr/)�sr/r/r0�<lambda>�sz,_ClsLevelDispatch.__init__.<locals>.<lambda>)�key)r3rTrSr�inspect_getfullargspec�argsrUrD�varkwrV�list�reversed�sorted�getattrrWr�_augment_fn_docs�__doc__r+�WeakKeyDictionaryrX)r.r[r]�argspecr/r/r0�__init__�s
���z_ClsLevelDispatch.__init__�namedr)cCsN|r|�|�}|jr%z	tj|dd�}Wn
tyY|Swt�|||�}|S)NT)�no_self)�_wrap_fn_for_kwrWr�get_callable_argspec�	TypeErrorr�_wrap_fn_for_legacy)r.r]rnrlr/r/r0�_adjust_fn_spec�s
�z!_ClsLevelDispatch._adjust_fn_speccsd��fdd�}|S)Nrcr�kwr)cs(tt�j|��}|�|��di|��S)Nr/)�dict�ziprU�update)rcru�argdict�r]r.r/r0�wrap_kw�s
z2_ClsLevelDispatch._wrap_fn_for_kw.<locals>.wrap_kw)rcrrurr)rr/)r.r]r{r/rzr0rp�sz!_ClsLevelDispatch._wrap_fn_for_kw�	event_key�_EventKey[_ET]�	is_appendr:cCs�|j}t|t�sJd��t|dd�st�d|�d���t�|�D]0}||ur1||jvr1|�	|�q ||jvr;|�	|�|rG|j|�
|j�q |j|�|j�q t
�||�dS)Nz*Class-level Event targets must be classes.�_sa_propagate_class_eventsTz&Can't assign an event directly to the z class)�dispatch_target�
isinstance�typerhr�InvalidRequestErrorr�walk_subclassesrX�update_subclassr=�
_listen_fnr?r�_stored_in_collection)r.r|r~�target�clsr/r/r0�_do_insert_or_append�s&��
�

z&_ClsLevelDispatch._do_insert_or_append�	propagatecC�|j|dd�dS)NF�r~�r��r.r|r�r/r/r0�insert��z_ClsLevelDispatch.insertcCr�)NTr�r�r�r/r/r0r=�r�z_ClsLevelDispatch.appendr��	Type[_ET]cs|||jvrt|dd�rt��|j|<nt�|j|<|j|�|jdd�D]}||jvr;���fdd�|j|D��q%dS)NrTrcsg|]}|�vr|�qSr/r/)�.0r]��clslevelr/r0�
<listcomp>�sz5_ClsLevelDispatch.update_subclass.<locals>.<listcomp>)rXrh�collections�dequer8�__mro__rB)r.r�r�r/r�r0r��s


���z!_ClsLevelDispatch.update_subclasscCsB|j}t�|�D]}||jvr|j|�|j�qt�||�dSr*)r�rr�rXrCr�r�_removed_from_collection)r.r|r�r�r/r/r0rC�s
�z_ClsLevelDispatch.removecCs8t�}|j��D]}|�|�|��qt�||�dS)zClear all class level listenersN)�setrX�valuesrxrLr�_clear)r.�to_clear�
dispatcherr/r/r0rL�s


z_ClsLevelDispatch.clear�obj�_Dispatch[_ET]�_ClsLevelDispatch[_ET]cC�|S�z�Return an event collection which can be modified.

        For _ClsLevelDispatch at the class level of
        a dispatcher, this returns self.

        r/�r.r�r/r/r0�
for_modify�sz_ClsLevelDispatch.for_modifyN)r[r\r]r�r]rrnrDr)r)r]rr)r)r|r}r~rDr)r:�r|r}r�rDr)r:)r�r�r)r:�r|r}r)r:rP)r�r�r)r�)r3r4r5rjr6r7rmrtrpr�r�r=r�rCrLr�r/r/r/r0rRqs&










	rRc@s�eZdZUdZded<d1d	d
�Zd2d
d�Zd3dd�Zd4dd�Zd5dd�Z	d6dd�Z
d6dd�Zd6dd�Zd6d d!�Z
d7d%d&�Zd7d'd(�Zd8d)d*�Zd9d.d/�Zd0S):�_InstanceLevelDispatchr/r��parentr]rrnrDr)cC�|j�||�Sr*)r�rt�r.r]rnr/r/r0rt�z&_InstanceLevelDispatch._adjust_fn_spec�itemrcC�t��r*��NotImplementedError�r.r�r/r/r0rG�z#_InstanceLevelDispatch.__contains__rMcCr�r*r�r-r/r/r0rO	r�z_InstanceLevelDispatch.__len__�Iterator[_ListenerFnType]cCr�r*r�r-r/r/r0rJr�z_InstanceLevelDispatch.__iter__cCr�r*r�r-r/r/r0�__bool__r�z_InstanceLevelDispatch.__bool__rcrur:cOr�r*r��r.rcrur/r/r0�	exec_oncer�z _InstanceLevelDispatch.exec_oncecOr�r*r�r�r/r/r0�exec_once_unless_exceptionr�z1_InstanceLevelDispatch.exec_once_unless_exceptioncOr�r*r�r�r/r/r0�_exec_w_sync_on_first_runr�z0_InstanceLevelDispatch._exec_w_sync_on_first_runcOr�r*r�r�r/r/r0�__call__r�z_InstanceLevelDispatch.__call__r|r}r�cCr�r*r�r�r/r/r0r�r�z_InstanceLevelDispatch.insertcCr�r*r�r�r/r/r0r=!r�z_InstanceLevelDispatch.appendcCr�r*r��r.r|r/r/r0rC$r�z_InstanceLevelDispatch.remover��_DispatchCommon[_ET]�_InstanceLevelDispatch[_ET]cCr�r�r/r�r/r/r0r�'�	z!_InstanceLevelDispatch.for_modifyNr��r�rr)rDrQ�r)r��r)rD�rcrrurr)r:r�r�)r�r�r)r�)r3r4r5r6r7rtrGrOrJr�r�r�r�r�r�r=rCr�r/r/r/r0r��s 












r�c@s�eZdZUdZdZe�Zded<dZded<ded	<d
ed<ded
<d:dd�Z	d;dd�Z
d<dd�Zd<dd�Zd<d d!�Z
d<d"d#�Zd<d$d%�Zd<d&d'�Zd<d(d)�Zd=d+d,�Zd>d/d0�Zd?d2d3�Zd@d5d6�ZdAd7d8�Zd9S)B�_EmptyListenerz�Serves as a proxy interface to the events
    served by a _ClsLevelDispatch, when there are no
    instance-level events present.

    Is replaced by _ListenerCollection when instance-level
    events are added.

    )r��parent_listenersrTzFrozenSet[_ListenerFnType]r�r/z	Tuple[()]�	listenersr�r�z(_ListenerFnSequenceType[_ListenerFnType]r�rZrT�
target_clsr�cCs2||jvr
|�|�||_|j||_|j|_dSr*)rXr�r�r�rT�r.r�r�r/r/r0rmEs


z_EmptyListener.__init__r�r�r)�_ListenerCollection[_ET]cCsbtd|�}|jdusJ�t|j|j�}t||j�|ur$t||j|�|Stt||j�t�s/J�|S)z�Return an event collection which can be modified.

        For _EmptyListener at the instance level of
        a dispatcher, this generates a new
        _ListenerCollection, applies it to the instance,
        and returns it.

        r�N)	r�
_instance_cls�_ListenerCollectionr�rhrT�setattrr��_JoinedListener)r.r��resultr/r/r0r�Ls
�z_EmptyListener.for_modifyrcrrurcOstd��)Nzneed to call for_modify()r�r�r/r/r0�
_needs_modifyarKz_EmptyListener._needs_modifycO�|j|i|��dSr*�r�r�r/r/r0r�d�z_EmptyListener.exec_oncecOr�r*r�r�r/r/r0r�gr�z)_EmptyListener.exec_once_unless_exceptioncOr�r*r�r�r/r/r0r�jr�z_EmptyListener.insertcOr�r*r�r�r/r/r0r=mr�z_EmptyListener.appendcOr�r*r�r�r/r/r0rCpr�z_EmptyListener.removecOr�r*r�r�r/r/r0rLsr�z_EmptyListener.clearr:cOs|jD]	}||i|��qdS�zExecute this event.N�r��r.rcrur]r/r/r0r�vs
�z_EmptyListener.__call__r�rDcCs
||jvSr*r�r�r/r/r0rG|�
z_EmptyListener.__contains__rMcC�
t|j�Sr*)�lenr�r-r/r/r0rOr�z_EmptyListener.__len__r�cCr�r*)rIr�r-r/r/r0rJ�r�z_EmptyListener.__iter__cCr�r*)rDr�r-r/r/r0r��r�z_EmptyListener.__bool__N�r�r�r�r��r�r�r)r�)rcrrurr)rr�r�rQr�r�)r3r4r5rjr6�	frozensetr�r7r�rmr�r�r�r�r�r=rCrLr�rGrOrJr�r/r/r/r0r�3s,
	












r�c@s eZdZddd�Zddd
�ZdS)�_MutexProtocolr)rDcCr;r*r/r-r/r/r0�	__enter__�sz_MutexProtocol.__enter__�exc_type�Optional[Type[BaseException]]�exc_val�Optional[BaseException]�exc_tb�Optional[TracebackType]�Optional[bool]cCr;r*r/)r.r�r�r�r/r/r0�__exit__�sz_MutexProtocol.__exit__Nr�)r�r�r�r�r�r�r)r�)r3r4r5r�r�r/r/r/r0r��s
r�cs�eZdZUdZded<ded<ded<ded<ded	<d,�fd
d�Zd-dd�Zd.dd�Zd/dd�Zd0dd�Z	d0dd�Z
d0dd�Zd0dd �Zd1d"d#�Z
d2d%d&�Zd3d(d)�Zd4d*d+�Z�ZS)5�_CompoundListener)�_exec_once_mutex�
_exec_once�_exec_w_sync_once�_is_asyncior�r��Collection[_ListenerFnType]r�r�rDr�r��argrrucst�j|i|��d|_dSrF)�superrmr�)r.r�ru��	__class__r/r0rm�s
z_CompoundListener.__init__r)r:cCs
d|_dS)NT)r�r-r/r/r0�_set_asyncio�r�z_CompoundListener._set_asynciocCs|jrt�St��Sr*)r�r�	threading�Lockr-r/r/r0�_memoized_attr__exec_once_mutex�sz1_CompoundListener._memoized_attr__exec_once_mutex�retry_on_exceptionrcc	Os�|j�8|js+zz||i|��d}Wnd}�W|r|s"d|_n|r'|s*d|_wWd�dSWd�dS1s>wYdS)NFT)r�r�)r.r�rcru�	exceptionr/r/r0�_exec_once_impl�s$������"z!_CompoundListener._exec_once_implcO�&|js|jdg|�Ri|��dSdS)z]Execute this event, but only if it has not been
        executed already for this collection.FN�r�r�r�r/r/r0r��s�z_CompoundListener.exec_oncecOr�)atExecute this event, but only if it has not been
        executed already for this collection, or was called
        by a previous exec_once_unless_exception call and
        raised an exception.

        If exec_once was already called, then this method will never run
        the callable regardless of whether it raised or not.

        .. versionadded:: 1.3.8

        TNr�r�r/r/r0r��s�z,_CompoundListener.exec_once_unless_exceptioncOsf|js*|j�z	||i|��Wn�d|_Wd�dS1s#wYdS||i|��dS)anExecute this event, and use a mutex if it has not been
        executed already for this collection, or was called
        by a previous _exec_w_sync_on_first_run call and
        raised an exception.

        If _exec_w_sync_on_first_run was already called and didn't raise an
        exception, then a mutex is not used.

        .. versionadded:: 1.4.11

        TN)r�r�r�r/r/r0r��s"�z+_CompoundListener._exec_w_sync_on_first_runcOs8|jD]	}||i|��q|jD]	}||i|��qdSr��r�r�r�r/r/r0r��s


�z_CompoundListener.__call__r�cCs||jvp	||jvSr*r�r�r/r/r0rG�r�z_CompoundListener.__contains__rMcCst|j�t|j�Sr*)r�r�r�r-r/r/r0rO�r�z_CompoundListener.__len__r�cC�t|j|j�Sr*)rr�r�r-r/r/r0rJ�r2z_CompoundListener.__iter__cCst|jp|j�Sr*)rDr�r�r-r/r/r0r���z_CompoundListener.__bool__)r�rrurrP)r)r�)r�rDrcrrurr)r:r�r�rQr�r�)r3r4r5r6r7rmr�r�r�r�r�r�r�rGrOrJr��
__classcell__r/r/r�r0r��s&










r�cs�eZdZUdZdZded<ded<ded<d	ed
<ded<d(�fdd�Zd)dd�Z	d*d+dd�Zd,d d!�Z	d,d"d#�Z
d-d$d%�Zd.d&d'�Z�Z
S)/r�z�Instance-level attributes on instances of :class:`._Dispatch`.

    Represents a collection of listeners.

    As of 0.7.9, _ListenerCollection is only first
    created via the _EmptyListener.for_modify() method.

    )r�r�rTr�r�rYr�r�r�r�rZrTzDeque[_ListenerFnType]r�zSet[_ListenerFnType]r�r�r�csZt���||jvr|�|�d|_d|_|j||_||_|j|_t	�
�|_t�|_
dSrF)r�rmrXr�r�r�r�r�rTr�r�r�r�r�r�r�r/r0rms



z_ListenerCollection.__init__r�r�r)r�cCr�)z�Return an event collection which can be modified.

        For _ListenerCollection at the instance level of
        a dispatcher, this returns self.

        r/r�r/r/r0r�%r�z_ListenerCollection.for_modifyTr@�only_propagaterDr:csj�j}t|���j�|j����fdd�|jD�}|�|�|jr&���|j�|�}t�	�||�dS)zIPopulate from the listeners in another :class:`_Dispatch`
        object.cs&g|]}|�vr
�r|�jvr|�qSr/)r�)r��l��existing_listener_setr�r.r/r0r�8s�
�z/_ListenerCollection._update.<locals>.<listcomp>N)
r�r�r�rxrBr�r��unionr�_stored_in_collection_multi)r.r@r��existing_listeners�other_listeners�to_associater/r�r0�_update0s�
z_ListenerCollection._updater|r}cC�,|�||j�r|r|j�|j�dSdSdSr*)�prepend_to_listr�r��addr�r�r/r/r0r�H�
�z_ListenerCollection.insertcCrr*)�append_to_listr�r�r	r�r�r/r/r0r=Mr
z_ListenerCollection.appendcCs,|j�|j�|j�|j�t�||�dSr*)r�rCr�r��discardrr�r�r/r/r0rCRsz_ListenerCollection.removecCs&t�||j�|j��|j��dSr*)rr�r�r�rLr-r/r/r0rLWs
z_ListenerCollection.clearr�r�)T)r@r�r�rDr)r:r�r�rP)r3r4r5rjr6r7rmr�rr�r=rCrLr�r/r/r�r0r�s 
		
�


r�c@s�eZdZUdZded<ded<ded<ded	<d'dd�Zejs&ed(dd��Z	d)dd�Z
d*dd�Zd+dd�Zd+d d!�Z
d,d"d#�Zd-d$d%�Zd&S).r�)�parent_dispatchrT�localr�r�r
rZrTr�rr�r��_EmptyListener[_ET]cCs$d|_||_||_||_|j|_dSrF)r�r
rTrr�)r.r
rTrr/r/r0rmes
z_JoinedListener.__init__r)cCr�r*)rhr
rTr-r/r/r0r�xsz_JoinedListener.listenersr]rrnrDcCr�r*)rrtr�r/r/r0rt|r�z_JoinedListener._adjust_fn_specr��_JoinedListener[_ET]cCs|j�|�|_|_|Sr*)rr�r�r�r/r/r0r��sz_JoinedListener.for_modifyr|r}r�r:cC�|j�||�dSr*)rr�r�r/r/r0r��r�z_JoinedListener.insertcCrr*)rr=r�r/r/r0r=�r�z_JoinedListener.appendcCs|j�|�dSr*)rrCr�r/r/r0rC�r�z_JoinedListener.removecCr�r*r�r-r/r/r0rL�r�z_JoinedListener.clearN)r
r�rTrZrr)r)r�r�)r�r�r)rr�r�rP)r3r4r5r6r7rm�typing�
TYPE_CHECKING�propertyr�rtr�r�r=rCrLr/r/r/r0r�]s 






r�)9rj�
__future__rr��	itertoolsrr��typesrrrrrrr	r
rrr
rrrrrrrrr+�rrrrrrr�util.concurrencyr�util.typingr r!r�baser#r$r%�
MemoizedSlotsr&r8�_ListenerFnSequenceTyperRr�r�r�r�r�r�r/r/r/r0�<module>sd	7Vl]