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/ext/__pycache__/instrumentation.cpython-310.pyc
o

���g[=�@sdZddlZddlmZddlmZddlmZddlmZddlm	Z
dd	lmZddlmZ
dd
lmZddlmZddlmZdd
lmZddlmZddlmZdZ	dd�ZegZ	Gdd�de�Ze�e_Zee_Gdd�d�ZGdd�de�Zdd�Zdd�Zdd�ZdS)a�Extensible class instrumentation.

The :mod:`sqlalchemy.ext.instrumentation` package provides for alternate
systems of class instrumentation within the ORM.  Class instrumentation
refers to how the ORM places attributes on the class which maintain
data and track changes to that data, as well as event hooks installed
on the class.

.. note::
    The extension package is provided for the benefit of integration
    with other object management packages, which already perform
    their own instrumentation.  It is not intended for general use.

For examples of how the instrumentation extension is used,
see the example :ref:`examples_instrumentation`.

�N�)�util)�
attributes)�base)�collections)�exc)�instrumentation)�_default_dict_getter)�_default_manager_getter)�_default_opt_manager_getter)�_default_state_getter)�ClassManager)�InstrumentationFactory�__sa_instrumentation_manager__cCst|td�S)z;Find user-specified instrumentation management for a class.N)�getattr�INSTRUMENTATION_MANAGER��cls�r�I/usr/local/lib/python3.10/dist-packages/sqlalchemy/ext/instrumentation.py�%find_native_user_instrumentation_hookEsrcs|eZdZdZe��Ze��Ze��ZdZ	dd�Z
dd�Zdd�Zd	d
�Z
�fdd�Zd
d�Zdd�Zdd�Zdd�Z�ZS)�ExtendedInstrumentationRegistryz�Extends :class:`.InstrumentationFactory` with additional
    bookkeeping, to accommodate multiple types of
    class managers.

    FcCs6tD]}||�}|dur|�||�}||fSqdS)N)NN)�instrumentation_finders�_extended_class_manager)�self�class_�finder�factory�managerrrr�_locate_extended_factorygs�z8ExtendedInstrumentationRegistry._locate_extended_factorycCs0|�|��|g�}|rtd|jt|�f��dS)NzRmultiple instrumentation implementations specified in %s inheritance hierarchy: %r)�!_collect_management_factories_for�
difference�	TypeError�__name__�list)rrr�existing_factoriesrrr�_check_conflictsps�����z0ExtendedInstrumentationRegistry._check_conflictscCsd||�}t|t�st||�}|tkr|jsd|_t�|��|j|<|��|j|<|�	�|j
|<|S)NT)�
isinstancer
�_ClassInstrumentationAdapter�	_extended�_install_instrumented_lookups�manager_getter�_manager_finders�state_getter�_state_finders�dict_getter�
_dict_finders)rrrrrrrr{s

z7ExtendedInstrumentationRegistry._extended_class_managercCstt�|�}t�}|D](}|�|�}|dur|�|j�q
tD]}||�}|dur*nqd}|�|�q
|�d�|S)acReturn a collection of factories in play or specified for a
        hierarchy.

        Traverses the entire inheritance graph of a cls and returns a
        collection of instrumentation factories for those classes. Factories
        are extracted from active ClassManagers, if available, otherwise
        instrumentation_finders is consulted.

        N)r�class_hierarchy�set�opt_manager_of_class�addrr�discard)rr�	hierarchy�	factories�memberrrrrrrr �s


