Hacked By AnonymousFox

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

�

�܋f�	���dZddlZddlmZddlmZddlmZddlmZddlm	Z	dd	lm
Z
dd
lmZddlmZddlm
Z
dd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm!Z!d!d"lm"Z"d!d#lm#Z#d!d$lm$Z$e#j%Gd%�d&ej&ej'ej(����Z)Gd'�d(e)��Z*d)�Z+e$j,d*��Z-e$j,d+��Z.e$j,d,��Z/e$j,d-��Z0e$j,d.��Z1Gd/�d0e2��Z3Gd1�d2e2��Z4Gd3�d4e4��Z5Gd5�d6e5��Z6Gd7�d8e4��Z7d9�Z8e$j,d:��Z9e:e;e��e;e��e;e��g��Z<e$j=d;gd<���Z>Gd=�d;e>��Z>e>ddd��Z?efd>�Z@efd?�ZAdNdA�ZBdB�ZC					dOdC�ZD	dPdD�ZEdE�ZFdF�ZGdG�ZHdH�ZIdQdI�ZJdJ�ZKdK�ZLdL�ZMdM�ZNdS)Rz�Defines instrumentation for class attributes and their interaction
with instances.

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


�N�)�collections)�exc)�
interfaces)�
ATTR_EMPTY)�ATTR_WAS_SET)�CALLABLES_OK)�INIT_OK)�
instance_dict��instance_state)�instance_str)�LOAD_AGAINST_COMMITTED)�manager_of_class)�	NEVER_SET)�NO_AUTOFLUSH)�	NO_CHANGE)�NO_RAISE)�NO_VALUE)�NON_PERSISTENT_OK)�PASSIVE_CLASS_MISMATCH)�PASSIVE_NO_FETCH)�PASSIVE_NO_FETCH_RELATED)�PASSIVE_NO_INITIALIZE)�PASSIVE_NO_RESULT)�PASSIVE_OFF)�PASSIVE_ONLY_PERSISTENT)�PASSIVE_RETURN_NEVER_SET)�RELATED_OBJECT_OK)�SQL_OK)�	state_str�)�event)�
inspection)�utilc�&�eZdZdZdZ				dd�Zejd���Ze	d���Z
efd�Zd�Z
ejd	���Zejd
���Ze	d���Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zejd���Z	dS)�QueryableAttributea�Base class for :term:`descriptor` objects that intercept
    attribute events on behalf of a :class:`.MapperProperty`
    object.  The actual :class:`.MapperProperty` is accessible
    via the :attr:`.QueryableAttribute.property`
    attribute.


    .. seealso::

        :class:`.InstrumentedAttribute`

        :class:`.MapperProperty`

        :attr:`_orm.Mapper.all_orm_descriptors`

        :attr:`_orm.Mapper.attrs`
    TNc�"�||_||_||_||_||_||_t
|��}|rQ|jD]K}||vrC|j�	||j��||jj
rd|j_
�JdSdS�NT)�class_�key�impl�
comparator�
_parententity�_of_typer�_bases�dispatch�_update�_active_history)	�selfr*r+r,r-�parententity�of_type�manager�bases	         �P/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/orm/attributes.py�__init__zQueryableAttribute.__init__Os�����������	�$���)�����
�"�6�*�*���	=� ��
=�
=���$�;�;��M�)�)�$�s�)�*<�=�=�=��C�y�)�9�=�8<��
�5��	=�	=�
=�
=�c��|jjS�N)r,�supports_population�r4s r9�_supports_populationz'QueryableAttribute._supports_populationjs
���y�,�,r;c��|jjSr=)r,�uses_objectsr?s r9�_impl_uses_objectsz%QueryableAttribute._impl_uses_objectsns
���y�%�%r;c�n�|j�t|��t|��|��Sr=)r,�get_historyr
r)r4�instance�passives   r9rEzQueryableAttribute.get_historyrs3���y�$�$��8�$�$�m�H�&=�&=�w�
�
�	
r;c��|Sr=�r?s r9�__selectable__z!QueryableAttribute.__selectable__ws���r;c��|jjS)a�Return the 'info' dictionary for the underlying SQL element.

        The behavior here is as follows:

        * If the attribute is a column-mapped property, i.e.
          :class:`.ColumnProperty`, which is mapped directly
          to a schema-level :class:`_schema.Column` object, this attribute
          will return the :attr:`.SchemaItem.info` dictionary associated
          with the core-level :class:`_schema.Column` object.

        * If the attribute is a :class:`.ColumnProperty` but is mapped to
          any other kind of SQL expression other than a
          :class:`_schema.Column`,
          the attribute will refer to the :attr:`.MapperProperty.info`
          dictionary associated directly with the :class:`.ColumnProperty`,
          assuming the SQL expression itself does not have its own ``.info``
          attribute (which should be the case, unless a user-defined SQL
          construct has defined one).

        * If the attribute refers to any other kind of
          :class:`.MapperProperty`, including :class:`.RelationshipProperty`,
          the attribute will refer to the :attr:`.MapperProperty.info`
          dictionary associated with that :class:`.MapperProperty`.

        * To access the :attr:`.MapperProperty.info` dictionary of the
          :class:`.MapperProperty` unconditionally, including for a
          :class:`.ColumnProperty` that's associated directly with a
          :class:`_schema.Column`, the attribute can be referred to using
          :attr:`.QueryableAttribute.property` attribute, as
          ``MyClass.someattribute.property.info``.

        .. seealso::

            :attr:`.SchemaItem.info`

            :attr:`.MapperProperty.info`

        )r-�infor?s r9rLzQueryableAttribute.info{s��P��#�#r;c�4�tj|j��S)aReturn an inspection instance representing the parent.

        This will be either an instance of :class:`_orm.Mapper`
        or :class:`.AliasedInsp`, depending upon the nature
        of the parent entity which this attribute is associated
        with.

        )r$�inspectr.r?s r9�parentzQueryableAttribute.parent�s���!�$�"4�5�5�5r;c�4�|j���S)z�The SQL expression object represented by this
        :class:`.QueryableAttribute`.

        This will typically be an instance of a :class:`.ColumnElement`
        subclass representing a column expression.

        �r-�__clause_element__r?s r9�
expressionzQueryableAttribute.expression�s����1�1�3�3�3r;c�4�|j���Sr=rQr?s r9rRz%QueryableAttribute.__clause_element__�s����1�1�3�3�3r;c�4�|j���S)znlike __clause_element__(), but called specifically
        by :class:`_query.Query` to allow special behavior.)r-�_query_clause_elementr?s r9rVz(QueryableAttribute._query_clause_element�s����4�4�6�6�6r;c�6�|j�|��S)z'Return setter tuples for a bulk UPDATE.)r-�_bulk_update_tuples�r4�values  r9rXz&QueryableAttribute._bulk_update_tuples�s����2�2�5�9�9�9r;c��|jrJ�|�|j|j|j|j�|��|���S)N)r,r-r5)r/�	__class__�entityr+r,r-�adapt_to_entity�r4r^s  r9r^z"QueryableAttribute.adapt_to_entity�sQ���=� � � ��~�~��"��H�����6�6��G�G�(��
�
�	
r;c��t|j|j|j|j�|��|j|���S)N)r6)r'r*r+r,r-r6r.)r4�clss  r9r6zQueryableAttribute.of_type�sD��!��K��H��I��O�#�#�C�(�(����

�
�
�	
r;c�P�|����|��Sr=)rV�label)r4�names  r9rczQueryableAttribute.label�s"���)�)�+�+�1�1�$�7�7�7r;c�$�||jg|�Ri|��Sr=�r-�r4�op�other�kwargss    r9�operatezQueryableAttribute.operate�s$���r�$�/�4�E�4�4�4�V�4�4�4r;c� �|||jfi|��Sr=rfrgs    r9�reverse_operatez"QueryableAttribute.reverse_operate�s���r�%���3�3�F�3�3�3r;Fc�>�|j�||���duS)N)�
optimisticF�r,�	hasparent)r4�stateros   r9rqzQueryableAttribute.hasparent�s"���y�"�"�5�Z�"�@�@��M�Mr;c
��	t|j|��S#t$rc}tjtdt|��j�dt|j��j�d|�d|����|���Yd}~dSd}~wwxYw)N�Neither � object nor � object associated with � has an attribute ��replace_context)�getattrr-�AttributeErrorr%�raise_�type�__name__)r4r+�errs   r9�__getattr__zQueryableAttribute.__getattr__�s���	��4�?�C�0�0�0���
	�
	�
	��K����T�
