Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/orm/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/orm/__pycache__/instrumentation.cpython-311.pyc

�

�܋f�H��&�dZddlmZddlmZddlmZddlmZddlmZddlmZej��Z	Gd	�d
e
��ZGd�de��Z
Gd
�de��Ze��ZejxZZejxZZejxZZd�Zd�Zd�Zd�ZdS)a�Defines SQLAlchemy's system of class instrumentation.

This module is usually not directly visible to user applications, but
defines a large part of the ORM's interactivity.

instrumentation.py deals with registration of end-user classes
for state tracking.   It interacts closely with state.py
and attributes.py which establish per-instance and per-class-attribute
instrumentation, respectively.

The class instrumentation system can be customized on a per-class
or global basis using the :mod:`sqlalchemy.ext.instrumentation`
module, which provides the means to build and specify
alternate instrumentation forms.

.. versionchanged: 0.8
   The instrumentation extension system was moved out of the
   ORM and into the external :mod:`sqlalchemy.ext.instrumentation`
   package.  When that package is imported, it installs
   itself within sqlalchemy.orm so that its more comprehensive
   resolution mechanics take effect.

�)�base)�collections)�exc)�
interfaces)�state�)�utilc�^�eZdZdZejZejZe	e
je����ZdZ
ejZdZd�Zd�Zd�Zed���Zed���Zed���Zed	���Ze
jd
���Zd/d�Zd/d�Zd
�Zd�Zd�Z d�Z!e
jd���Z"d�Z#d�Z$e
j%d���Z&e
j%d���Z'e
j%d���Z(d0d�Z)d�Z*d�Z+d0d�Z,d�Z-d�Z.d�Z/d�Z0d �Z1d!�Z2d"�Z3d0d#�Z4d$�Z5ed%���Z6d/d&�Z7d/d'�Z8d(�Z9d)�Z:d*�Z;d+�Z<d0d,�Z=d-�Z>e>Z?d.�Z@dS)1�ClassManagerz,Tracks state information at the class level.Nc��||_i|_d|_i|_i|_d�d�|jjD��D��|_|jD]}|�|���|jj	�
||��|jD]2}t|��}|�|j�
|j���3|���|���d|jvrt#jd|z��dSdS)Nc��g|]}|�|��S�N�)�.0�mgrs  �U/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/orm/instrumentation.py�
<listcomp>z)ClassManager.__init__.<locals>.<listcomp>As)��
�
�
��
��

����c�V�g|]&}t|t���t|����'Sr)�
isinstance�type�manager_of_class)rrs  rrz)ClassManager.__init__.<locals>.<listcomp>Cs@�������d�D�)�)�� ��&�&���r�__del__z�__del__() method on class %s will cause unreachable cycles and memory leaks, as SQLAlchemy instrumentation often creates reference cycles.  Please remove this method.)�class_�info�new_init�local_attrs�	originals�	__bases__�_bases�update�dispatch�_events�_new_classmanager_instance�__mro__r�_update�manage�_instrument_init�__dict__r	�warn)�selfr�base_�baseclsrs     r�__init__zClassManager.__init__:sJ�������	���
�������
�
��� �K�1����
�
�
����[�	�	�E��K�K�������
��8�8���F�F�F��~�	4�	4�G�"�7�+�+�C����
�%�%�c�l�3�3�3�����
�
�
����������'�'��I�@�CI�I�
�
�
�
�
�(�'rc� �t|��Sr)�id�r+s r�__hash__zClassManager.__hash__`s
���$�x�x�rc�
�||uSrr)r+�others  r�__eq__zClassManager.__eq__cs����}�rc��d|jvS)N�mapper)r)r1s r�	is_mappedzClassManager.is_mappedfs���4�=�(�(rc� �t|��Sr)�	frozensetr1s r�_all_key_setzClassManager._all_key_setjs������rc�X�td�|���D����S)Nc�4�g|]}|jj�|j��Sr)�impl�
collection�key�r�attrs  rrz6ClassManager._collection_impl_keys.<locals>.<listcomp>qs$��H�H�H�$�4�9�3G�H�T�X�H�H�Hr�r:�valuesr1s r�_collection_impl_keysz"ClassManager._collection_impl_keysns-���H�H�$�+�+�-�-�H�H�H�
�
�	
rc�X�td�|���D����S)Nc�4�g|]}|jj�|j��Sr)r>�accepts_scalar_loaderrAs  rrz5ClassManager._scalar_loader_impls.<locals>.<listcomp>ws5��
�
�
���9�2�
��	�
�
�
rrCr1s r�_scalar_loader_implsz!ClassManager._scalar_loader_implsts8���
�
� �K�K�M�M�
�
�
�
�
�	
rc�4�tj|j���r)r�UnmappedClassErrorrr1s rr7zClassManager.mapper~s���$�T�[�1�1�1rc#�K�i}|jjdd�D]s}|jd}|jD]\}|�||��||jvr�"||j|}t	|t
j��r
|jr||fV��]�tdS)areturn an iterator of all classbound attributes that are
        implement :class:`.InspectionAttr`.

        This includes :class:`.QueryableAttribute` as well as extension
        types such as :class:`.hybrid_property` and
        :class:`.AssociationProxy`.

        ����rN)rr%r)�
setdefaultrr�InspectionAttr�is_attribute)r+�exclude�found�supercls�inheritsr@�vals       r�_all_sqla_attributesz!ClassManager._all_sqla_attributes�s���������+�A�b�D�1�	#�	#�H��'��*�H��(�	
#�	
#��� � ��h�/�/�/��(�+�+�+���C�j�)�#�.���s�J�$=�>�>�#��(�#��s�(�N�N�N��	
#�	#�	#rc�T�|jjD]}||jvr|j|cS�|S)z5return an attribute on the class without tripping it.)rr%r))r+r@�defaultrTs    r�_get_class_attr_mroz ClassManager._get_class_attr_mro�sF����+�	�	�H��h�'�'�'��(��-�-�-�-�(��Nrc�(�||vo||jduS)z\Return True if the given attribute is fully initialized.

        i.e. has an impl.
        N�r>�r+r@s  r�_attr_has_implzClassManager._attr_has_impl�s���d�{�9�t�C�y�~�T�9�9rc�\�t|��}|�t�|��}|S)a�Create a new ClassManager for a subclass of this ClassManager's
        class.

        This is called automatically when attributes are instrumented so that
        the attributes can be propagated to subclasses against their own
        class-local manager, without the need for mappers etc. to have already
        pre-configured managers for the full class hierarchy.   Mappers
        can post-configure the auto-generated ClassManager when needed.

        �r�_instrumentation_factory�create_manager_for_cls)r+�cls�managers   r�_subclass_managerzClassManager._subclass_manager�s.��#�3�'�'���?�.�E�E�c�J�J�G��rc��|jj|_t|j|��|_|�d|j��dS�Nr.)rr.�
original_init�_generate_initr�install_memberr1s rr(zClassManager._instrument_init�sB��"�[�1���&�t�{�D�9�9��
����J��
�6�6�6�6�6rc�P�|jr|�d��d|_dSdSrg)r�uninstall_memberr1s r�_uninstrument_initzClassManager._uninstrument_init�s5���=�	!��!�!�*�-�-�-� �D�M�M�M�	!�	!rc�Z�|j�||j��tjSr)r"�
first_initrr�
InstanceStater1s r�_state_constructorzClassManager._state_constructor�s%���
� � ��t�{�3�3�3��"�"rc�<�t|j|j|��dS)z0Mark this instance as the manager for its class.N)�setattrr�MANAGER_ATTRr1s rr'zClassManager.manage�s!��	���T�.��5�5�5�5�5rc�:�t|j|j��dS)z)Disassociate this manager from its class.N)�delattrrrtr1s r�disposezClassManager.dispose�s��	���T�.�/�/�/�/�/rc��tSr)�_default_manager_getterr1s r�manager_getterzClassManager.manager_getter�s��&�&rc��tS)z�Return a (instance) -> InstanceState callable.

        "state getter" callables should raise either KeyError or
        AttributeError if no InstanceState could be found for the
        instance.
        )�_default_state_getterr1s r�state_getterzClassManager.state_getter�s