�
zAExtendedInstrumentationRegistry._collect_management_factories_forcs6t��|�||jvr|j|=|j|=|j|=dSdS�N)�super�
unregisterr,r.r0�rr��	__class__rrr;�s
�z*ExtendedInstrumentationRegistry.unregistercCs.z|j�|t�}W||�StyYdSwr9)r,�getrr")rrrrrrr3�s���z4ExtendedInstrumentationRegistry.opt_manager_of_classcCsZz	|j�|t�}Wntyt�|d|����w||�}|dur+t�|d|����|S)Nz2Can't locate an instrumentation manager for class )r,r?r
r"�orm_exc�UnmappedClassError)rrrrrrr�manager_of_class�s
���z0ExtendedInstrumentationRegistry.manager_of_classcC�$|durtd��|j�|jt�|�S�NzNone has no persistent state.)�AttributeErrorr.r?r>r�r�instancerrr�state_of����z(ExtendedInstrumentationRegistry.state_ofcCrCrD)rEr0r?r>r	rFrrr�dict_of�rIz'ExtendedInstrumentationRegistry.dict_of)r#�
__module__�__qualname__�__doc__�weakref�WeakKeyDictionaryr,r.r0r)rr&rr r;r3rBrHrJ�
__classcell__rrr=rr[s	rc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$S)%�InstrumentationManageraWUser-defined class instrumentation extension.

    :class:`.InstrumentationManager` can be subclassed in order
    to change
    how class instrumentation proceeds. This class exists for
    the purposes of integration with other object management
    frameworks which would like to entirely modify the
    instrumentation methodology of the ORM, and is not intended
    for regular usage.  For interception of class instrumentation
    events, see :class:`.InstrumentationEvents`.

    The API for this class should be considered as semi-stable,
    and may change slightly with new releases.

    cC�dSr9rr<rrr�__init__��zInstrumentationManager.__init__cCst|d|�dS�N�_default_class_manager��setattr�rrrrrr�manage��zInstrumentationManager.managecCst|d�dSrU��delattrrYrrrr;��z!InstrumentationManager.unregistercCsdd�}|S)NcS�|jSr9)rVrrrrr?��z2InstrumentationManager.manager_getter.<locals>.getr)rrr?rrrr+�sz%InstrumentationManager.manager_gettercCrRr9r�rr�key�instrrr�instrument_attributerTz+InstrumentationManager.instrument_attributecCrRr9rrarrr�post_configure_attributerTz/InstrumentationManager.post_configure_attributecC�t|||�dSr9rWrarrr�install_descriptor	r[z)InstrumentationManager.install_descriptorcC�t||�dSr9r\�rrrbrrr�uninstall_descriptorr^z+InstrumentationManager.uninstall_descriptorcCrfr9rW)rrrb�implementationrrr�install_memberr[z%InstrumentationManager.install_membercCrhr9r\rirrr�uninstall_memberr^z'InstrumentationManager.uninstall_membercCs
t�|�Sr9)r�prepare_instrumentation)rrrb�collection_classrrr�instrument_collection_classs
z2InstrumentationManager.instrument_collection_classcCs|jSr9)�__dict__�rrrGrrr�get_instance_dictr`z(InstrumentationManager.get_instance_dictcCrRr9rrrrrr�initialize_instance_dictrTz/InstrumentationManager.initialize_instance_dictcCst|d|�dS�N�_default_staterW)rrrG�staterrr�
install_stater[z$InstrumentationManager.install_statecCst|d�dSrur\rrrrr�remove_state!r^z#InstrumentationManager.remove_statecCsdd�S)NcSs
t|d�Sru)r)rGrrr�<lambda>%s
z5InstrumentationManager.state_getter.<locals>.<lambda>rr<rrrr-$sz#InstrumentationManager.state_gettercs��fdd�S)Ncs���|�Sr9)rs)rc�rrrrrz(sz4InstrumentationManager.dict_getter.<locals>.<lambda>rr<rr{rr/'r^z"InstrumentationManager.dict_getterN)r#rKrLrMrSrZr;r+rdrergrjrlrmrprsrtrxryr-r/rrrrrQ�s&rQcs�eZdZdZdd�Zdd�Zdd�Zdd	�Zd*dd�Z�fd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd+dd�Zdd�Zd+d d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Z�ZS),r(z?Adapts a user-defined InstrumentationManager to a ClassManager.cCs2||_|j�|�|_|j�|�|_t�||�dSr9)�_adaptedr-�
_get_stater/�	_get_dictr
rS)rr�overriderrrrS.sz%_ClassInstrumentationAdapter.__init__cC�|j�|j|�dSr9)r|rZr�rrrrrZ5�z#_ClassInstrumentationAdapter.managecCr�r9)r|r;rr�rrrr;8r�z'_ClassInstrumentationAdapter.unregistercCs|j�|j�Sr9)r|r+rr�rrrr+;r^z+_ClassInstrumentationAdapter.manager_getterFcCs.t�||||�|s|j�|j||�dSdSr9)r
rdr|r)rrbrc�
propagatedrrrrd>s�z1_ClassInstrumentationAdapter.instrument_attributecs&t��|�|j�|j|||�dSr9)r:rer|r�rrbr=rrreCsz5_ClassInstrumentationAdapter.post_configure_attributecC�|j�|j||�dSr9)r|rgr)rrbrcrrrrgG�z/_ClassInstrumentationAdapter.install_descriptorcC�|j�|j|�dSr9)r|rjrr�rrrrjJr�z1_ClassInstrumentationAdapter.uninstall_descriptorcCr�r9)r|rlr)rrbrkrrrrlMr�z+_ClassInstrumentationAdapter.install_membercCr�r9)r|rmrr�rrrrmPr�z-_ClassInstrumentationAdapter.uninstall_membercCs|j�|j||�Sr9)r|rpr)rrbrorrrrpSs�z8_ClassInstrumentationAdapter.instrument_collection_classcCs.t|jdd�}|r||||�St�||||�S)N�initialize_collection)rr|r
r�)rrbrwr�delegaterrrr�Xs�z2_ClassInstrumentationAdapter.initialize_collectionNcCs|j�|j�}|�||�|Sr9)r�__new__�setup_instance)rrwrGrrr�new_instanceasz)_ClassInstrumentationAdapter.new_instancecCs|�|�rdS|�|�S)z�Install a default InstanceState if none is present.

        A private convenience method used by the __init__ decorator.
        F)�	has_stater�rFrrr�_new_state_if_nonefs

z/_ClassInstrumentationAdapter._new_state_if_nonecCs:|j�|j|�|dur|�||�}|j�|j||�|Sr9)r|rtr�_state_constructorrx)rrGrwrrrr�ps
z+_ClassInstrumentationAdapter.setup_instancecCr�r9)r|ryrrFrrr�teardown_instancezr�z._ClassInstrumentationAdapter.teardown_instancecCs(z|�|�WdStjyYdSw)NFT)r}r@�NO_STATErFrrrr�}s��z&_ClassInstrumentationAdapter.has_statecCr_r9)r}r�rrrr-�r`z)_ClassInstrumentationAdapter.state_gettercCr_r9)r~r�rrrr/�r`z(_ClassInstrumentationAdapter.dict_getter)Fr9)r#rKrLrMrSrZr;r+rdrergrjrlrmrpr�r�r�r�r�r�r-r/rPrrr=rr(+s*

	


r(cCs tttjtjtjtjd��dS)a�Replace global class/object management functions
    with ExtendedInstrumentationRegistry implementations, which
    allow multiple types of class managers to be present,
    at the cost of performance.

    This function is called only by ExtendedInstrumentationRegistry
    and unit tests specific to this behavior.

    The _reinstall_default_lookups() function can be called
    after this one to re-establish the default functions.

    ��instance_state�
instance_dictrBr3N)�_install_lookups�dict�_instrumentation_factoryrHrJrBr3rrrrr*�s
��r*cCsttttttd��dt_dS)zRestore simplified lookups.r�FN)r�r�rr	r
rr�r)rrrr�_reinstall_default_lookups�s��
r�cCsr|da|da|da|datt_t_t_tt_t_t_tt_t_t_tt_t_t_t_dS)Nr�r�rBr3)r�r�rBr3�orm_baser�orm_instrumentation�orm_util)�lookupsrrrr��s"����r�)rMrN�r�ormrrr�rrr@rr�r��orm.instrumentationr	r
rrr
rrrrrr�rQr(r*r�r�rrrr�<module>s:�La