�
�+�+�+��T�_�-�-�6�6�6������
�	�	�!$�
�
�
�
�
�
�
�
�
�
�����
	���s��
B�AA?�?Bc�.�|jj�d|j��S�N�.�r*r~r+r?s r9�__str__zQueryableAttribute.__str__�����+�.�.�.����9�9r;c��|jjS)z�Return the :class:`.MapperProperty` associated with this
        :class:`.QueryableAttribute`.


        Return values here will commonly be instances of
        :class:`.ColumnProperty` or :class:`.RelationshipProperty`.


        �r-�propertyr?s r9r�zQueryableAttribute.property�s����'�'r;)NNNN�F)r~�
__module__�__qualname__�__doc__�is_attributer:r%�memoized_propertyr@r�rCrrErJrLrOrSrRrVrXr^r6rcrkrmrqr�r�rIr;r9r'r'5s���������$�L�����=�=�=�=�6
��-�-���-��&�&��X�&�-8�
�
�
�
�
���
��'$�'$���'$�R
��	6�	6���	6��4�4��X�4�4�4�4�7�7�7�:�:�:�

�
�
�
�
�
�8�8�8�5�5�5�4�4�4�N�N�N�N����$:�:�:�
��
(�
(���
(�
(�
(r;r'c�$�eZdZdZd�Zd�Zd�ZdS)�InstrumentedAttributez�Class bound instrumented attribute which adds basic
    :term:`descriptor` methods.

    See :class:`.QueryableAttribute` for a description of most features.


    c�t�|j�t|��t|��|d��dSr=)r,�setr
r)r4rFrZs   r9�__set__zInstrumentedAttribute.__set__s=���	�
�
��8�$�$�m�H�&=�&=�u�d�	
�	
�	
�	
�	
r;c�p�|j�t|��t|����dSr=)r,�deleter
r)r4rFs  r9�
__delete__z InstrumentedAttribute.__delete__s0���	�����1�1�=��3J�3J�K�K�K�K�Kr;c��|�|St|��}|jr|j|vr
||jS|j�t|��|��Sr=)rr@r+r,�getr
)r4rF�owner�dict_s    r9�__get__zInstrumentedAttribute.__get__s\�����K��h�'�'���$�	B���U�):�):����?�"��9�=�=���!9�!9�5�A�A�Ar;N)r~r�r�r�r�r�r�rIr;r9r�r�
sS��������
�
�
�
L�L�L�B�B�B�B�Br;r�c���G�fd�dt��}t���jdz|_tj|t���d����|S)z�Create an QueryableAttribute / user descriptor hybrid.

    Returns a new QueryableAttribute type that delegates descriptor
    behavior and getattr() to the given descriptor.
    c���eZdZdZ			dd�ZdZed���Zed���Zej	d���Z
d�Zd	�Zd
�Z
�fd�ZdS)
�'create_proxied_attribute.<locals>.Proxyz�Presents the :class:`.QueryableAttribute` interface as a
        proxy on top of a Python descriptor / :class:`.PropComparator`
        combination.

        Nc�h�||_||_||_||_||_||_||_dSr=)r*r+�
descriptor�original_property�_comparator�_adapt_to_entityr�)r4r*r+r�r-r^�docr�s        r9r:z0create_proxied_attribute.<locals>.Proxy.__init__:s<��!�D�K��D�H�(�D�O�%6�D�"�)�D��$3�D�!��D�L�L�Lr;Tc�\�|jduo#t|j|j��jjSr=)r�rzr*r+r,rBr?s r9rCz:create_proxied_attribute.<locals>.Proxy._impl_uses_objectsNs1���&�d�2�E��D�K���2�2�7�D�
r;c��|jjSr=r�r?s r9r�z0create_proxied_attribute.<locals>.Proxy.propertyUs
���?�+�+r;c���tj|j��r|���|_|jr$|j�|j��|_|jSr=)r%�callabler�r�r^r?s r9r-z2create_proxied_attribute.<locals>.Proxy.comparatorYsb���}�T�-�.�.�
6�#'�#3�#3�#5�#5�� ��$�
�#'�#3�#C�#C��)�$�$�� ��#�#r;c�\�|�|j|j|j|j|��Sr=)r\r]r+r�r�r_s  r9r^z7create_proxied_attribute.<locals>.Proxy.adapt_to_entitycs1���>�>��&������ ����
r;c�V�|j�||��}||jur|�|S|Sr=)r�r�)r4rFr��retvals    r9r�z/create_proxied_attribute.<locals>.Proxy.__get__ls7���_�,�,�X�u�=�=�F����(�(�X�-=����
r;c�.�|jj�d|j��Sr�r�r?s r9r�z/create_proxied_attribute.<locals>.Proxy.__str__vs��"�k�2�2�2�D�H�H�=�=r;c�p��	t�|��S#t$�r}|dkr#tjtd��|���	|j}	t||��cYd}~S#t$r]}tjtdt���j�dt|��j�d|�d|����|���Yd}~n]d}~wwxYw#t$rH}tjtdt���j�d|�d|����|���Yd}~nd}~wwxYwYd}~dSYd}~dSd}~wwxYw)	zNDelegate __getattr__ to the original descriptor and/or
            comparator.r-rxNrtrurvrwz; object nor unconfigured comparator object associated with )rzr{r%r|r-r}r~)r4�	attributerr-�err3�err2r�s      �r9r�z3create_proxied_attribute.<locals>.Proxy.__getattr__ys���#
��z�9�5�5�5��!�!
�!
�!
���,�,��K�&�|�4�4�c������!%��J��&�z�9�=�=�=�=�=�=�=�=��)�
�
�
���*�N�%)��$4�$4�$=�$=�$=�$(��$4�$4�$=�$=�$=�$(�D�D�$-�I�
!"�	�	�-1��������������
�����&�����K�&�� $�J�/�/�8�8�8�$�$�$�	�	�K���
)-�
���������������������������������!
���sc��D5�)D0�C�A%�D5�%
C�/AC�D0�C�D0�
D!�>D�D0�D!�!D0�0D5�NNN)r~r�r�r�r:�_is_internal_proxyr�rCr%r�r-r^r�r�r�)r�s�r9�Proxyr�3s��������	�	�!��"�	�	�	�	�$"��	�	�	�
��	�
�	,�	,�
��	,�
�	�	$�	$�
 �	�	$�	�	�	�	�	�	�	>�	>�	>�&	�&	�&	�&	�&	�&	�&	r;r�r�)rd�
from_instance)r'r}r~r%�monkeypatch_proxied_specials)r�r�s` r9�create_proxied_attributer�)s����l�l�l�l�l�l�l�"�l�l�l�\�*�%�%�.��8�E�N��%�
�t�J���l�*������Lr;�REMOVE�APPEND�REPLACE�BULK_REPLACE�MODIFIEDc�>�eZdZdZdZd�Zd�Zed���Zd�Z	dS)�Eventa�A token propagated throughout the course of a chain of attribute
    events.

    Serves as an indicator of the source of the event and also provides
    a means of controlling propagation across a chain of attribute
    operations.

    The :class:`.Event` object is sent as the ``initiator`` argument
    when dealing with events such as :meth:`.AttributeEvents.append`,
    :meth:`.AttributeEvents.set`,
    and :meth:`.AttributeEvents.remove`.

    The :class:`.Event` object is currently interpreted by the backref
    event handlers, and is used to control the propagation of operations
    across two mutually-dependent attributes.

    .. versionadded:: 0.9.0

    :attribute impl: The :class:`.AttributeImpl` which is the current event
     initiator.

    :attribute op: The symbol :attr:`.OP_APPEND`, :attr:`.OP_REMOVE`,
     :attr:`.OP_REPLACE`, or :attr:`.OP_BULK_REPLACE`, indicating the
     source operation.

    �r,rh�parent_tokenc�D�||_||_|jj|_dSr=r�)r4�attribute_implrhs   r9r:zEvent.__init__�s#��"��	���� �I�2����r;c�h�t|t��o|j|juo|j|jkSr=)�
isinstancer�r,rh)r4ris  r9�__eq__zEvent.__eq__�s6���u�e�$�$�
$��
�d�i�'�
$���D�G�#�	
r;c��|jjSr=)r,r+r?s r9r+z	Event.key�s���y�}�r;c�6�|j�|��Sr=rp)r4rrs  r9rqzEvent.hasparent�s���y�"�"�5�)�)�)r;N)
r~r�r�r��	__slots__r:r�r�r+rqrIr;r9r�r��sm��������6-�I�3�3�3�

�
�
�����X��*�*�*�*�*r;r�c���eZdZdZ								dd�ZdZd�Zd�Zd	�Ze	ee��Z
dd
�Zd�Ze
fd�Zefd
�Zd�Ze
fd�Ze
fd�Ze
fd�Ze
fd�Ze
ddfd�Ze
fd�Zd�ZdS)�
AttributeImplz4internal implementation for instrumented attributes.FNTc
��||_||_||_||_||_|	p||_||_|�tj|_	n||_	|�||_
n|j|_
t|��|}tj|pg��D]}|�||���|rd|j_|
|_t%|t&��|_dS)a*Construct an AttributeImpl.

        :param \class_: associated class

        :param key: string name of the attribute

        :param \callable_:
          optional function which generates a callable based on a parent
          instance, which produces the "default" values for a scalar or
          collection attribute when it's first accessed, if not present
          already.

        :param trackparent:
          if True, attempt to track if an instance has a parent attached
          to it via this attribute.

        :param extension:
          a single or list of AttributeExtension object(s) which will
          receive set/delete/append/remove/etc. events.
          The event package is now used.

          .. deprecated::  1.3

            The :paramref:`.AttributeImpl.extension` parameter is deprecated
            and will be removed in a future release, corresponding to the
            "extension" parameter on the :class:`.MapperProprty` classes
            like :func:`.column_property` and :func:`_orm.relationship`  The
            events system is now used.

        :param compare_function:
          a function that compares two values which are normally
          assignable to this attribute.

        :param active_history:
          indicates that get_history() should always return the "old" value,
          even if it means executing a lazy callable upon attribute change.

        :param parent_token:
          Usually references the MapperProperty, used as a key for
          the hasparent() function to identify an "owning" attribute.
          Allows multiple AttributeImpls to all match a single
          owner attribute.

        :param expire_missing:
          if False, don't add an "expiry" callable to this attribute
          during state.expire_attributes(None), if no value is present
          for this key.

        :param send_modified_events:
          if False, the InstanceState._modified_event method will have no
          effect; this means the attribute will never show up as changed in a
          history entry.

        NT)r*r+�	callable_r1�trackparentr��send_modified_events�operator�eq�is_equal�accepts_scalar_loader�default_accepts_scalar_loaderrr%�to_list�_adapt_listenerr3�expire_missingr��OP_MODIFIED�_modified_token)r4r*r+r�r1r��	extension�compare_function�active_historyr�r�r�r�rj�attr�exts                r9r:zAttributeImpl.__init__�s���L������"��� ��
�&���(�0�D���$8��!��#�$�K�D�M�M�,�D�M� �,�)>�D�&�&�)-�)K�D�&� ��'�'��,���<�	��R�0�0�	+�	+�C�����c�*�*�*�*��	1�,0�D�M�)�,���$�T�;�7�7����r;)r*r+r�r1r�r�r�r�r�r�r�c�.�|jj�d|j��Sr�r�r?s r9r�zAttributeImpl.__str__Wr�r;c��|jjS)z(Backwards compat for impl.active_history�r1r3r?s r9�_get_active_historyz!AttributeImpl._get_active_historyZs���}�,�,r;c��||j_dSr=r�rYs  r9�_set_active_historyz!AttributeImpl._set_active_history_s��(-��
�%�%�%r;c��d}|js
J|���|j�t|j��|��duS)a4Return the boolean value of a `hasparent` flag attached to
        the given state.

        The `optimistic` flag determines what the default return value
        should be if no `hasparent` flag can be located.

        As this function is used to determine if an instance is an
        *orphan*, instances that were loaded from storage should be
        assumed to not be orphans, until a True/False value for this
        flag is set.

        An instance attribute that is loaded by a callable function
        will also not have a `hasparent` flag.

        �6This AttributeImpl is not configured to track parents.F)r��parentsr��idr�)r4rrro�msgs    r9rqzAttributeImpl.hasparentdsM�� G����$�$��$�$��
�M���b��!2�3�3�Z�@�@��M�	
r;c	�~�d}|js
J|���t|j��}|r||j|<dS||jvrt|j|}|durc|j|jkrS|����=t
jdt|���dt|���d|j�d����dSd|j|<dS)z�Set a boolean flag on the given item corresponding to
        whether or not it is attached to a parent object via the
        attribute represented by this ``InstrumentedAttribute``.

        r�FNzRemoving state z from parent state z along attribute 'zV', but the parent record has gone stale, can't be sure this is the most recent parent.)	r�r�r�r�r+�obj�orm_exc�StaleDataErrorr!)r4rr�parent_staterZr��id_�last_parents       r9�sethasparentzAttributeImpl.sethasparent{s���G����$�$��$�$����"�#�#���	'�!-�E�M�#�����e�m�#�#�#�m�C�0�� �u�,�,�#��<�+;�;�;�#���(�(�0�%�4�4�!*�%� 0� 0� 0� 0� )�,� 7� 7� 7� 7� $����	�����F�!&�E�M�#���r;c��t���r=��NotImplementedError�r4rrr�rGs    r9rEzAttributeImpl.get_history�s��!�#�#�#r;c��t���)a�Return a list of tuples of (state, obj)
        for all objects in this attribute's current state
        + history.

        Only applies to object-based attributes.

        This is an inlining of existing functionality
        which roughly corresponds to:

            get_state_history(
                        state,
                        key,
                        passive=PASSIVE_NO_INITIALIZE).sum()

        r�r�s    r9�get_all_pendingzAttributeImpl.get_all_pending�s�� "�#�#�#r;c�X�d}|jjD]}||||��}|tur|}�|S)z;Initialize the given state's attribute with an empty value.N)r1�init_scalarr)r4rrr�rZ�fn�rets      r9�
initializezAttributeImpl.initialize�sF�����-�+�	�	�B��"�U�E�5�)�)�C��*�$�$�����r;c��|j|vr
||jS|j}||jvs|j|tur�|tzstS||jvr|�||��}nH||jvr|j|}|||��}n%|jr|�||��}nt}|tus	|tur|S|turF	||S#t$r0}tj
td|z��|���Yd}~n(d}~wwxYw|tur|�|||��S|tzstS|�||��S)z�Retrieve a value from the given object.
        If a callable is assembled on this object's attribute, and
        passive is False, the callable will be executed and the
        resulting value will be set as the new value for this attribute.
        z=Deferred loader for attribute %r failed to populate correctlyrxN)r+�committed_staterr	r�expired_attributes�
_load_expired�	callablesr�rr�KeyErrorr%r|�set_committed_valuer
r�)r4rrr�rGr+rZr�rs        r9r�zAttributeImpl.get�s����8�u������?�"��(�C��5�0�0�0��(��-��:�:���-�-�,�,��%�2�2�2�!�/�/��w�?�?�E�E��E�O�+�+� %��� 4�I�%�I�e�W�5�5�E�E��^�'� �N�N�5�'�:�:�E�E�&�E��-�-�-��)�1C�1C� �L��l�*�*��$�S�z�)��#�	�	�	���$�!,�.1�!2���
-0�
�������������	�����*�,�,��3�3�E�5�%�H�H�H��W�$�
5� � ����u�e�4�4�4s�C�
D�$&D�Dc�:�|�|||||���dS�N�rG�r��r4rrr�rZ�	initiatorrGs      r9�appendzAttributeImpl.append�s$�������u�i���A�A�A�A�Ar;c�<�|�||d|||���dS)N)rG�	check_oldrrs      r9�removezAttributeImpl.remove�s4������5�$�	�7�e�	�	
�	
�	
�	
�	
r;c	�>�|�||d|||d���dS)NT)rGr�poprrs      r9rzAttributeImpl.pop�s<������������	�	
�	
�	
�	
�	
r;c��t���r=r�)r4rrr�rZrrGrrs        r9r�zAttributeImpl.set	s��"�#�#�#r;c��|j|jvr&|j|j}|ttfvrdS|S|�|||���S)z,return the unchanged value of this attributeNr)r+r�rrr�)r4rrr�rGrZs     r9�get_committed_valuez!AttributeImpl.get_committed_valuesU���8�u�,�,�,��)�$�(�3�E���9�-�-�-��t����8�8�E�5�'�8�:�:�:r;c�R�|||j<|�||jg��|S)z=set an attribute value on the given instance and 'commit' it.)r+�_commit)r4rrr�rZs    r9rz!AttributeImpl.set_committed_value!s,�� ��d�h��
�
�
�e�d�h�Z�(�(�(��r;)FNNFNTTNr�)r~r�r�r�r:r�r�r�r�r�r�rqr�rrErr�r�r�r	rrr�rrrIr;r9r�r��s�������>�>�������!�"�b8�b8�b8�b8�H�I�:�:�:�-�-�-�
.�.�.��X�1�3F�G�G�N�
�
�
�
�.%'�%'�%'�N1<�$�$�$�$�5J�$�$�$�$�$	�	�	�)4�25�25�25�25�h>I�B�B�B�B�>I�
�
�
�
�
;F�	
�	
�	
�	
�"���
$�
$�
$�
$�9D�
;�
;�
;�
;�����r;r�c�z��eZdZdZdZdZdZdZdZdZ	�fd�Z
d�Zefd�Z
eddfd	�Zd
�Zd�Zed���Z�xZS)
�ScalarAttributeImplz8represents a scalar value-holding InstrumentedAttribute.TF)�_replace_token�
_append_token�
_remove_tokenc���tt|��j|i|��t|t��x|_|_t|t��|_dSr=)	�superrr:r��
OP_REPLACErr�	OP_REMOVEr)r4�arg�kwr\s   �r9r:zScalarAttributeImpl.__init__4sX���1��!�4�(�(�1�3�=�"�=�=�=�38��z�3J�3J�J���d�0�"�4��3�3����r;c���|jjr|�||t��}n |�|jt
��}|jjr|�||||j��|�	|||��|�
|jt
��}|t
ur0|t
ur)|js$|j|jvrtd|z���dSdSdSdS)N�%s object does not have a value)r1r3r�rr+rr�fire_remove_eventr�_modified_eventr�expiredr�r{�r4rrr��old�existings     r9r�zScalarAttributeImpl.delete9s����=�(�	0��(�(�5�%�)A�B�B�C�C��)�)�D�H�h�/�/�C��=��	J��"�"�5�%��d�6H�I�I�I�
���e�T�3�/�/�/��9�9�T�X�x�0�0���� � ��x����M� ���� 8�8�8� �!B�T�!I�J�J�J�
!� �����8�8r;c��|j|vr't�||||j��S|tzr
|tz}|�|||���}|t
urtSt�|||��Sr)r+�History�from_scalar_attributer
r�r�
HISTORY_BLANK�r4rrr�rG�currents     r9rEzScalarAttributeImpl.get_historyL����8�u����0�0��u�e�D�H�o�N�N�N��� �
#��7�"���h�h�u�e�W�h�=�=�G��+�+�+�$�$��4�4�T�5�'�J�J�Jr;Nc�$�|jjr|�||t��}n |�|jt
��}|jjr|�|||||��}|�|||��|||j<dSr=)	r1r3r�rr+rr��fire_replace_eventr"�	r4rrr�rZrrGrrr%s	         r9r�zScalarAttributeImpl.setXs����=�(�	0��(�(�5�%�)A�B�B�C�C��)�)�D�H�h�/�/�C��=��	��+�+��u�e�S�)���E�	���e�T�3�/�/�/���d�h���r;c�N�|jjD]}|||||p|j��}�|Sr=)r1r�r�r4rrr�rZ�previousrr�s       r9r/z&ScalarAttributeImpl.fire_replace_eventnsA���-�#�	�	�B��B��u�h�	�(H�T�5H���E�E��r;c�L�|jjD]}||||p|j���dSr=)r1rr�r4rrr�rZrr�s      r9r!z%ScalarAttributeImpl.fire_remove_eventus?���-�&�	>�	>�B��B�u�e�Y�<�$�*<�=�=�=�=�	>�	>r;c�4�|jjdjdS)Nr)r��columnsr}r?s r9r}zScalarAttributeImpl.typeys���
��a� �%�%�%�%r;)r~r�r�r�r�rBr>�
collection�dynamicr�r:r�rrEr�r/r!r�r}�
__classcell__�r\s@r9rr)s��������B�B�$(�!��L����J��G�B�I�4�4�4�4�4�
K�K�K�&1<�
K�
K�
K�
K�$��� � � � �,���>�>�>��&�&��X�&�&�&�&�&r;rc�Z�eZdZdZdZdZdZdZdZd�Z	e
fd�Zefd�Z
e
ddfd	�Zd
�Zd�ZdS)�ScalarObjectAttributeImplz�represents a scalar-holding InstrumentedAttribute,
    where the target object is also instrumented.

    Adds events to delete/set operations.

    FTrIc��|jjr.|�||ttzt
z���}n5|�||ttzt
ztz���}|�	||||j
��|�|jt��}|tur"|tur|j�td|z���dSdSdS)Nrr )r1r3r�rrrrr
rr!rrr+rrr{r$s     r9r�z ScalarObjectAttributeImpl.delete�s����=�(�	��(�(���/���(�)����C�C��(�(���(�7�2�(�)������C�	
���u�e�S�$�2D�E�E�E��9�9�T�X�x�0�0��
�� � ��,�,�,��	�!� �!B�T�!I�J�J�J�	
!� �,�,�!�!r;c��|j|vr't�||||j��S|tzr
|tz}|�|||���}|t
urtSt�|||��Sr)r+r(�from_object_attributer
r�rr*r+s     r9rEz%ScalarObjectAttributeImpl.get_history�r-r;c��|j|vr||j}n%|tzr|�|||���}ngS|�%|tur|turt|��|fg}ndg}|j|jvrN|j|j}|�:|tur1|tur(||ur$|�t|��|f��|S)Nr)NN)r+r	r�rrr
r�r	)r4rrr�rGr,r��originals       r9r�z)ScalarObjectAttributeImpl.get_all_pending�s����8�u����D�H�o�G�G�
�|�
#�	��h�h�u�e�W�h�=�=�G�G��I�
���0�0�0��y�(�(�"�7�+�+�W�5�6�C�C��.�C��8�u�,�,�,��,�T�X�6�H��$��$5�5�5��I�-�-��G�+�+��
�
�N�8�4�4�h�?�@�@�@��
r;Nc	��|jjr.|�||ttzt
z���}n5|�||ttzt
ztz���}|�I|tur@||ur<|rdStdt|���dt|���d|j
�d����|�|||||��}|||j
<dS)z'Set a value on the given InstanceState.rNzObject z not associated with z on attribute '�')r1r3r�rrrrr
rr�
ValueErrorrr!r+r/r0s	         r9r�zScalarObjectAttributeImpl.set�s���=�(�	��(�(���/���(�)����C�C��(�(���(�7�2�(�)������C�
�!��,�,�,���$�$��
��� �j�#�I�.�.�.�.�	�%�0@�0@�0@�0@�$�(�(�(�L����
�'�'��u�e�S�)�L�L����d�h���r;c���|jr&|�$|�t|��|d��|jjD]}||||p|j���|�|||��dS)NF)r�r�r
r1rrr"r5s      r9r!z+ScalarObjectAttributeImpl.fire_remove_events�����	C�� 1����n�U�3�3�U�E�B�B�B��-�&�	>�	>�B��B�u�e�Y�<�$�*<�=�=�=�=�
���e�T�5�1�1�1�1�1r;c�V�|jr9||ur5|dttfvr$|�t	|��|d��|jjD]}|||||p|j��}�|�|||��|jr&|�$|�t	|��|d��|S�NFT)	r�rrr�r
r1r�rr"r2s       r9r/z,ScalarObjectAttributeImpl.fire_replace_events�����	J��u�$�$���!��:�*�*�
�!�!�.��":�":�E�5�I�I�I��-�#�	�	�B��B��u�h�	�(H�T�5H���E�E�	���e�T�8�4�4�4���	F�� ��!�!�.��"7�"7���E�E�E��r;)r~r�r�r�r�rBr>r8r�r�rrErr�r�r!r/rIr;r9r=r=~s���������%*�!��L����J��I�K�K�K�@1<�
K�
K�
K�
K�5J�����H���* �* �* �* �X2�2�2�����r;r=c����eZdZdZdZdZdZdZdZdZ						d�fd�	Z
d�Zefd�Z
efd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zefd�Zefd�Zefd�Zdeddfd�Zd�Zd�Zdefd�Z�xZS)�CollectionAttributeImpla�A collection-holding attribute that instruments changes in membership.

    Only handles collections of instrumented objects.

    InstrumentedCollectionAttribute holds an arbitrary, user-specified
    container object (defaulting to a list) and brokers access to the
    CollectionAdapter, a "view" onto that object that presents consistent bag
    semantics to the orm layer independent of the user data implementation.

    FT)�copy�collection_factoryrr�_bulk_replace_token�_duck_typed_asNc