��%�$rc��tSr)�_default_dict_getterr1s r�dict_getterzClassManager.dict_getter�s��#�#rFc�0�|r||jvrdSn ||j|<|�||��t�|��|||<|j���D].}|�|��}|�||d���/dS�NT)r�install_descriptor�_memoized_key_collection�expire_instancer�__subclasses__re�instrument_attribute)r+r@�inst�
propagatedrcrds      rr�z!ClassManager.instrument_attribute�s����	/��d�&�&�&���'�%)�D��S�!��#�#�C��.�.�.� �0�0��6�6�6���S�	��;�-�-�/�/�	:�	:�C��,�,�S�1�1�G��(�(��d�D�9�9�9�9�	:�	:rc#�K�|j���D]9}t|��}|�&||ur"|V�|r|�d��D]}|V���:dSr�)rr�r�subclass_managers)r+�	recursivercr�ms     rr�zClassManager.subclass_managerss������;�-�-�/�/�	 �	 �C�"�3�'�'�C���3�d�?�?��	�	�	�� � �2�2�4�8�8� � ��������
	 �	 rc�^�tj�|j|||��dSr)rar"�attribute_instrumentrr]s  r�post_configure_attributez%ClassManager.post_configure_attribute
s4�� �)�>�>��K��d�3�i�	
�	
�	
�	
�	
rc�(�||vrdS|r||jvrdSn|j|=|�|��t�|��||=|j���D])}t
|��}|r|�|d���*dSr�)r�uninstall_descriptorr�r�rr�r�uninstrument_attribute)r+r@r�rcrds     rr�z#ClassManager.uninstrument_attributes����d�?�?��F��	+��d�&�&�&���'�� ��%��%�%�c�*�*�*� �0�0��6�6�6���I��;�-�-�/�/�	:�	:�C�&�s�+�+�G��
:��.�.�s�D�9�9�9��	:�	:rc���|���dx|_|_|j���t|��D] }||jvr|�|���!dS)z<remove all instrumentation established by this ClassManager.N)rmr7r"r�clear�listrr�r]s  r�
unregisterzClassManager.unregister"sx��	
���!�!�!�&*�*���d�m��	��������:�:�	1�	1�C��d�&�&�&��+�+�C�0�0�0��	1�	1rc�v�||j|jfvrtd|z���t|j||��dS�NzW%r: requested attribute name conflicts with instrumentation attribute of the same name.)�
STATE_ATTRrt�KeyErrorrsr)r+r@r�s   rr�zClassManager.install_descriptor.sS���4�?�D�$5�6�6�6��>�@C�D���
�	���S�$�'�'�'�'�'rc�0�t|j|��dSr)rvrr]s  rr�z!ClassManager.uninstall_descriptor6s�����S�!�!�!�!�!rc���||j|jfvrtd|z���|j�|t|j|d����t|j||��dSr�)r�rtr�rrO�getattrrrs)r+r@�implementations   rrjzClassManager.install_member9sy���4�?�D�$5�6�6�6��>�@C�D���
�	
��!�!�#�w�t�{�C��'F�'F�G�G�G����S�.�1�1�1�1�1rc�p�|j�|d��}|�t|j||��dSdSr)r�poprsr)r+r@�originals   rrlzClassManager.uninstall_memberBsA���>�%�%�c�4�0�0�����D�K��h�/�/�/�/�/� �rc�*�tj|��Sr)r�prepare_instrumentation)r+r@�collection_classs   r�instrument_collection_classz(ClassManager.instrument_collection_classGs���2�3C�D�D�Drc�p�|��}tj|�|��||��}||fSr)r�CollectionAdapter�get_impl)r+r@r�factory�	user_data�adapters      r�initialize_collectionz"ClassManager.initialize_collectionJs?���G�I�I�	��/��M�M�#����y�
�
���	�!�!rc� �|r||vS||jvSr)r)r+r@�searchs   r�is_instrumentedzClassManager.is_instrumentedQs"���	+��$�;���$�*�*�*rc��||jSrr\r]s  rr�zClassManager.get_implWs���C�y�~�rc�D�t|�����Sr)�iterrDr1s r�
attributeszClassManager.attributesZs���D�K�K�M�M�"�"�"rc��|j�|j��}|�|�||��}|�||��|Sr)r�__new__rq�
_state_setter)r+r�instances   r�new_instancezClassManager.new_instance`sN���;�&�&�t�{�3�3���=��+�+�H�d�;�;�E����8�U�+�+�+��rc�b�|�|�||��}|�||��dSr)rqr��r+r�rs   r�setup_instancezClassManager.setup_instancegs8���=��+�+�H�d�;�;�E����8�U�+�+�+�+�+rc�0�t||j��dSr)rvr��r+r�s  r�teardown_instancezClassManager.teardown_instancels����$�/�*�*�*�*�*rc�"�t||��Sr)�_SerializeManager)r+r�
state_dicts   r�
_serializezClassManager._serializeos�� ��
�3�3�3rc��t||j��rdS|j|jur4|jr-|�|j���|��S|�||��}|�||��|S)z�Install a default InstanceState if none is present.

        A private convenience method used by the __init__ decorator.

        F)	�hasattrr�r�	__class__r8re�_new_state_if_nonerqr�r�s   rr�zClassManager._new_state_if_noners����8�T�_�-�-�	��5�
�[�� 2�
2�
2�t�~�
2��)�)��"��� � ��*�*�
+��+�+�H�d�;�;�E����x��/�/�/��Lrc�,�t||j��Sr)r�r�r�s  r�	has_statezClassManager.has_state�s���x���1�1�1rc�V�|�|���||���S)�TODO)�
optimistic)r��	hasparent)r+rr@r�s    r�
has_parentzClassManager.has_parent�s'���}�}�S�!�!�+�+�E�j�+�I�I�Irc��dS)z=All ClassManagers are non-zero regardless of attribute state.Trr1s r�__bool__zClassManager.__bool__�s���trc�J�d|jj|jt|��fzS)Nz<%s of %r at %x>)r��__name__rr0r1s r�__repr__zClassManager.__repr__�s*��!��N�#��K��t�H�H�%
�
�	
rr)F)Ar��
__module__�__qualname__�__doc__r�DEFAULT_MANAGER_ATTRrt�DEFAULT_STATE_ATTRr��staticmethodr	�
attrsetterr��deferred_scalar_loader�objectr.rhr�r2r5�propertyr8r�r;rErI�memoized_propertyr7rWrZr^rer(rmrqr'rw�hybridmethodrzr}r�r�r�r�r�r�r�r�rjrlr�r�r�r�r�r�r�r�r�r�r�r�r��__nonzero__r�rrrrr,s�������6�6��,�L��(�J� �L�����!<�!<�=�=�M�!���O�M��G�$�$�$�L�������)�)��X�)��������
�
���
�
�
�
���
�
��2�2���2�#�#�#�#�B����:�:�:���� 7�7�7�!�!�!�

��#�#���#�6�6�6�
0�0�0�

��'�'���'�
��%�%���%�
��$�$���$�:�:�:�:� � � �
�
�
�
:�:�:�:� 
1�
1�
1�(�(�(�"�"�"�2�2�2�0�0�0�
E�E�E�"�"�"�+�+�+�+�����#�#��X�#�
����,�,�,�,�
+�+�+�4�4�4����,2�2�2�J�J�J�J�����K�
�
�
�
�
rrc��eZdZdZd�Zd�ZdS)r�z�Provide serialization of a :class:`.ClassManager`.

    The :class:`.InstanceState` uses ``__init__()`` on serialize
    and ``__call__()`` on deserialize.

    c�b�|j|_|j}|j�||��dSr)rrdr"�pickle)r+r�drds    rr.z_SerializeManager.__init__�s1���l����-�������q�)�)�)�)�)rc�8�t|j��x|_}|�tj|d|jz���|jr%|jjs|j���|�|�	||��|j
�||��dS)NzxCannot deserialize object of type %r - no mapper() has been configured for this class within the current Python process!)rrrdr�UnmappedInstanceErrorr8r7�
configured�_configure_allr�r"�unpickle)r+rr�r�rds     r�__call__z_SerializeManager.__call__�s���"2�4�;�"?�"?�?��
���?��+��"�%)�K�0���
��
�	,�w�~�'@�	,��N�)�)�+�+�+�
���"�"�4��/�/�/���!�!�%��4�4�4�4�4rN)r�r�r�r�r.r�rrrr�r��s<��������*�*�*�
5�5�5�5�5rr�c�*�eZdZdZd�Zd�Zd�Zd�ZdS)�InstrumentationFactoryz'Factory for new ClassManager instances.c��|�J�t|���J�|�|��\}}|�t}||��}|�||��||_|j�|��|Sr)r�_locate_extended_factoryr�_check_conflictsr�r"�class_instrument)r+rrdr�s    rrbz-InstrumentationFactory.create_manager_for_cls�s����!�!�!���'�'�/�/�/� �8�8��@�@�����?�"�G��g�f�o�o�G����f�g�.�.�.�!����
�&�&�v�.�.�.��rc��dS)z2Overridden by a subclass to do an extended lookup.)NNr)r+rs  rr�z/InstrumentationFactory._locate_extended_factory�s���zrc��dS)z;Overridden by a subclass to test for conflicting factories.Nr)r+rr�s   rr�z'InstrumentationFactory._check_conflicts�s���rc��t|��}|���|���|j�|��t
j|jvrt|t
j��dSdSr)	rr�rwr"�class_uninstrumentrrtr)rv)r+rrds   rr�z!InstrumentationFactory.unregister�sx��"�6�*�*���������������
�(�(��0�0�0��$���7�7��F�L�5�6�6�6�6�6�8�7rN)r�r�r�r�rbr�r�r�rrrr�r��sV������1�1����&������7�7�7�7�7rr�c�\�t|��}|�t�|��}|S)z_Register class instrumentation.

    Returns the existing or newly created class manager.

    r`)rrds  r�register_classr��s.���v�&�&�G���*�A�A�&�I�I���Nrc�:�t�|��dS)z!Unregister class instrumentation.N)rar�)rs r�unregister_classr�s���'�'��/�/�/�/�/rc�T�t|j���|d���S)z�Return True if the given attribute on the given instance is
    instrumented by the attributes package.

    This function may be used regardless of instrumentation
    applied directly to the class, i.e. no descriptors are required.

    T)r�)rr�r�)r�r@s  rr�r�s2���H�.�/�/�?�?��D�@���rc���|j}|sJ�d}tj|d���}||z}tjr#t	|d|��}t	|dd��}n"t	|dd��}t	|dd��}t�����}	t||	��|	d	}