� ��tt|��j||||f|||	d�|
��|�|j}||_||_t
|t��|_t
|t��|_
t
|t��|_tj|�����|_t!|jdd��r>t#j|d��d���}t#j|d��d���}dSdS)N)r�r�r��
_sa_linker�init_collectionc�0�|�|��dSr=�rP��targetr8�collection_adapters   r9�linkz.CollectionAttributeImpl.__init__.<locals>.linkcs���%�%�&8�9�9�9�9�9r;�dispose_collectionc�0�|�d��dSr=rSrTs   r9�unlinkz0CollectionAttributeImpl.__init__.<locals>.unlinkgs���%�%�d�+�+�+�+�+r;)rrJr:�_CollectionAttributeImpl__copyrKrLr��	OP_APPENDrrr�OP_BULK_REPLACErMr%�duck_type_collectionrNrzr#�listens_for)r4r*r+r�r1�typecallabler�r��
copy_functionr�rjrWrZr\s             �r9r:z CollectionAttributeImpl.__init__>sI���	6��%�t�,�,�5�����			
�
$��-�		
�		
��		
�		
�		
�� � �K�M�!��	�".���"�4��3�3���"�4��3�3���#(���#?�#?�� �"�7��#�#�%�%�
�
����4�*�L�$�?�?�	,�
�
�t�%6�
7�
7�
:�
:�8�
7�
:��
�t�%9�
:�
:�
,�
,�;�
:�
,�
,�
,�	,�	,r;c�>�d�tj|��D��S)Nc��g|]}|��SrIrI)�.0�ys  r9�
<listcomp>z2CollectionAttributeImpl.__copy.<locals>.<listcomp>ls��@�@�@�a��@�@�@r;)rrV)r4�items  r9�__copyzCollectionAttributeImpl.__copyks!��@�@�;�9�$�?�?�@�@�@�@r;c��|�|||���}|turtSt�|||��Sr)r�rr*r(�from_collectionr+s     r9rEz#CollectionAttributeImpl.get_historynsC���(�(�5�%��(�9�9���'�'�'� � ��*�*�4���@�@�@r;c���	�|j|vrgS||j}t|d��}|j|jvr�|j|j}|ttfvrbd�|D��}d�|D��}t|���t|���	�	fd�|D���	fd�|D��z�fd�|D��zSd�|D��S)N�_sa_adapterc�<�g|]}|durt|��pd|f��Sr=r�rd�cs  r9rfz;CollectionAttributeImpl.get_all_pending.<locals>.<listcomp>�sC��"�"�"���t�m�:���):�):�B�d�A�F�"�"�"r;c�<�g|]}|durt|��pd|f��Sr=rrns  r9rfz;CollectionAttributeImpl.get_all_pending.<locals>.<listcomp>�sC��#�#�#���t�m�:���):�):�B�d�A�F�#�#�#r;c�&��g|]
\}}|�v�	||f��SrIrI�rd�s�o�original_sets   �r9rfz;CollectionAttributeImpl.get_all_pending.<locals>.<listcomp>�s6������ �A�q��L�0�0��A��0�0�0r;c�&��g|]
\}}|�v�	||f��SrIrIrrs   �r9rfz;CollectionAttributeImpl.get_all_pending.<locals>.<listcomp>�s+���N�N�N�$�!�Q�A��<M�<M��1�v�<M�<M�<Mr;c�&��g|]
\}}|�v�	||f��SrIrI�rdrsrt�current_sets   �r9rfz;CollectionAttributeImpl.get_all_pending.<locals>.<listcomp>�s6������ �A�q��K�/�/��A��/�/�/r;c�0�g|]}t|��|f��SrIr)rdrts  r9rfz;CollectionAttributeImpl.get_all_pending.<locals>.<listcomp>�s%��8�8�8�1���"�"�A�&�8�8�8r;)r+rzr�rr�dict)
r4rrr�rGr,rB�current_states�original_statesryrus
        @@r9r�z'CollectionAttributeImpl.get_all_pendingusE�����8�5� � ��I����/���'�=�1�1���8�u�,�,�,��,�T�X�6�H���)�4�4�4�"�"�$�"�"�"��#�#�%�#�#�#��
#�>�2�2��#�O�4�4������$2����
O�N�N�N�.�N�N�N�O�����$3����
��9�8��8�8�8�8r;c���|jjD]}||||p|j��}�|�||td��|jr&|�$|�t|��|d��|Sr))r1r	rr"rr�r�r
r5s      r9�fire_append_eventz)CollectionAttributeImpl.fire_append_event�s����-�&�	F�	F�B��B�u�e�Y�%D�$�2D�E�E�E�E�
���e�T�9�d�;�;�;���	B�� 1����n�U�3�3�U�D�A�A�A��r;c�@�|�||td��dS)afA special event used for pop() operations.

        The "remove" event needs to have the item to be removed passed to
        it, which in the case of pop from a set, we don't have a way to access
        the item before the operation.   the event is used for all pop()
        operations (even though set.pop is the one where it is really needed).

        TN)r"r)r4rrr�rs    r9�fire_pre_remove_eventz-CollectionAttributeImpl.fire_pre_remove_event�s$��	���e�T�9�d�;�;�;�;�;r;c���|jr&|�$|�t|��|d��|jjD]}||||p|j���|�||td��dSrH)r�r�r
r1rrr"rr5s      r9r!z)CollectionAttributeImpl.fire_remove_event�s�����	C�� 1����n�U�3�3�U�E�B�B�B��-�&�	>�	>�B��B�u�e�Y�<�$�*<�=�=�=�=�
���e�T�9�d�;�;�;�;�;r;c���|j|vrdS|�||td��|�||j��}|���||j=dSr))r+r"r�get_collectionr{�clear_with_event)r4rrr�r8s    r9r�zCollectionAttributeImpl.delete�sf���8�5� � ��F�
���e�T�9�d�;�;�;��(�(���
�;�;�
��#�#�%�%�%�
�$�(�O�O�Or;c�J�|�|��\}}|||j<|S)z3Initialize this attribute with an empty collection.)�_initialize_collectionr+)r4rrr��_�	user_datas     r9r�z"CollectionAttributeImpl.initialize�s,���2�2�5�9�9���9�#��d�h���r;c��|j�|j||j��\}}|j�|||��||fSr=)r7�initialize_collectionr+rLr1rQ)r4rr�adapterr8s    r9r�z.CollectionAttributeImpl._initialize_collection�sQ��#�m�A�A��H�e�T�4�
�
����	
�
�%�%�e�Z��A�A�A��
�"�"r;c�(�|�|||���}|turZ|�||||��}|j|vs
Jd���|�|j���|��dS|�||��dS�Nrz,Collection was loaded during event handling.)r�rrr+�_get_pending_mutationr	�append_with_event�r4rrr�rZrrGr8s       r9r	zCollectionAttributeImpl.append�s����(�(���w�(�G�G�
��*�*�*��*�*�5�%��	�J�J�E����%�%�%�=�&�%�%��'�'���1�1�8�8��?�?�?�?�?��(�(��	�:�:�:�:�:r;c�2�|�||j|���}|turZ|�||||��|j|vs
Jd���|�|j���|��dS|�||��dSr�)r�r{rr!r+r�r�remove_with_eventr�s       r9rzCollectionAttributeImpl.remove�s����(�(���
�G�(�L�L�
��*�*�*��"�"�5�%��	�B�B�B����%�%�%�=�&�%�%��'�'���1�1�8�8��?�?�?�?�?��(�(��	�:�:�:�:�:r;c�x�	|�|||||���dS#tttf$rYdSwxYwr)rrEr�
IndexErrorrs      r9rzCollectionAttributeImpl.pop�sT��	�
�K�K��u�e�Y��K�H�H�H�H�H���H�j�1�	�	�	��D�D�	���s��9�9c���|x}}	|�|��\}
}|r�|
j�|
�|��}n�tj|��}|j}
||
ur4|durdp|jj}|jj}td|�d|�d����t|d��r|�	��}nX|tur@tjr|���}n.t|d|j����}nt|��}t|��}|j}|j�|||��|�||t(���}|t*ur|�||��}n||	urdS|�|||d��|j}|||j<t5j|||
|�	��|`|j�|||��dS)
N�NonezIncompatible collection type: z is not z-like�_sa_iterator�
itervaluesrT)r)r��
_converterr%r^rNr\r~�	TypeError�hasattrr�r{�py3k�valuesrz�iter�listrMr1�bulk_replacer�rrr�r"rlr+rrX)r4rrr�rZrrGr�_adapt�iterable�
orig_iterable�new_collectionr��setting_type�receiving_type�given�wanted�
new_values�evtr%�old_collections                    r9r�zCollectionAttributeImpl.set�s9��$)�(��=�%)�$?�$?��$F�$F�!��	��	.��(�4�)�4�4�X�>�>���#�8��B�B��!%�!4���~�5�5� �D�(�#�"�7�#�-�6��
"�0�9�F�#�)� �5�5�&�&�&�*�����8�^�4�4�
.�'�4�4�6�6�H�H�!�T�)�)��y��#+�?�?�#4�#4���$�7�$�l�H�O�$�$�$�$��� $�H�~�~�H��(�^�^�
��&���
�"�"�5�*�c�:�:�:��h�h�u�e�-D�h�E�E���#�#�#��/�/�%��/�/�C�C�
�M�
!�
!�
�F�	���e�T�3��5�5�5����#��d�h��� ����#�	
�	
�	
�	
�
�O��
�(�(���^�D�D�D�D�Dr;c�4�t|d��}d|_dS)NrlT)rz�invalidated)r4r8r�s   r9�_invalidate_collectionz.CollectionAttributeImpl._invalidate_collectionDs���*�m�4�4��"����r;c���|�|��\}}|r|�|��||j|j<|�||jg��|j|jvry|�|||d��|j�|j��}|j}|j	}|D]}	|�
|	���|D]}	|�|	���|S)z=Set an attribute value on the given instance and 'commit' it.T)r��append_multiple_without_eventr{r+r�_pending_mutationsr"r�added_items�
deleted_items�append_without_event�remove_without_event)
r4rrr�rZr8r��pending�added�removedrgs
          r9rz+CollectionAttributeImpl.set_committed_valueHs��!%� ;� ;�E� B� B��
�I��	<��4�4�U�;�;�;�(��
�4�8��
�
�
�e�d�h�Z�(�(�(��8�u�/�/�/�
�!�!�%��y�$�?�?�?��.�2�2�4�8�<�<�G��'�E��+�G��
6�
6���/�/��5�5�5�5��
6�
6���/�/��5�5�5�5��r;c�l�|�#|�|||���}|tur|St|d��S)z�Retrieve the CollectionAdapter associated with the given state.

        Creates a new CollectionAdapter if one does not exist.

        Nrrl)r�rrz)r4rrr�r�rGs     r9r�z&CollectionAttributeImpl.get_collectioncsC���������w��?�?�I��-�-�-� � ��y�-�0�0�0r;)NFNNN)r~r�r�r�r�rBr>r8r9r�r:r[rrErr�rr�r!r�r�r�r	rrr�r�rr�r:r;s@r9rJrJ#s��������	�	�%*�!��L����J��G��I������+,�+,�+,�+,�+,�+,�ZA�A�A�1<�A�A�A�A�5J�&9�&9�&9�&9�P	�	�	�	<�	<�	<�<�<�<�������#�#�#�>I�	;�	;�	;�	;�>I�	;�	;�	;�	;�;F���������IE�IE�IE�IE�V#�#�#����8'+�K�
1�
1�
1�
1�
1�
1�
1�
1r;rJc�
��������jj��j��fd������fd�}���fd�}���fd�}�rtj�d|dd���ntj�d|dd���tj�d	|dd���d
S)z6Apply listeners to synchronize a two-way relationship.c�~��tdt|���d|j�d|j�d�jj�d�	���)Nz:Bidirectional attribute conflict detected: Passing object z to attribute "z(" triggers a modify event on attribute "z" via the backref "z".)rEr!r�r,)�child_stater�
child_implr�s   �r9�_acceptable_key_errz.backref_listeners.<locals>._acceptable_key_err�sU����j��+�&�&�&�&��&�&�&��'�'�'���+�+�+�	
�
�
�	
r;c���||ur|S|��|tur�|tur�t|��t|��}}|j�j}|js|js|j}n|j	}||ur6|�
|||����jt���|��t|��t|��}	}|j�j}
|j�ur|j|
jur
�
|||
��|
j}|
jr|
jnd}||ur5||ur1|
�||	|���|t���|Sr)rrr
rr7r,r8r9rrrr�rrr�rMr	)rr�child�oldchildr�	old_state�old_dictr,�check_recursive_tokenr��
child_dictr��check_append_token�check_bulk_replace_tokenr�r+�parent_implr�s             ����r9�"emit_backref_from_scalar_set_eventz=backref_listeners.<locals>.emit_backref_from_scalar_set_event�s�����u����L�� �� 1�1�1��	�)�)�
�x�(�(��h�'�'� �I��$�S�)�.�D��?�
;�4�<�
;�(,�(;�%�%�(,�(:�%�� 5�5�5�������I�I�K�K��-�,��������u�%�%��e�$�$�$�K�%�,�S�1�6�J��&�l�:�:��*�*�2I�I�I�#�#�E�9�j�A�A�A�",�!9���(��
�.�.��
%��!3�3�3��%=�=�=��!�!����I�I�K�K��,�"�����r;c�X��|�dSt|��t|��}}|j�	j}|j�
ur|j|jur
�|||��|j}|jr|jnd}||ur5||ur1|�|||�	��|t���|Sr)r
rr7r,r�rr8rMr	r�r)rrr�rr�r�r�r�r�r�r+r�s        ���r9�)emit_backref_from_collection_append_eventzDbackref_listeners.<locals>.emit_backref_from_collection_append_event�s�����=��F�"0��"7�"7��u�9M�9M�Z�� �(��-�2�
�
�"�,�6�6��&�j�.E�E�E����y�*�=�=�=�(�5��.8�.C�M�J�*�*��	!�

�/�/�/��!9�9�9�������	�	����(�
�
�
�
��r;c����|��|tur�|tur�t|��t|��}}|j�	j}|js |js|j}|j	}�o�
j}n|j}|jr|j
nd}d}||urd||urb|r%tj|j
�
j|��s=|�|||���|t"���dSdSdSdSdSdSdS)NFr)rrr
rr7r,r8r9rrrMr%�	has_dupesr{r+rr�r)rrr�rr�r�r��check_remove_token�check_replace_token�check_for_dupes_on_remover+r��uselists         ���r9�)emit_backref_from_collection_remove_eventzDbackref_listeners.<locals>.emit_backref_from_collection_remove_event�so������.�.�.��Y�&�&��u�%�%��e�$�$�$�K�%�,�S�1�6�J��(�
2��1C�
2�%/�%=�"�&0�&?�#�,3�,O�K�<O�8O�)�)�%/�%=�"�"�,��J�2�2��$�
-2�)��!3�3�3��%8�8�8�1�����J�{��/��	9�9���N�N�#�"��	�	���!� 0�#������G
��.�.�&�&�.4�3�8�8��r;r	T)r��rawr�rN)r,r�r#�listen)	r�r+r�r�r�r�r�r�r�s	```   @@@r9�backref_listenersr�ss:���������>�.�L��.�K�
�
�
�
�
�?�?�?�?�?�?�?�?�B�������@+�+�+�+�+�+�+�Z�
�
����5���	
�	
�	
�	
�	
�	����.���	
�	
�	
�	
�
�L���1��������r;�
NO_HISTORYr(�r��	unchanged�deletedc��eZdZdZd�ZeZd�Zd�Zd�Zd�Z	d�Z
d�Zed	���Z
ed
���Zed���ZdS)
r(aA 3-tuple of added, unchanged and deleted values,
    representing the changes which have occurred on an instrumented
    attribute.

    The easiest way to get a :class:`.History` object for a particular
    attribute on an object is to use the :func:`_sa.inspect` function::

        from sqlalchemy import inspect

        hist = inspect(myobject).attrs.myattribute.history

    Each tuple member is an iterable sequence:

    * ``added`` - the collection of items added to the attribute (the first
      tuple element).

    * ``unchanged`` - the collection of items that have not changed on the
      attribute (the second tuple element).

    * ``deleted`` - the collection of items that have been removed from the
      attribute (the third tuple element).

    c��|tkSr=)r*r?s r9�__bool__zHistory.__bool__Xs