|j|
_||
_	|r||
_
tjs	|r||
_|
S)
z>Build an __init__ decorator that triggers ClassManager events.z�def __init__(%(apply_pos)s):
    new_state = class_manager._new_state_if_none(%(self_arg)s)
    if new_state:
        return new_state._initialize_instance(%(apply_kw)s)
    else:
        return original__init__(%(apply_kw)s)
F)�grouped�im_func�
func_defaultsN�__defaults__�__kwdefaults__r.)r.r	�format_argspec_init�py2kr��locals�copy�execr��_sa_original_initr�r�)r�
class_manager�original__init__�	func_body�	func_vars�	func_text�funcr��func_kw_defaults�envr.s           rriris����������I��(�)9�5�I�I�I�I��I�%�I��y�M��'��4D�E�E����o�t�<�<�
�
�� 0�.�$�G�G�
�"�#3�5E�t�L�L��
�(�(�-�-�/�/�C���C�����:��H�'�/�H��!1�H���.� -����9�3�)�3�"2����OrN)r��rrrrrr	�!group_expirable_memoized_propertyr��dictrr�r�r�ra�instance_stater|�
instance_dictrrryr�r�r�rirrr�<module>rs�����2������������������������������������B�4�A�C�C��n
�n
�n
�n
�n
�4�n
�n
�n
�b5�5�5�5�5��5�5�5�D$7�$7�$7�$7�$7�V�$7�$7�$7�R2�1�3�3��
*.�)<�<��&�'+�'9�9�
�$�-1�-B�B��*�
�
�
�0�0�0�
�
�
�+�+�+�+�+r

Hacked By AnonymousFox1.0, Coded By AnonymousFox