���}�$�$r;c�H�t|jp
|jp|j��S)zhReturn True if this :class:`.History` has no changes
        and no existing, unchanged state.

        )�boolr�r�r�r?s r9�emptyz
History.empty]s%�����3�t�|�F���G�G�G�Gr;c�<�|jpg|jpgz|jpgzS)z3Return a collection of added + unchanged + deleted.r�r?s r9�sumzHistory.sumes+���Z�
�2�$�.�"6�B�7�4�<�;M�2�N�	
r;c�(�|jpg|jpgzS)z)Return a collection of added + unchanged.)r�r�r?s r9�non_deletedzHistory.non_deletedls���
� �b�T�^�%9�r�:�:r;c�(�|jpg|jpgzS)z+Return a collection of unchanged + deleted.)r�r�r?s r9�	non_addedzHistory.non_addedqs����$�"���);��<�<r;c�8�t|jp|j��S)z2Return True if this :class:`.History` has changes.)r�r�r�r?s r9�has_changeszHistory.has_changesvs���D�J�.�$�,�/�/�/r;c�~�td�|jD��d�|jD��d�|jD����S)Nc�8�g|]}|durt|��pd��Sr=rrns  r9rfz$History.as_state.<locals>.<listcomp>}�>��
�
�
���$��5�N�1�$5�$5�=��
�
�
r;c�8�g|]}|durt|��pd��Sr=rrns  r9rfz$History.as_state.<locals>.<listcomp>�r�r;c�8�g|]}|durt|��pd��Sr=rrns  r9rfz$History.as_state.<locals>.<listcomp>�r�r;)r(r�r�r�r?s r9�as_statezHistory.as_state{sn���
�
���
�
�
�
�
���
�
�
�
�
���
�
�
�

�

�
	
r;c��|j�|jt��}|tur$|tur
|ddd��S|d|gd��S|�||��dur|d|gd��St
|��tvrd}t
|��tvrd}n|g}|tur
|dd|��S||gd|��S)NrIT)r�r�r+�_NO_HISTORYrr�r��_NO_STATE_SYMBOLS�rar�rrr,rBr�s      r9r)zHistory.from_scalar_attribute�s����(�,�,�Y�]�K�H�H���{�"�"��)�#�#��s�2�r�2���&��s�2��y�"�-�-�-�
�
�
���
2�
2�d�
:�
:��3�r�G�9�b�)�)�)��(�|�|�0�0�0����g�;�;�"3�3�3�"�G��#�*���)�#�#��s�2�r�7�+�+�+��s�G�9�b�'�2�2�2r;c��|j�|jt��}|tur-|tus	|t
ur
|ddd��S|d|gd��S||ur|t
ur|d|gd��St
|��tvs|�d}t
|��tvrd}n|g}|tus	|t
ur
|dd|��S||gd|��S)NrI)r�r�r+r�rrr�r�r�s      r9r@zHistory.from_object_attribute�s
���(�,�,�Y�]�K�H�H���{�"�"��(�"�"�g��&:�&:��s�2�r�2���&��s�2��y�"�-�-�-�
��
 �
 �W�I�%=�%=��3�r�G�9�b�)�)�)��(�|�|�0�0�0�H�4D����g�;�;�"3�3�3�"�G��#�*���(�"�"�g��&:�&:��s�2�r�7�+�+�+��s�G�9�b�'�2�2�2r;c����|j�|jt��}|tus	|t
ur
|ddd��St
|d��}|tt
fvr|t|��dd��S|tur|dt|��d��Sd�|D��}d�|D��}t|���t|���|�fd�|D���fd�|D���fd�|D����S)NrIrlc�<�g|]}|durt|��pd|f��Sr=rrns  r9rfz+History.from_collection.<locals>.<listcomp>�sC�������4�-�6�^�A�%6�%6�>�$��B���r;c�<�g|]}|durt|��pd|f��Sr=rrns  r9rfz+History.from_collection.<locals>.<listcomp>�sC�������4�-�6�^�A�%6�%6�>�$��B���r;c�"��g|]\}}|�v�	|��SrIrIrrs   �r9rfz+History.from_collection.<locals>.<listcomp>�s'���G�G�G�t�q�!��,�1F�1F��1F�1F�1Fr;c�"��g|]\}}|�v�	|��SrIrIrrs   �r9rfz+History.from_collection.<locals>.<listcomp>�s'���C�C�C�t�q�!��l�1B�1B��1B�1B�1Br;c�"��g|]\}}|�v�	|��SrIrIrxs   �r9rfz+History.from_collection.<locals>.<listcomp>�s'���G�G�G�t�q�!�!�;�2F�2F��2F�2F�2Fr;)	r�r�r+r�rrrzr�r{)	rar�rrr,rBr|r}ryrus	       @@r9rjzHistory.from_collection�sT�����(�,�,�Y�]�K�H�H���h���'�Y�"6�"6��3�r�2�r�?�?�"��'�=�1�1����)�,�,�,��3�t�G�}�}�b�"�-�-�-�
��
$�
$��3�r�4��=�=�"�-�-�-��� ����N���!����O�
�~�.�.�K���0�0�L��3�G�G�G�G�~�G�G�G�C�C�C�C�~�C�C�C�G�G�G�G��G�G�G���
r;N)r~r�r�r�r��__nonzero__r�r�r�r�r�r��classmethodr)r@rjrIr;r9r(r(?s���������0%�%�%��K�H�H�H�
�
�
�;�;�;�
=�=�=�
0�0�0�

�
�
� �3�3��[�3�<�3�3��[�3�:����[���r;c��|durtjd��t}n|durtjd��t}t	t|��||��S)a
Return a :class:`.History` record for the given object
    and attribute key.

    This is the **pre-flush** history for a given attribute, which is
    reset each time the :class:`.Session` flushes changes to the
    current database transaction.

    .. note::

        Prefer to use the :attr:`.AttributeState.history` and
        :meth:`.AttributeState.load_history` accessors to retrieve the
        :class:`.History` for instance attributes.


    :param obj: an object whose class is instrumented by the
      attributes package.

    :param key: string attribute name.

    :param passive: indicates loading behavior for the attribute
       if the value is not already present.   This is a
       bitflag attribute, which defaults to the symbol
       :attr:`.PASSIVE_OFF` indicating all necessary SQL
       should be emitted.

    .. seealso::

        :attr:`.AttributeState.history`

        :meth:`.AttributeState.load_history` - retrieve history
        using loader callables if the value is not locally present.

    TzNPassing True for 'passive' is deprecated. Use attributes.PASSIVE_NO_INITIALIZEFzFPassing False for 'passive' is deprecated.  Use attributes.PASSIVE_OFF)r%�warn_deprecatedrr�get_state_historyr
)r�r+rGs   r9rErE�sw��D�$�����
3�	
�	
�	
�(���	�E�	�	���
6�	
�	
�	
����^�C�0�0�#�w�?�?�?r;c�.�|�||��Sr=)rE)rrr+rGs   r9r�r�s�����S�'�*�*�*r;Fc�l�t|��}t|��}|�|||��S)�TODO)rr
�
has_parent)rar�r+ror7rrs      r9rr"s4���s�#�#�G��3���E����e�S�*�5�5�5r;c���|�dd��}|�dd��}|�dd��}t|||||���}t||fi|��|S)Nr-r5r�)r�)r�register_descriptor�register_attribute_impl)r*r+rr-r5r��descs       r9�register_attributer)sp������d�+�+�J��6�6�.�$�/�/�L�
�&�&���
�
�C��v�s�J��#�N�N�N�D��F�C�.�.�2�.�.�.��Kr;c���t|��}|r4|�dd��}	|�||	pt��}
n|�dd��}
||j}|r
||||
|fi|��}n8|rt||||fd|
i|��}n#|rt
||||fi|��}nt||||fi|��}|||_|rt||||��|�
|��||S)Nr`)rr�instrument_collection_classr�r1rJr=rr,r��post_configure_attribute)
r*r+r�r��	useobject�
impl_class�backrefrr7�factoryr`r1r,s
             r9rr2sd���v�&�&�G��4��&�&���.�.���:�:����D�
�
����v�v�n�d�3�3���s�|�$�H��K��z�&�#�|�X�D�D��D�D���	�	K�&��C��H�
�
�;G�
�KM�
�
���
�K�(��C��H�
�
�02�
�
���#�6�3�	�8�J�J�r�J�J���G�C�L���:��'�#�,���9�9�9��$�$�S�)�)�)��3�<�r;c��t|��}t||||���}||_|�||��|S)N)r-r5)rr�r��instrument_attribute)r*r+r-r5r�r7r�s       r9rr^sT���v�&�&�G�&���
�����J��J��� � ��j�1�1�1��r;c�J�t|���|��dSr=)r�uninstrument_attribute)r*r+s  r9�unregister_attributerms$���V���3�3�C�8�8�8�8�8r;c�P�t|��}|j}t|||��S)a4Initialize a collection attribute and return the collection adapter.

    This function is used to provide direct access to collection internals
    for a previously unloaded attribute.  e.g.::

        collection_adapter = init_collection(someobject, 'elements')
        for elem in values:
            collection_adapter.append_without_event(elem)

    For an easier way to do the above, see
    :func:`~sqlalchemy.orm.attributes.set_committed_value`.

    :param obj: a mapped object

    :param key: string attribute name where the collection is located.

    )r
r{�init_state_collection)r�r+rrr�s    r9rQrQqs*��$
�3���E��J�E� ���s�3�3�3r;c��|j|j}|�||��}|�|||��S)zDInitialize a collection attribute and return the collection adapter.)r7r,r�r�)rrr�r+r�r�s     r9rr�s>���=���"�D�����u�-�-�I����u�e�Y�7�7�7r;c��t|��t|��}}|j|j�|||��dS)a[Set the value of an attribute with no history events.

    Cancels any previous history present.  The value should be
    a scalar value for scalar-holding attributes, or
    an iterable for any collection-holding attribute.

    This is the same underlying method used when a lazy loader
    fires off and loads additional data from the database.
    In particular, this method can be used by application code
    which has loaded additional attributes or collections through
    separate queries, which can then be attached to an instance
    as though it were part of its original loaded state.

    N)r
rr7r,r)rFr+rZrrr�s     r9rr�sE��"�(�+�+�]�8�-D�-D�5�E�	�M�#���/�/��u�e�D�D�D�D�Dr;c��t|��t|��}}|j|j�||||��dS)asSet the value of an attribute, firing history events.

    This function may be used regardless of instrumentation
    applied directly to the class, i.e. no descriptors are required.
    Custom attribute management schemes will need to make usage
    of this method to establish attribute state as understood
    by SQLAlchemy.

    :param instance: the object that will be modified

    :param key: string name of the attribute

    :param value: value to assign

    :param initiator: an instance of :class:`.Event` that would have
     been propagated from a previous event listener.  This argument
     is used when the :func:`.set_attribute` function is being used within
     an existing event listening function where an :class:`.Event` object
     is being supplied; the object may be used to track the origin of the
     chain of events.

     .. versionadded:: 1.2.3

    N)r
rr7r,r�)rFr+rZrrrr�s      r9�
set_attributer�sG��2"�(�+�+�]�8�-D�-D�5�E�	�M�#������u�e�Y�?�?�?�?�?r;c��t|��t|��}}|j|j�||��S)aZGet the value of an attribute, firing any callables required.

    This function may be used regardless of instrumentation
    applied directly to the class, i.e. no descriptors are required.
    Custom attribute management schemes will need to make usage
    of this method to make usage of attribute state as understood
    by SQLAlchemy.

    )r
rr7r,r��rFr+rrr�s    r9�
get_attributer�s=��"�(�+�+�]�8�-D�-D�5�E��=���"�&�&�u�e�4�4�4r;c��t|��t|��}}|j|j�||��dS)aQDelete the value of an attribute, firing history events.

    This function may be used regardless of instrumentation
    applied directly to the class, i.e. no descriptors are required.
    Custom attribute management schemes will need to make usage
    of this method to establish attribute state as understood
    by SQLAlchemy.

    N)r
rr7r,r�rs    r9�
del_attributer�sC��"�(�+�+�]�8�-D�-D�5�E�	�M�#���"�"�5�%�0�0�0�0�0r;c���t|��t|��}}|j|j}|j�||j��|�||td���dS)a�Mark an attribute on an instance as 'modified'.

    This sets the 'modified' flag on the instance and
    establishes an unconditional change event for the given attribute.
    The attribute must have a value present, else an
    :class:`.InvalidRequestError` is raised.

    To mark an object "dirty" without referring to any specific attribute
    so that it is considered within a flush, use the
    :func:`.attributes.flag_dirty` call.

    .. seealso::

        :func:`.attributes.flag_dirty`

    T��is_userlandN)	r
rr7r,r1�modifiedr�r"r)rFr+rrr�r,s     r9�
flag_modifiedr#�sj��""�(�+�+�]�8�-D�-D�5�E��=���"�D��M���5�$�"6�7�7�7�	���%��x�T��B�B�B�B�Br;c�~�t|��t|��}}|�|dtd���dS)a�Mark an instance as 'dirty' without any specific attribute mentioned.

    This is a special operation that will allow the object to travel through
    the flush process for interception by events such as
    :meth:`.SessionEvents.before_flush`.   Note that no SQL will be emitted in
    the flush process for an object that has no changes, even if marked dirty
    via this method.  However, a :meth:`.SessionEvents.before_flush` handler
    will be able to see the object in the :attr:`.Session.dirty` collection and
    may establish changes on it, which will then be included in the SQL
    emitted.

    .. versionadded:: 1.2

    .. seealso::

        :func:`.attributes.flag_modified`

    NTr )r
rr"r)rFrrr�s   r9�
flag_dirtyr%�s@��("�(�+�+�]�8�-D�-D�5�E�	���%��x�T��B�B�B�B�Br;r�)FNFNNr�r=)Or�r��rrr�rr8rrr	r
rr
rrrrrrrrrrrrrrrrrrr r!r#r$r%�_self_inspects�_MappedAttribute�InspectionAttr�PropComparatorr'r�r��symbolrr\rr]r��objectr�r�rr=rJr�r��	frozensetr�r��
namedtupler(r*rEr�rrrrrrQrrrrrr#r%rIr;r9�<module>r/sA�������������������������������������������������������� � � � � � �������(�(�(�(�(�(�"�"�"�"�"�"�������������������������������#�#�#�#�#�#�(�(�(�(�(�(�"�"�"�"�"�"�*�*�*�*�*�*�'�'�'�'�'�'�#�#�#�#�#�#�������)�)�)�)�)�)�*�*�*�*�*�*�#�#�#�#�#�#���������������������������������T(�T(�T(�T(�T(�������T(�T(���T(�nB�B�B�B�B�.�B�B�B�8}�}�}�@
�D�K��!�!�	��D�K��!�!�	�
�T�[��
#�
#�
��$�+�n�-�-���d�k�*�%�%��/*�/*�/*�/*�/*�F�/*�/*�/*�dD�D�D�D�D�F�D�D�D�N
R&�R&�R&�R&�R&�-�R&�R&�R&�jb�b�b�b�b� 3�b�b�b�JM1�M1�M1�M1�M1�m�M1�M1�M1�`
A�A�A�H�d�k�,�'�'���I��R����B�B�x�L�L�"�"�Y�-�-�8�����$�/�)�%F�%F�%F�
G�
G��g�g�g�g�g�g�g�g�g�T���d�D�)�)�
�#.�/@�/@�/@�/@�d+6�+�+�+�+�6�6�6�6����
�����)�)�)�)�Z:>�����9�9�9�4�4�4�.8�8�8�E�E�E�&@�@�@�@�:5�5�5�1�1�1�C�C�C�.C�C�C�C�Cr;

Hacked By AnonymousFox1.0, Coded By AnonymousFox