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__/session.cpython-311.pyc

�

�܋f����dZddlZddlZddlZddlmZddlmZddlmZddlmZddlm	Z	dd	lm
Z
dd
lmZddl
mZddl
mZdd
l
mZddl
mZddl
mZddl
mZddl
mZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZ gd�Z!ej"��Z#	d�Z$Gd�de%��Z&ej'd��Z(ej'd��Z)ej'd ��Z*ej'd!��Z+ej'd"��Z,Gd#�d$e%��Z-Gd%�d&e&��Z.Gd'�d(e&��Z/d)�Z0d*�Z1d+�Z2d,�Z3ej4��Z5dS)-z1Provides the Session class and related utilities.�N�)�
attributes)�exc)�identity)�loading)�persistence)�query��state)�_class_to_mapper)�	_none_set)�
_state_mapper)�instance_str)�
object_mapper)�object_state)�	state_str)�SessionExtension)�UOWTransaction�)�engine)�sql)�util)�inspect)�
expression)�Session�SessionTransactionr�sessionmakerc�Z�|jr#	t|jS#t$rYnwxYwdS)z\Given an :class:`.InstanceState`, return the :class:`.Session`
    associated, if any.

    N)�
session_id�	_sessions�KeyErrorr
s �M/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/orm/session.py�_state_sessionr#-sG��

���	��U�-�.�.���	�	�	��D�	�����4s��
(�(c��eZdZdZeejdd��d�����Zeejd��d�����Z	ed���Z
dS)	�_SessionClassMethodszBClass-level methods for :class:`.Session`, :class:`.sessionmaker`.z1.3z�The :meth:`.Session.close_all` method is deprecated and will be removed in a future release.  Please refer to :func:`.session.close_all_sessions`.c�"�t��dS)zClose *all* sessions in memory.N)�close_all_sessions)�clss r"�	close_allz_SessionClassMethods.close_all=s��	������zsqlalchemy.orm.utilc��|j|i|��S)zZReturn an identity key.

        This is an alias of :func:`.util.identity_key`.

        )�identity_key)r(�orm_util�args�kwargss    r"r,z!_SessionClassMethods.identity_keyIs��%�x�$�d�5�f�5�5�5r*c� �t|��S)zxReturn the :class:`.Session` to which an object belongs.

        This is an alias of :func:`.object_session`.

        )�object_session)r(�instances  r"r1z#_SessionClassMethods.object_sessionSs���h�'�'�'r*N)�__name__�
__module__�__qualname__�__doc__�classmethodr�
deprecatedr)�dependenciesr,r1�r*r"r%r%:s�������L�L���T�_�
�	/�����
���[��
��T��,�-�-�6�6�.�-��[�6��(�(��[�(�(�(r*r%�ACTIVE�PREPARED�	COMMITTED�DEACTIVE�CLOSEDc���eZdZdZdZdd�Zed���ZdZ	ed���Z					dd�Z
ed	���Zdd
�Zdd�Z
dd�Zd
�Zdd�Zd�Zd�Zd�Zd�Zd�Zdd�Zdd�Zd�Zd�ZdS)ra�A :class:`.Session`-level transaction.

    :class:`.SessionTransaction` is a mostly behind-the-scenes object
    not normally referenced directly by application code.   It coordinates
    among multiple :class:`_engine.Connection` objects, maintaining a database
    transaction for each one individually, committing or rolling them
    back all at once.   It also provides optional two-phase commit behavior
    which can augment this coordination operation.

    The :attr:`.Session.transaction` attribute of :class:`.Session`
    refers to the current :class:`.SessionTransaction` object in use, if any.
    The :attr:`.SessionTransaction.parent` attribute refers to the parent
    :class:`.SessionTransaction` in the stack of :class:`.SessionTransaction`
    objects.  If this attribute is ``None``, then this is the top of the stack.
    If non-``None``, then this :class:`.SessionTransaction` refers either
    to a so-called "subtransaction" or a "nested" transaction.  A
    "subtransaction" is a scoping concept that demarcates an inner portion
    of the outermost "real" transaction.  A nested transaction, which
    is indicated when the :attr:`.SessionTransaction.nested`
    attribute is also True, indicates that this :class:`.SessionTransaction`
    corresponds to a SAVEPOINT.

    **Life Cycle**

    A :class:`.SessionTransaction` is associated with a :class:`.Session` in
    its default mode of ``autocommit=False`` immediately, associated
    with no database connections.  As the :class:`.Session` is called upon
    to emit SQL on behalf of various :class:`_engine.Engine` or
    :class:`_engine.Connection`
    objects, a corresponding :class:`_engine.Connection` and associated
    :class:`.Transaction` is added to a collection within the
    :class:`.SessionTransaction` object, becoming one of the
    connection/transaction pairs maintained by the
    :class:`.SessionTransaction`.  The start of a :class:`.SessionTransaction`
    can be tracked using the :meth:`.SessionEvents.after_transaction_create`
    event.

    The lifespan of the :class:`.SessionTransaction` ends when the
    :meth:`.Session.commit`, :meth:`.Session.rollback` or
    :meth:`.Session.close` methods are called.  At this point, the
    :class:`.SessionTransaction` removes its association with its parent
    :class:`.Session`.   A :class:`.Session` that is in ``autocommit=False``
    mode will create a new :class:`.SessionTransaction` to replace it
    immediately, whereas a :class:`.Session` that's in ``autocommit=True``
    mode will remain without a :class:`.SessionTransaction` until the
    :meth:`.Session.begin` method is called.  The end of a
    :class:`.SessionTransaction` can be tracked using the
    :meth:`.SessionEvents.after_transaction_end` event.

    **Nesting and Subtransactions**

    Another detail of :class:`.SessionTransaction` behavior is that it is
    capable of "nesting".  This means that the :meth:`.Session.begin` method
    can be called while an existing :class:`.SessionTransaction` is already
    present, producing a new :class:`.SessionTransaction` that temporarily
    replaces the parent :class:`.SessionTransaction`.   When a
    :class:`.SessionTransaction` is produced as nested, it assigns itself to
    the :attr:`.Session.transaction` attribute, and it additionally will assign
    the previous :class:`.SessionTransaction` to its :attr:`.Session.parent`
    attribute.  The behavior is effectively a
    stack, where :attr:`.Session.transaction` refers to the current head of
    the stack, and the :attr:`.SessionTransaction.parent` attribute allows
    traversal up the stack until :attr:`.SessionTransaction.parent` is
    ``None``, indicating the top of the stack.

    When the scope of :class:`.SessionTransaction` is ended via
    :meth:`.Session.commit` or :meth:`.Session.rollback`, it restores its
    parent :class:`.SessionTransaction` back onto the
    :attr:`.Session.transaction` attribute.

    The purpose of this stack is to allow nesting of
    :meth:`.Session.rollback` or :meth:`.Session.commit` calls in context
    with various flavors of :meth:`.Session.begin`. This nesting behavior
    applies to when :meth:`.Session.begin_nested` is used to emit a
    SAVEPOINT transaction, and is also used to produce a so-called
    "subtransaction" which allows a block of code to use a
    begin/rollback/commit sequence regardless of whether or not its enclosing
    code block has begun a transaction.  The :meth:`.flush` method, whether
    called explicitly or via autoflush, is the primary consumer of the
    "subtransaction" feature, in that it wishes to guarantee that it works
    within in a transaction block regardless of whether or not the
    :class:`.Session` is in transactional mode when the method is called.

    Note that the flush process that occurs within the "autoflush" feature
    as well as when the :meth:`.Session.flush` method is used **always**
    creates a :class:`.SessionTransaction` object.   This object is normally
    a subtransaction, unless the :class:`.Session` is in autocommit mode
    and no transaction exists at all, in which case it's the outermost
    transaction.   Any event-handling logic or other inspection logic
    needs to take into account whether a :class:`.SessionTransaction`
    is the outermost transaction, a subtransaction, or a "nested" / SAVEPOINT
    transaction.

    .. seealso::

        :meth:`.Session.rollback`

        :meth:`.Session.commit`

        :meth:`.Session.begin`

        :meth:`.Session.begin_nested`

        :attr:`.Session.is_active`

        :meth:`.SessionEvents.after_transaction_create`

        :meth:`.SessionEvents.after_transaction_end`

        :meth:`.SessionEvents.after_commit`

        :meth:`.SessionEvents.after_rollback`

        :meth:`.SessionEvents.after_soft_rollback`

    NFc��||_i|_||_||_t|_|s|rt
jd���|jjr|�	��|jj
�|j|��dS)NzOCan't start a SAVEPOINT transaction when no existing transaction is in progress)�session�_connections�_parent�nestedr;�_state�sa_exc�InvalidRequestError�_enable_transaction_accounting�_take_snapshot�dispatch�after_transaction_create)�selfrB�parentrEs    r"�__init__zSessionTransaction.__init__�s�������������������	�&�	��,�-���
�
�<�6�	"����!�!�!����6�6�t�|�T�J�J�J�J�Jr*c��|jS)ajThe parent :class:`.SessionTransaction` of this
        :class:`.SessionTransaction`.

        If this attribute is ``None``, indicates this
        :class:`.SessionTransaction` is at the top of the stack, and
        corresponds to a real "COMMIT"/"ROLLBACK"
        block.  If non-``None``, then this is either a "subtransaction"
        or a "nested" / SAVEPOINT transaction.  If the
        :attr:`.SessionTransaction.nested` attribute is ``True``, then
        this is a SAVEPOINT, and if ``False``, indicates this a subtransaction.

        .. versionadded:: 1.0.16 - use ._parent for previous versions

        )rD�rMs r"rNzSessionTransaction.parent�s�� �|�r*c�0�|jduo
|jtuS�N)rBrFr;rQs r"�	is_activezSessionTransaction.is_actives���|�4�'�A�D�K�6�,A�Ar*�This transaction is closedc��|jturtjd���|jtur|stjd���dS|jt
urE|s=|s=|jrtjd|jzd����|stjd���dSdSdS|jturtj|���dS)Nz\This session is in 'committed' state; no further SQL can be emitted within this transaction.z[This session is in 'prepared' state; no further SQL can be emitted within this transaction.z�This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: %s�7s2a)�codez�This session is in 'inactive' state, due to the SQL transaction being rolled back; no further SQL can be emitted within this transaction.)	rFr=rGrHr<r>�_rollback_exceptionr?�ResourceClosedError)rM�prepared_ok�rollback_ok�deactive_ok�
closed_msgs     r"�_assert_activez!SessionTransaction._assert_actives,���;�)�#�#��,�>���
��[�H�
$�
$��
��0�B����
�
�
�[�H�
$�
$��
�{�
��+�� �4�6�
�2�3�$�����%�� �4�F����
�
�
�
����[�F�
"�
"��,�Z�8�8�8�#�
"r*c� �|jp|jSrS)rErDrQs r"�_is_transaction_boundaryz+SessionTransaction._is_transaction_boundary3s���{�.�$�,�.�.r*c�|�|���|jj|fi|��}|�||��SrS)r_rB�get_bind�_connection_for_bind)rM�bindkey�execution_optionsr/�binds     r"�
connectionzSessionTransaction.connection7sG��������$�t�|�$�W�7�7��7�7���(�(��/@�A�A�Ar*c�X�|���t|j||���S)N�rE)r_rrB)rMrEs  r"�_beginzSessionTransaction._begin<s+��������!�$�,��V�D�D�D�Dr*c��|}d}|r7||fz
}|j|urn'|j�tjd|z���|j}|�7|S)Nr:z4Transaction %s is not on the active transaction list)rDrGrH)rM�upto�current�results    r"�_iterate_self_and_parentsz,SessionTransaction._iterate_self_and_parents@sr�������
	*��w�j� �F���$�&�&����(��0�J������
"�/���
	*��
r*c��|jsF|jj|_|jj|_|jj|_|jj|_dS|jjs|j���tj
��|_tj
��|_tj
��|_tj
��|_dSrS)rarD�_new�_deleted�_dirty�
_key_switchesrB�	_flushing�flush�weakref�WeakKeyDictionaryrQs r"rJz!SessionTransaction._take_snapshotRs����,�	���)�D�I� �L�1�D�M��,�-�D�K�!%��!;�D���F��|�%�	!��L��� � � ��-�/�/��	��1�3�3��
��/�1�1���$�6�8�8����r*c��|jsJ�t|j���|jj��}|j�|d���|j���D]Q\}\}}|jj�	|��||_
||vr|jj�|���Rt|j���|jj��D]}|j�
|d����|jjrJ�|jj���D]>}|r|js	||jvr*|�|j|jjj���?dS)zmRestore the restoration state taken before a transaction began.

        Corresponds to a rollback.

        T��to_transient)�revert_deletionN)ra�setrr�unionrB�_expunge_statesru�items�identity_map�safe_discard�key�replacers�_update_impl�
all_states�modifiedrt�_expire�dict�	_modified)rM�
dirty_only�
to_expunge�s�oldkey�newkeys      r"�_restore_snapshotz$SessionTransaction._restore_snapshotbs����,�,�,�,����^�^�)�)�$�,�*;�<�<�
���$�$�Z�d�$�C�C�C�#'�#5�#;�#;�#=�#=�
	5�
	5��A����
�L�%�2�2�1�5�5�5��A�E��
�"�"���)�1�1�!�4�4�4���T�]�#�#�)�)�$�,�*?�@�@�	?�	?�A��L�%�%�a��%�>�>�>�>��<�(�(�(�(���*�5�5�7�7�	G�	G�A��
G���
G�q�D�K�/?�/?��	�	�!�&�$�,�";�"E�F�F�F��	G�	Gr*c��|jsJ�|js�|jjr�|jj���D],}|�|j|jjj���-tj
�t|j
��|j��|j
���dS|jr�|jj�|j��|jj�|j��|jj
�|j
��|jj�|j��dSdS)zjRemove the restoration state taken before a transaction began.

        Corresponds to a commit.

        N)rarErB�expire_on_commitr�r�r�r�r��statelib�
InstanceState�_detach_states�listrs�clearrDrr�updatertru)rMr�s  r"�_remove_snapshotz#SessionTransaction._remove_snapshot�s@���,�,�,�,��{�	B�t�|�<�	B��\�.�9�9�;�;�
G�
G���	�	�!�&�$�,�";�"E�F�F�F�F��"�1�1��T�]�#�#�T�\�
�
�
�
�M���!�!�!�!�!�
�[�	B��L��$�$�T�Y�/�/�/��L��&�&�t�{�3�3�3��L�!�(�(���7�7�7��L�&�-�-�d�.@�A�A�A�A�A�		B�	Br*c�(�|���||jvr)|rtjd��|j|dSd}|jr%|j�||��}|js|SnUt|tj	��r%|}|j|jvrtjd���n|���}d}	|r
|j
di|��}|jjr|j�|���}n0|jr|���}n|���}||||ufx|j|<|j|j<|jj�|j||��|S#|r|����xYw)NzOConnection is already established for the given bind; execution_options ignoredrFzMSession already has a Connection associated for the given Connection's EngineTr:)r_rCr�warnrDrdrE�
isinstancer�
ConnectionrGrH�_contextual_connectrfrB�twophase�begin_twophase�begin_nested�beginrK�after_begin�close)rMrgrf�
local_connect�conn�transactions      r"rdz'SessionTransaction._connection_for_bind�s����������4�$�$�$� �
��	�<�����$�T�*�1�-�-��
��<�	%��<�4�4�T�;L�M�M�D��;�
���
��$�� 1�2�2�	
%����;�$�"3�3�3� �4�4����4��/�/�1�1�� $�
�	� �
C�-�t�-�B�B�0A�B�B���|�$�
+���)=�"�1�1�3�3�����
+�"�/�/�1�1���"�j�j�l�l�����D� �H�
�D��d�#�d�&7���&D�

�L�!�-�-�d�l�D�$�G�G�G��K��	��
��
�
�������s
�A'E8�8Fc�|�|j�|jjstjd���|���dS)NzD'twophase' mode not enabled, or not root transaction; can't prepare.)rDrBr�rGrH�
_prepare_implrQs r"�preparezSessionTransaction.prepare�sH���<�#�4�<�+@�#��,�!���
�	
�������r*c�,�|���|j�|jr$|jj�|j��|jj}||ur-|�|���D]}|����|jj	sZtd��D]6}|j���rn.|j����7tjd���|j��|jjr�	t!|j�����D]}|d����nF#t)j��5|���ddd��n#1swxYwYYnxYwt.|_dS)N�rm�dzrOver 100 subsequent flushes have occurred within session.commit() - is an after_flush() hook creating new objects?r)r_rDrErBrK�
before_commitr�rp�commitrv�range�	_is_cleanrwr�
FlushErrorr�r~rC�valuesr�r�safe_reraise�rollbackr<rF)rM�stx�subtransaction�_flush_guard�ts     r"r�z SessionTransaction._prepare_impl�s����������<��4�;���L�!�/�/���=�=�=��l�&���d�?�?�"%�"?�"?�T�"?�"J�"J�
(�
(���%�%�'�'�'�'��|�%�
	� %�c�
�
�	
�	
���<�)�)�+�+���E���"�"�$�$�$�$��n�,�����<��D�L�$9��
$��T�.�5�5�7�7�8�8�#�#�A��a�D�L�L�N�N�N�N�#��
$��&�(�(�$�$��M�M�O�O�O�$�$�$�$�$�$�$�$�$�$�$����$�$�$�$����������s1�>AE�F�E8�,F�8E<	�<F�?E<	�Fc���|�d���|jtur|���|j�|jr�t
|j�����D]}|d�	���t|_|jj�
|j��|jjr|���|���|jS)NT)r[r)r_rFr<r�rDrEr~rCr�r�r=rBrK�after_commitrIr�r�)rMr�s  r"r�zSessionTransaction.commit�s��������-�-�-��;�h�&�&���� � � ��<��4�;����*�1�1�3�3�4�4�
�
���!����
�
�
�
�#�D�K��L�!�.�.�t�|�<�<�<��|�:�
(��%�%�'�'�'��
�
�����|�r*c��|�dd���|jj}||ur-|�|���D]}|����|}d}|jttfv�r4|���D�]}|j�|j	�r	t|j�����D]}|d�
���t|_|jj�|j��n#t#j��}YnxYwt|_|jjr|�|j	���n9#t|_|jjr|�|j	���wwxYw|}nt|_�� |j}|sJ|jrC|���s/t-jd��|�|j	���|���|jr%|r#t#j��d|j_|r"t-j|d|d���|j�||��|jS)	NT)r[r\r�r)r�z\Session's state has been changed on a non-active transaction - this state will be discarded.r��with_traceback)r_rBr�rpr�rFr;r<rDrEr~rCr�r�r>rK�after_rollback�sys�exc_inforIr�r�rr�rY�raise_�after_soft_rollback)	rM�_capture_exceptionr�r��boundary�rollback_errr�r��sesss	         r"r�zSessionTransaction.rollbacks�������$��?�?�?��l�&���d�?�?�"%�"?�"?�T�"?�"J�"J�
'�
'���$�$�&�&�&�&������;�6�8�,�,�,�#�=�=�?�?�
2�
2���&�.�+�2D�.�
�!$�[�%=�%D�%D�%F�%F�!G�!G�,�,�A��a�D�M�M�O�O�O�O�-5��*���-�<�<�T�\�J�J�J�J��6�'*�|�~�~�������-5��*��<�F��'�9�9�+6�+=�:������.6��*��<�F��'�9�9�+6�+=�:��������� +�H��E�)1�K�&�&��|���
	C��3�
	C��N�N�$�$�
	C�
�I�%�
�
�
�

�&�&�(�/�&�B�B�B��
�
�����<�	A�.�	A�/2�|�~�~�a�/@�D�L�,��	I��K��Q���Q��H�H�H�H��
�)�)�$��5�5�5��|�s�A3D
�	E�
D!�E�6Fc���|j|j_|j�nt|j�����D]G\}}}|r|���|r|����3|����Ht|_	|jj
�|j|��|j�%|jjs|j�
��d|_d|_dSrS)rDrBr�r~rCr��
invalidater�r?rFrK�after_transaction_end�
autocommitr�)rMr�rhr��	autocloses     r"r�zSessionTransaction.closeDs���#'�<��� ��<��69��!�(�(�*�*�7�7�
(�
(�2�
�K���,��)�)�+�+�+��(��$�$�&�&�&�&��%�%�'�'�'�'�������3�3�D�L�$�G�G�G��<���<�*�
%���"�"�$�$�$���� ����r*c��|SrSr:rQs r"�	__enter__zSessionTransaction.__enter__Zs���r*c�>�|�dd���|jj�dS|�a	|���dS#t	j��5|���ddd��n#1swxYwYYdSYdSxYw|���dS)NT)r]r[)r_rBr�r�rr�r�)rM�type_�value�	tracebacks    r"�__exit__zSessionTransaction.__exit__]s�������$��?�?�?��<�#�+��F��=�
$����
�
�
�
�
��
$��&�(�(�$�$��M�M�O�O�O�$�$�$�$�$�$�$�$�$�$�$����$�$�$�$�$�$�$�$�$�$����
�M�M�O�O�O�O�Os-�?�B�A5�)B�5A9	�9B�<A9	�=B)NF)FFFrUrS�F)r3r4r5r6rYrO�propertyrNrErTr_rarhrkrprJr�r�rdr�r�r�r�r�r�r�r:r*r"rres�������s�s�j��K�K�K�K�"����X��"�F���B�B��X�B�
���/�%9�%9�%9�%9�N�/�/��X�/�B�B�B�B�
E�E�E�E�����$9�9�9� G�G�G�G�@B�B�B�,3�3�3�j������@���$;�;�;�;�z!�!�!�!�,�������r*rc�$�eZdZdZdZejddd���												dNd
���ZdZdZ		ej
d���ZdOd�Zd
�Z
d�Zd�Zd�Z					dPd�ZdQd�ZdRd�ZdRd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZdSd�Zd�Zeejd�����Z d�Z!			dRd �Z"d!�Z#dQd"�Z$d#�Z%d$�Z&ej'd%d&��d'���Z(d(�Z)dTd)�Z*d*�Z+d+�Z,d,�Z-dUd-�Z.d.�Z/d/�Z0d0�Z1d1�Z2dUd2�Z3			dVd3�Z4d4�Z5d5�Z6dTd6�Z7d7�Z8d8�Z9d9�Z:d:�Z;d;�Z<d<�Z=d=�Z>dQd>�Z?d?�Z@d@�ZAdQdA�ZB			dWdB�ZC	dOdC�ZDdD�ZEdE�ZFejdF�G��dXdH���ZGedI���ZHdZI	edJ���ZJedK���ZKedL���ZLedM���ZMdS)Yrz�Manages persistence operations for ORM-mapped objects.

    The Session's usage paradigm is described at :doc:`/orm/session`.


    )�__contains__�__iter__�add�add_allr�r�r�r�rh�delete�execute�expire�
expire_all�expunge�expunge_allrwrc�is_modified�bulk_save_objects�bulk_insert_mappings�bulk_update_mappings�merger	�refreshr��scalar)z1.0a�The :paramref:`.Session.weak_identity_map` parameter as well as the strong-referencing identity map are deprecated, and will be removed in a future release.  For the use case where objects present in a :class:`.Session` need to be automatically strong referenced, see the recipe at :ref:`session_referencing_behavior` for an event-based approach to maintaining strong identity references. )�0.7zxThe :paramref:`.Session._enable_transaction_accounting` parameter is deprecated and will be removed in a future release.)r�z�:class:`.SessionExtension` is deprecated in favor of the :class:`.SessionEvents` listener interface.  The :paramref:`.Session.extension` parameter will be removed in a future release.)�weak_identity_maprI�	extensionNTFc
���|dvrtj|_ntj|_|���|_i|_i|_||_i|_d|_	d|_
d|_t��|_
||_||_||_|
|_||_||_|r|nt(j|_|r|j�|��|	r,t3j|	��D]}
t7j||
���|�0|���D]\}}|�||���|js|���|t@|j
<dS)a�Construct a new Session.

        See also the :class:`.sessionmaker` function which is used to
        generate a :class:`.Session`-producing callable with a given
        set of arguments.

        :param autocommit:

          .. warning::

             The autocommit flag is **not for general use**, and if it is
             used, queries should only be invoked within the span of a
             :meth:`.Session.begin` / :meth:`.Session.commit` pair.  Executing
             queries outside of a demarcated transaction is a legacy mode
             of usage, and can in some cases lead to concurrent connection
             checkouts.

          Defaults to ``False``. When ``True``, the
          :class:`.Session` does not keep a persistent transaction running,
          and will acquire connections from the engine on an as-needed basis,
          returning them immediately after their use. Flushes will begin and
          commit (or possibly rollback) their own transaction if no
          transaction is present. When using this mode, the
          :meth:`.Session.begin` method is used to explicitly start
          transactions.

          .. seealso::

            :ref:`session_autocommit`

        :param autoflush: When ``True``, all query operations will issue a
           :meth:`~.Session.flush` call to this ``Session`` before proceeding.
           This is a convenience feature so that :meth:`~.Session.flush` need
           not be called repeatedly in order for database queries to retrieve
           results. It's typical that ``autoflush`` is used in conjunction
           with ``autocommit=False``. In this scenario, explicit calls to
           :meth:`~.Session.flush` are rarely needed; you usually only need to
           call :meth:`~.Session.commit` (which flushes) to finalize changes.

        :param bind: An optional :class:`_engine.Engine` or
           :class:`_engine.Connection` to
           which this ``Session`` should be bound. When specified, all SQL
           operations performed by this session will execute via this
           connectable.

        :param binds: A dictionary which may specify any number of
           :class:`_engine.Engine` or :class:`_engine.Connection`
           objects as the source of
           connectivity for SQL operations on a per-entity basis.   The keys
           of the dictionary consist of any series of mapped classes,
           arbitrary Python classes that are bases for mapped classes,
           :class:`_schema.Table` objects and :class:`_orm.Mapper` objects.
           The
           values of the dictionary are then instances of
           :class:`_engine.Engine`
           or less commonly :class:`_engine.Connection` objects.
           Operations which
           proceed relative to a particular mapped class will consult this
           dictionary for the closest matching entity in order to determine
           which :class:`_engine.Engine` should be used for a particular SQL
           operation.    The complete heuristics for resolution are
           described at :meth:`.Session.get_bind`.  Usage looks like::

            Session = sessionmaker(binds={
                SomeMappedClass: create_engine('postgresql://engine1'),
                SomeDeclarativeBase: create_engine('postgresql://engine2'),
                some_mapper: create_engine('postgresql://engine3'),
                some_table: create_engine('postgresql://engine4'),
                })

           .. seealso::

                :ref:`session_partitioning`

                :meth:`.Session.bind_mapper`

                :meth:`.Session.bind_table`

                :meth:`.Session.get_bind`


        :param \class_: Specify an alternate class other than
           ``sqlalchemy.orm.session.Session`` which should be used by the
           returned class. This is the only argument that is local to the
           :class:`.sessionmaker` function, and is not sent directly to the
           constructor for ``Session``.

        :param enable_baked_queries: defaults to ``True``.  A flag consumed
           by the :mod:`sqlalchemy.ext.baked` extension to determine if
           "baked queries" should be cached, as is the normal operation
           of this extension.  When set to ``False``, all caching is disabled,
           including baked queries defined by the calling application as
           well as those used internally.  Setting this flag to ``False``
           can significantly reduce memory use, however will also degrade
           performance for those areas that make use of baked queries
           (such as relationship loaders).   Additionally, baked query
           logic in the calling application or potentially within the ORM
           that may be malfunctioning due to cache key collisions or similar
           can be flagged by observing if this flag resolves the issue.

           .. versionadded:: 1.2

        :param _enable_transaction_accounting:   A
           legacy-only flag which when ``False`` disables *all* 0.5-style
           object accounting on transaction boundaries.

        :param expire_on_commit:  Defaults to ``True``. When ``True``, all
           instances will be fully expired after each :meth:`~.commit`,
           so that all attribute/object access subsequent to a completed
           transaction will load from the most recent database state.

            .. seealso::

                :ref:`session_committing`

        :param extension: An optional
           :class:`~.SessionExtension` instance, or a list
           of such instances, which will receive pre- and post- commit and
           flush events, as well as a post-rollback event.

        :param info: optional dictionary of arbitrary data to be associated
           with this :class:`.Session`.  Is available via the
           :attr:`.Session.info` attribute.  Note the dictionary is copied at
           construction time so that modifications to the per-
           :class:`.Session` dictionary will be local to that
           :class:`.Session`.

           .. versionadded:: 0.9.0

        :param query_cls:  Class which should be used to create new Query
          objects, as returned by the :meth:`~.Session.query` method.
          Defaults to :class:`_query.Query`.

        :param twophase:  When ``True``, all transactions will be started as
            a "two phase" transaction, i.e. using the "two phase" semantics
            of the database in use along with an XID.  During a
            :meth:`~.commit`, after :meth:`~.flush` has been issued for all
            attached databases, the :meth:`~.TwoPhaseTransaction.prepare`
            method on each database's :class:`.TwoPhaseTransaction` will be
            called. This allows each database to roll back the entire
            transaction, before each transaction is committed.

        :param weak_identity_map:  Defaults to ``True`` - when set to
           ``False``, objects placed in the :class:`.Session` will be
           strongly referenced until explicitly removed or the
           :class:`.Session` is closed.


        �TNFN)!r�WeakInstanceDict�
_identity_cls�StrongInstanceDictr�rrrsrg�_Session__bindsrv�_warn_on_eventsr��_new_sessionid�hash_key�	autoflushr�r��enable_baked_queriesrIr�r	�Query�
_query_cls�infor�r�to_listr�_adapt_listenerr��	_add_bindr�r )rMrgr�r�rIr�r�r��bindsr�r�r��	query_cls�extr�s               r"rOzSession.__init__�sr��z��,�,�!)�!:�D���!)�!<�D�� �.�.�0�0�����	���
���	�������$������&�(�(��
�"���$��� 0���$8��!�.L��+� ��
�'0�A�)�)�e�k����	#��I���T�"�"�"��	<��|�I�.�.�
<�
<�� �0��s�;�;�;�;���"�[�[�]�]�
*�
*�	��T����s�D�)�)�)�)���	��J�J�L�L�L�#'�	�$�-� � � r*c��iS)a�A user-modifiable dictionary.

        The initial value of this dictionary can be populated using the
        ``info`` argument to the :class:`.Session` constructor or
        :class:`.sessionmaker` constructor or factory methods.  The dictionary
        here is always local to this :class:`.Session` and can be modified
        independently of all other :class:`.Session` objects.

        .. versionadded:: 0.9.0

        r:rQs r"r�zSession.infoxs	���	r*c��|j�9|s|r!|j�|���|_n*tjd���t	||���|_|jS)a8	Begin a transaction on this :class:`.Session`.

        .. warning::

            The :meth:`.Session.begin` method is part of a larger pattern
            of use with the :class:`.Session` known as **autocommit mode**.
            This is essentially a **legacy mode of use** and is
            not necessary for new applications.    The :class:`.Session`
            normally handles the work of "begin" transparently, which in
            turn relies upon the Python DBAPI to transparently "begin"
            transactions; there is **no need to explicitly begin transactions**
            when using modern :class:`.Session` programming patterns.
            In its default mode of ``autocommit=False``, the
            :class:`.Session` does all of its work within
            the context of a transaction, so as soon as you call
            :meth:`.Session.commit`, the next transaction is implicitly
            started when the next database operation is invoked.  See
            :ref:`session_autocommit` for further background.

        The method will raise an error if this :class:`.Session` is already
        inside of a transaction, unless
        :paramref:`~.Session.begin.subtransactions` or
        :paramref:`~.Session.begin.nested` are specified.  A "subtransaction"
        is essentially a code embedding pattern that does not affect the
        transactional state of the database connection unless a rollback is
        emitted, in which case the whole transaction is rolled back.  For
        documentation on subtransactions, please see
        :ref:`session_subtransactions`.

        :param subtransactions: if True, indicates that this
         :meth:`~.Session.begin` can create a "subtransaction".

        :param nested: if True, begins a SAVEPOINT transaction and is
         equivalent to calling :meth:`~.Session.begin_nested`. For
         documentation on SAVEPOINT transactions, please see
         :ref:`session_begin_nested`.

        :return: the :class:`.SessionTransaction` object.  Note that
         :class:`.SessionTransaction`
         acts as a Python context manager, allowing :meth:`.Session.begin`
         to be used in a "with" block.  See :ref:`session_autocommit` for
         an example.

        .. seealso::

            :ref:`session_autocommit`

            :meth:`.Session.begin_nested`


        NrjzSA transaction is already begun.  Use subtransactions=True to allow subtransactions.)r�rkrGrHr)rM�subtransactionsrEs   r"r�z
Session.begin�sw��h��'��
�&�
�#'�#3�#:�#:�&�#:�#I�#I�� � ��0�E����
 2�$�v�F�F�F�D����r*c�.�|�d���S)a"Begin a "nested" transaction on this Session, e.g. SAVEPOINT.

        The target database(s) and associated drivers must support SQL
        SAVEPOINT for this method to function correctly.

        For documentation on SAVEPOINT
        transactions, please see :ref:`session_begin_nested`.

        :return: the :class:`.SessionTransaction` object.  Note that
         :class:`.SessionTransaction` acts as a context manager, allowing
         :meth:`.Session.begin_nested` to be used in a "with" block.
         See :ref:`session_begin_nested` for a usage example.

        .. seealso::

            :ref:`session_begin_nested`

            :ref:`pysqlite_serializable` - special workarounds required
            with the SQLite driver in order for SAVEPOINT to work
            correctly.

        Trj)r�rQs r"r�zSession.begin_nested�s��.�z�z��z�&�&�&r*c�J�|j�dS|j���dS)a�Rollback the current transaction in progress.

        If no transaction is in progress, this method is a pass-through.

        This method rolls back the current transaction or nested transaction
        regardless of subtransactions being in effect.  All subtransactions up
        to the first real transaction are closed.  Subtransactions occur when
        :meth:`.begin` is called multiple times.

        .. seealso::

            :ref:`session_rollback`

        N)r�r�rQs r"r�zSession.rollback�s-����#��D���%�%�'�'�'�'�'r*c��|j�0|js|���ntjd���|j���dS)a�Flush pending changes and commit the current transaction.

        If no transaction is in progress, this method raises an
        :exc:`~sqlalchemy.exc.InvalidRequestError`.

        By default, the :class:`.Session` also expires all database
        loaded state on all ORM-managed attributes after transaction commit.
        This so that subsequent operations load the most recent
        data from the database.   This behavior can be disabled using
        the ``expire_on_commit=False`` option to :class:`.sessionmaker` or
        the :class:`.Session` constructor.

        If a subtransaction is in effect (which occurs when begin() is called
        multiple times), the subtransaction will be closed, and the next call
        to ``commit()`` will operate on the enclosing transaction.

        When using the :class:`.Session` in its default mode of
        ``autocommit=False``, a new transaction will
        be begun immediately after the commit, but note that the newly begun
        transaction does *not* use any connection resources until the first
        SQL is actually emitted.

        .. seealso::

            :ref:`session_committing`

        N�No transaction is begun.)r�r�r�rGrHr�rQs r"r�zSession.commit�sT��8��#��?�
M��
�
������0�1K�L�L�L�����!�!�!�!�!r*c��|j�0|js|���ntjd���|j���dS)axPrepare the current transaction in progress for two phase commit.

        If no transaction is in progress, this method raises an
        :exc:`~sqlalchemy.exc.InvalidRequestError`.

        Only root transactions of two phase sessions can be prepared. If the
        current transaction is not such, an
        :exc:`~sqlalchemy.exc.InvalidRequestError` is raised.

        Nr)r�r�r�rGrHr�rQs r"r�zSession.preparesT����#��?�
M��
�
������0�1K�L�L�L��� � �"�"�"�"�"r*c�V�|�|j|fd|i|��}|�|||���S)a�
Return a :class:`_engine.Connection` object corresponding to this
        :class:`.Session` object's transactional state.

        If this :class:`.Session` is configured with ``autocommit=False``,
        either the :class:`_engine.Connection` corresponding to the current
        transaction is returned, or if no transaction is in progress, a new
        one is begun and the :class:`_engine.Connection`
        returned (note that no
        transactional state is established with the DBAPI until the first
        SQL statement is emitted).

        Alternatively, if this :class:`.Session` is configured with
        ``autocommit=True``, an ad-hoc :class:`_engine.Connection` is returned
        using :meth:`_engine.Engine.connect` on the underlying
        :class:`_engine.Engine`.

        Ambiguity in multi-bind or unbound :class:`.Session` objects can be
        resolved through any of the optional keyword arguments.   This
        ultimately makes usage of the :meth:`.get_bind` method for resolution.

        :param bind:
          Optional :class:`_engine.Engine` to be used as the bind.  If
          this engine is already involved in an ongoing transaction,
          that connection will be used.  This argument takes precedence
          over ``mapper``, ``clause``.

        :param mapper:
          Optional :func:`.mapper` mapped class, used to identify
          the appropriate bind.  This argument takes precedence over
          ``clause``.

        :param clause:
            A :class:`_expression.ClauseElement` (i.e.
            :func:`_expression.select`,
            :func:`_expression.text`,
            etc.) which will be used to locate a bind, if a bind
            cannot otherwise be identified.

        :param close_with_result: Passed to :meth:`_engine.Engine.connect`,
          indicating the :class:`_engine.Connection` should be considered
          "single use", automatically closing when the first result set is
          closed.  This flag only has an effect if this :class:`.Session` is
          configured with ``autocommit=True`` and does not already have a
          transaction in progress.

        :param execution_options: a dictionary of execution options that will
         be passed to :meth:`_engine.Connection.execution_options`, **when the
         connection is first procured only**.   If the connection is already
         present within the :class:`.Session`, a warning is emitted and
         the arguments are ignored.

         .. versionadded:: 0.9.9

         .. seealso::

            :ref:`session_transaction_isolation`

        :param \**kw:
          Additional keyword arguments are sent to :meth:`get_bind`,
          allowing additional arguments to be passed to custom
          implementations of :meth:`get_bind`.

        N�clause)�close_with_resultrf)rcrd)rM�mapperr	rgr
rf�kws       r"rhzSession.connection+sN��P�<� �4�=��=�=��=�"�=�=�D��(�(��/�/�)�
�
�	
r*c��|j�|j�||��S|jdi|��}|r
|jdi|��}|S)Nr:)r�rdr�rf)rMrrfrr�s     r"rdzSession._connection_for_bind|sm����'��#�8�8��)���
�.�6�-�3�3��3�3�D� �
C�-�t�-�B�B�0A�B�B���Kr*c��tj|d���}|�|j|fd|i|��}|�|d����||pi��S)a�Execute a SQL expression construct or string statement within
        the current transaction.

        Returns a :class:`_engine.ResultProxy` representing
        results of the statement execution, in the same manner as that of an
        :class:`_engine.Engine` or
        :class:`_engine.Connection`.

        E.g.::

            result = session.execute(
                        user_table.select().where(user_table.c.id == 5)
                    )

        :meth:`~.Session.execute` accepts any executable clause construct,
        such as :func:`_expression.select`,
        :func:`_expression.insert`,
        :func:`_expression.update`,
        :func:`_expression.delete`, and
        :func:`_expression.text`.  Plain SQL strings can be passed
        as well, which in the case of :meth:`.Session.execute` only
        will be interpreted the same as if it were passed via a
        :func:`_expression.text` construct.  That is, the following usage::

            result = session.execute(
                        "SELECT * FROM user WHERE id=:param",
                        {"param":5}
                    )

        is equivalent to::

            from sqlalchemy import text
            result = session.execute(
                        text("SELECT * FROM user WHERE id=:param"),
                        {"param":5}
                    )

        The second positional argument to :meth:`.Session.execute` is an
        optional parameter set.  Similar to that of
        :meth:`_engine.Connection.execute`, whether this is passed as a single
        dictionary, or a sequence of dictionaries, determines whether the DBAPI
        cursor's ``execute()`` or ``executemany()`` is used to execute the
        statement.   An INSERT construct may be invoked for a single row::

            result = session.execute(
                users.insert(), {"id": 7, "name": "somename"})

        or for multiple rows::

            result = session.execute(users.insert(), [
                                    {"id": 7, "name": "somename7"},
                                    {"id": 8, "name": "somename8"},
                                    {"id": 9, "name": "somename9"}
                                ])

        The statement is executed within the current transactional context of
        this :class:`.Session`.   The :class:`_engine.Connection`
        which is used
        to execute the statement can also be acquired directly by
        calling the :meth:`.Session.connection` method.  Both methods use
        a rule-based resolution scheme in order to determine the
        :class:`_engine.Connection`,
        which in the average case is derived directly
        from the "bind" of the :class:`.Session` itself, and in other cases
        can be based on the :func:`.mapper`
        and :class:`_schema.Table` objects passed to the method; see the
        documentation for :meth:`.Session.get_bind` for a full description of
        this scheme.

        The :meth:`.Session.execute` method does *not* invoke autoflush.

        The :class:`_engine.ResultProxy` returned by the
        :meth:`.Session.execute`
        method is returned with the "close_with_result" flag set to true;
        the significance of this flag is that if this :class:`.Session` is
        autocommitting and does not have a transaction-dedicated
        :class:`_engine.Connection` available, a temporary
        :class:`_engine.Connection` is
        established for the statement execution, which is closed (meaning,
        returned to the connection pool) when the :class:`_engine.ResultProxy`
        has
        consumed all available data. This applies *only* when the
        :class:`.Session` is configured with autocommit=True and no
        transaction has been started.

        :param clause:
            An executable statement (i.e. an :class:`.Executable` expression
            such as :func:`_expression.select`) or string SQL statement
            to be executed.

        :param params:
            Optional dictionary, or list of dictionaries, containing
            bound parameter values.   If a single dictionary, single-row
            execution occurs; if a list of dictionaries, an
            "executemany" will be invoked.  The keys in each dictionary
            must correspond to parameter names present in the statement.

        :param mapper:
          Optional :func:`.mapper` or mapped class, used to identify
          the appropriate bind.  This argument takes precedence over
          ``clause`` when locating a bind.   See :meth:`.Session.get_bind`
          for more details.

        :param bind:
          Optional :class:`_engine.Engine` to be used as the bind.  If
          this engine is already involved in an ongoing transaction,
          that connection will be used.  This argument takes
          precedence over ``mapper`` and ``clause`` when locating
          a bind.

        :param \**kw:
          Additional keyword arguments are sent to :meth:`.Session.get_bind()`
          to allow extensibility of "bind" schemes.

        .. seealso::

            :ref:`sqlexpression_toplevel` - Tutorial on using Core SQL
            constructs.

            :ref:`connections_toplevel` - Further information on direct
            statement execution.

            :meth:`_engine.Connection.execute`
            - core level statement execution
            method, which is :meth:`.Session.execute` ultimately uses
            in order to execute the statement.

        T)�allow_coercion_to_textNr	)r
)r�_literal_as_textrcrdr��rMr	�paramsrrgrs      r"r�zSession.execute�sz��B�,��4�
�
�
���<� �4�=��=�=��=�"�=�=�D��(�(���(�F�F�N�N��F�L�b�
�
�	
r*c�J�|j|f|||d�|�����S)z:Like :meth:`~.Session.execute` but return a scalar result.)rrrg)r�r�rs      r"r�zSession.scalars?���t�|��
�!�&�t�
�
�?A�
�
�
�&�(�(�	r*c�2�|�d���dS)a>Close this Session.

        This clears all items and ends any transaction in progress.

        If this session were created with ``autocommit=False``, a new
        transaction is immediately begun.  Note that this new transaction does
        not use any connection resources until they are first needed.

        F�r�N��_close_implrQs r"r�z
Session.closes!��	
���E��*�*�*�*�*r*c�2�|�d���dS)aClose this Session, using connection invalidation.

        This is a variant of :meth:`.Session.close` that will additionally
        ensure that the :meth:`_engine.Connection.invalidate`
        method will be called
        on all :class:`_engine.Connection` objects.  This can be called when
        the database is known to be in a state where the connections are
        no longer safe to be used.

        E.g.::

            try:
                sess = Session()
                sess.add(User())
                sess.commit()
            except gevent.Timeout:
                sess.invalidate()
                raise
            except:
                sess.rollback()
                raise

        This clears all items and ends any transaction in progress.

        If this session were created with ``autocommit=False``, a new
        transaction is immediately begun.  Note that this new transaction does
        not use any connection resources until they are first needed.

        .. versionadded:: 0.9.9

        TrNrrQs r"r�zSession.invalidate&s"��@	
���D��)�)�)�)�)r*c��|���|j�1|j���D]}|�|���dSdSrS)r�r�rpr�)rMr�r�s   r"rzSession._close_implHsd����������'�#�/�I�I�K�K�
.�
.���!�!�*�-�-�-�-�(�'�
.�
.r*c���|j���t|j��z}|���|_i|_i|_tj�||��dS)z�Remove all object instances from this ``Session``.

        This is equivalent to calling ``expunge(obj)`` on all objects in this
        ``Session``.

        N)	r�r�r�rrr�rsr�r�r�)rMr�s  r"r�zSession.expunge_allNsf���&�1�1�3�3�d�4�9�o�o�E�
� �.�.�0�0�����	���
���-�-�j�$�?�?�?�?�?r*c��	t|��}|jr||j|<dS|jr%||j|j<|jD]}||j|<�
dSt
jd|z���#tj$r\}t|t��s,tjt
jd|z��|���n||j|<Yd}~dSYd}~dSd}~wwxYw)Nz!Not an acceptable bind target: %s��replace_context)
r�
is_selectabler��	is_mapper�class_�_all_tablesrG�
ArgumentError�NoInspectionAvailabler��typerr�)rMr�rg�insp�
selectable�errs      r"r�zSession._add_bind]sB��	��3�<�<�D��!�	
�%)���T�"�"�"���
�,0���T�[�)�"&�"2�4�4�J�/3�D�L��,�,�4�4��*�7�#�=�����%�+�		)�		)�		)��c�4�(�(�
)����(�;�c�A���%(�	�����%)���S�!�!�!�!�!�!�!�����������		)���s�A'�'C�6AC
�
Cc�2�|�||��dS)a�Associate a :class:`_orm.Mapper` or arbitrary Python class with a
        "bind", e.g. an :class:`_engine.Engine` or
        :class:`_engine.Connection`.

        The given entity is added to a lookup used by the
        :meth:`.Session.get_bind` method.

        :param mapper: a :class:`_orm.Mapper` object,
         or an instance of a mapped
         class, or any Python class that is the base of a set of mapped
         classes.

        :param bind: an :class:`_engine.Engine` or :class:`_engine.Connection`
                    object.

        .. seealso::

            :ref:`session_partitioning`

            :paramref:`.Session.binds`

            :meth:`.Session.bind_table`


        N�r�)rMrrgs   r"�bind_mapperzSession.bind_mappervs��4	
���v�t�$�$�$�$�$r*c�2�|�||��dS)a�Associate a :class:`_schema.Table` with a "bind", e.g. an
        :class:`_engine.Engine`
        or :class:`_engine.Connection`.

        The given :class:`_schema.Table` is added to a lookup used by the
        :meth:`.Session.get_bind` method.

        :param table: a :class:`_schema.Table` object,
         which is typically the target
         of an ORM mapping, or is present within a selectable that is
         mapped.

        :param bind: an :class:`_engine.Engine` or :class:`_engine.Connection`
                    object.

        .. seealso::

            :ref:`session_partitioning`

            :paramref:`.Session.binds`

            :meth:`.Session.bind_mapper`


        Nr))rM�tablergs   r"�
bind_tablezSession.bind_table�s��4	
���u�d�#�#�#�#�#r*c�r�||cxur�%nn"|jr|jStjd���|�l	t|��}n[#tj$rI}t|t��r)tjtj
|��|���n�Yd}~nd}~wwxYw|jre|r0|jj
D]}||jvr|j|cS�|�|j}|�1tj|d���D]}||jvr|j|cS�|jr|jSt|t"jj��r|jr|jS|r|jjr|jjSg}|�|�d|z��|�|�d��tjdd	�|��z���)
alReturn a "bind" to which this :class:`.Session` is bound.

        The "bind" is usually an instance of :class:`_engine.Engine`,
        except in the case where the :class:`.Session` has been
        explicitly bound directly to a :class:`_engine.Connection`.

        For a multiply-bound or unbound :class:`.Session`, the
        ``mapper`` or ``clause`` arguments are used to determine the
        appropriate bind to return.

        Note that the "mapper" argument is usually present
        when :meth:`.Session.get_bind` is called via an ORM
        operation such as a :meth:`.Session.query`, each
        individual INSERT/UPDATE/DELETE operation within a
        :meth:`.Session.flush`, call, etc.

        The order of resolution is:

        1. if mapper given and :paramref:`.Session.binds` is present,
           locate a bind based first on the mapper in use, then
           on the mapped class in use, then on any base classes that are
           present in the ``__mro__`` of the mapped class, from more specific
           superclasses to more general.
        2. if clause given and ``Session.binds`` is present,
           locate a bind based on :class:`_schema.Table` objects
           found in the given clause present in ``Session.binds``.
        3. if ``Session.binds`` is present, return that.
        4. if clause given, attempt to return a bind
           linked to the :class:`_schema.MetaData` ultimately
           associated with the clause.
        5. if mapper given, attempt to return a bind
           linked to the :class:`_schema.MetaData` ultimately
           associated with the :class:`_schema.Table` or other
           selectable to which the mapper is mapped.
        6. No bind can be found, :exc:`~sqlalchemy.exc.UnboundExecutionError`
           is raised.

        Note that the :meth:`.Session.get_bind` method can be overridden on
        a user-defined subclass of :class:`.Session` to provide any kind
        of bind resolution scheme.  See the example at
        :ref:`session_custom_partitioning`.

        :param mapper:
          Optional :func:`.mapper` mapped class or instance of
          :class:`_orm.Mapper`.   The bind can be derived from a
          :class:`_orm.Mapper`
          first by consulting the "binds" map associated with this
          :class:`.Session`, and secondly by consulting the
          :class:`_schema.MetaData`
          associated with the :class:`_schema.Table` to which the
          :class:`_orm.Mapper`
          is mapped for a bind.

        :param clause:
            A :class:`_expression.ClauseElement` (i.e.
            :func:`_expression.select`,
            :func:`_expression.text`,
            etc.).  If the ``mapper`` argument is not present or could not
            produce a bind, the given expression construct will be searched
            for a bound element, typically a :class:`_schema.Table`
            associated with
            bound :class:`_schema.MetaData`.

        .. seealso::

             :ref:`session_partitioning`

             :paramref:`.Session.binds`

             :meth:`.Session.bind_mapper`

             :meth:`.Session.bind_table`

        NzlThis session is not bound to a single Engine or Connection, and no context was provided to locate a binding.rT)�include_crudz	mapper %szSQL expressionz8Could not locate a bind configured on %s or this Session�, )rgrG�UnboundExecutionErrorrr#r�r$rr�r�UnmappedClassErrorr�r �__mro__�persist_selectable�sql_util�find_tablesrr�
ClauseElement�append�join)rMrr	r'r(r��contexts       r"rczSession.get_bind�sP��X�V�#�#�#�#�#�#�#�#��y�
��y� ��2�!������	
� ��������/�
�
�
��f�d�+�+���K��.�v�6�6�(+������
����������
�����<�	/��
7�!�=�0�1�1�C��d�l�*�*�#�|�C�0�0�0�0�+��>�#�6�F��!�!�-�f�4�H�H�H�/�/�A��D�L�(�(�#�|�A��.�.�.�)��9�	��9���f�c�n�:�;�;�	���	��;���	2�f�/�4�	2��,�1�1������N�N�;��/�0�0�0����N�N�+�,�,�,��*�F��y�y��!�!�
#�
�
�	
s�A�B�?B�Bc� �|j||fi|��S)zZReturn a new :class:`_query.Query` object corresponding to this
        :class:`.Session`.)r�)rM�entitiesr/s   r"r	z
Session.query1s ���t��x��8�8��8�8�8r*c#�VK�|j}d|_	|V�||_dS#||_wxYw)agReturn a context manager that disables autoflush.

        e.g.::

            with session.no_autoflush:

                some_object = SomeClass()
                session.add(some_object)
                # won't autoflush
                some_object.related_thing = session.query(SomeRelated).first()

        Operations that proceed within the ``with:`` block
        will not be subject to flushes occurring upon query
        access.  This is useful when initializing a series
        of objects which involve existing database queries,
        where the uncompleted object should not yet be flushed.

        FN)r�)rMr�s  r"�no_autoflushzSession.no_autoflush7sB����*�N�	����	'��J�J�J�&�D�N�N�N��Y�D�N�&�&�&�&s��	(c��|jr}|jsx	|���dS#tj$rM}|�d��t
j|tj	��d���Yd}~dSd}~wwxYwdSdS)Nz�raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurelyrr�)
r�rvrwrG�StatementError�
add_detailrr�r�r�)rM�es  r"�
_autoflushzSession._autoflushSs����>�
	A�$�.�
	A�
A��
�
��������(�

A�

A�

A�
���5����
��A�c�l�n�n�Q�.?�@�@�@�@�@�@�@�@�@�@�����

A����
	A�
	A�
	A�
	As�&�B�AA=�=Bc��	tj|��}nD#tj$r2}t	jtj|��|���Yd}~nd}~wwxYw|�||��|ikrtj	d���|r tj�|��}n0|�.|durtj��}n|rtjdi|��}nd}tj|�
t|����|j|||���	�$tjdt%|��z���dS)a{Expire and refresh the attributes on the given instance.

        A query will be issued to the database and all attributes will be
        refreshed with their current database value.

        Lazy-loaded relational attributes will remain lazily loaded, so that
        the instance-wide refresh operation will be followed immediately by
        the lazy load of that attribute.

        Eagerly-loaded relational attributes will eagerly load within the
        single refresh operation.

        Note that a highly isolated transaction will return the same values as
        were previously read in that same transaction, regardless of changes
        in database state outside of that transaction - usage of
        :meth:`~Session.refresh` usually only makes sense if non-ORM SQL
        statement were emitted in the ongoing transaction, or if autocommit
        mode is turned on.

        :param attribute_names: optional.  An iterable collection of
          string attribute names indicating a subset of attributes to
          be refreshed.

        :param with_for_update: optional boolean ``True`` indicating FOR UPDATE
          should be used, or may be a dictionary containing flags to
          indicate a more specific set of FOR UPDATE flags for the SELECT;
          flags should match the parameters of
          :meth:`_query.Query.with_for_update`.
          Supersedes the :paramref:`.Session.refresh.lockmode` parameter.

          .. versionadded:: 1.2

        :param lockmode: Passed to the :class:`~sqlalchemy.orm.query.Query`
          as used by :meth:`~sqlalchemy.orm.query.Query.with_lockmode`.
          Superseded by :paramref:`.Session.refresh.with_for_update`.

        .. seealso::

            :ref:`session_expire` - introductory material

            :meth:`.Session.expire`

            :meth:`.Session.expire_all`

            :meth:`_orm.Query.populate_existing`

        rNzqwith_for_update should be the boolean value True, or a dictionary with options.  A blank dictionary is ambiguous.T)�
refresh_state�with_for_update�only_load_propszCould not refresh instance '%s'r:)r�instance_stater�NO_STATErr��UnmappedInstanceError�
_expire_staterGr"r	�LockmodeArg�parse_legacy_queryr�
load_on_identrr�rHr)rMr2�attribute_namesrF�lockmoderr's       r"r�zSession.refreshcs���l	��-�h�7�7�E�E���|�	�	�	��K��)�(�3�3� #�
�
�
�
�
�
�
�
�
�����	����	
���5�/�2�2�2��b� � ��&�3���
��	'�#�/�B�B�8�L�L�O�O�
�
(��$�&�&�"'�"3�"5�"5��� �
'�"'�"3�"F�"F�o�"F�"F���"&��
�!��
�
�=��2�2�3�3��	�#� /� /�
�
�
��
��,�1�L��4J�4J�J���
�
�
���A�(A�Ac��|j���D]'}|�|j|jj���(dS)a�Expires all persistent instances within this Session.

        When any attributes on a persistent instance is next accessed,
        a query will be issued using the
        :class:`.Session` object's current transactional context in order to
        load all expired attributes for the given instance.   Note that
        a highly isolated transaction will return the same values as were
        previously read in that same transaction, regardless of changes
        in database state outside of that transaction.

        To expire individual objects and individual attributes
        on those objects, use :meth:`Session.expire`.

        The :class:`.Session` object's default behavior is to
        expire all state whenever the :meth:`Session.rollback`
        or :meth:`Session.commit` methods are called, so that new
        state can be loaded for the new transaction.   For this reason,
        calling :meth:`Session.expire_all` should not be needed when
        autocommit is ``False``, assuming the transaction is isolated.

        .. seealso::

            :ref:`session_expire` - introductory material

            :meth:`.Session.expire`

            :meth:`.Session.refresh`

            :meth:`_orm.Query.populate_existing`

        N)r�r�r�r�r��rMrs  r"r�zSession.expire_all�sP��@�&�1�1�3�3�	C�	C�E��M�M�%�*�d�&7�&A�B�B�B�B�	C�	Cr*c���	tj|��}nD#tj$r2}t	jtj|��|���Yd}~nd}~wwxYw|�||��dS)a�Expire the attributes on an instance.

        Marks the attributes of an instance as out of date. When an expired
        attribute is next accessed, a query will be issued to the
        :class:`.Session` object's current transactional context in order to
        load all expired attributes for the given instance.   Note that
        a highly isolated transaction will return the same values as were
        previously read in that same transaction, regardless of changes
        in database state outside of that transaction.

        To expire all objects in the :class:`.Session` simultaneously,
        use :meth:`Session.expire_all`.

        The :class:`.Session` object's default behavior is to
        expire all state whenever the :meth:`Session.rollback`
        or :meth:`Session.commit` methods are called, so that new
        state can be loaded for the new transaction.   For this reason,
        calling :meth:`Session.expire` only makes sense for the specific
        case that a non-ORM SQL statement was emitted in the current
        transaction.

        :param instance: The instance to be refreshed.
        :param attribute_names: optional list of string attribute names
          indicating a subset of attributes to be expired.

        .. seealso::

            :ref:`session_expire` - introductory material

            :meth:`.Session.expire`

            :meth:`.Session.refresh`

            :meth:`_orm.Query.populate_existing`

        rN)rrHrrIrr�rJrK)rMr2rOrr's     r"r�zSession.expire�s���J	��-�h�7�7�E�E���|�	�	�	��K��)�(�3�3� #�
�
�
�
�
�
�
�
�
�����	����
	
���5�/�2�2�2�2�2rQc�0�|�|��|r|�|j|��dSt|jj�d|����}|�|��|D]\}}}}|�|���dS)Nzrefresh-expire)�_validate_persistent�_expire_attributesr�r��managerr�cascade_iterator�_conditional_expire)rMrrO�cascaded�o�m�st_�dct_s        r"rKzSession._expire_states����!�!�%�(�(�(��
	.��$�$�U�Z��A�A�A�A�A���
�$�5�5�6F��N�N���H�
�$�$�U�+�+�+�#+�
.�
.���1�c�4��(�(��-�-�-�-�
.�
.r*c���|jr'|�|j|jj��dS||jvr1|j�|��|�|��dSdS)z5Expire a state if persistent, else expunge if pendingN)r�r�r�r�r�rr�pop�_detachrSs  r"rZzSession._conditional_expire!sq���9�	 ��M�M�%�*�d�&7�&A�B�B�B�B�B�
�d�i�
�
��I�M�M�%� � � ��M�M�$������ �
r*r�z�The :meth:`.Session.prune` method is deprecated along with :paramref:`.Session.weak_identity_map`.  This method will be removed in a future release.c�4�|j���S)a�Remove unreferenced instances cached in the identity map.

        Note that this method is only meaningful if "weak_identity_map" is set
        to False.  The default weak identity map is self-pruning.

        Removes any object in this Session's identity map that is not
        referenced in user code, modified, new or scheduled for deletion.
        Returns the number of objects pruned.

        )r��prunerQs r"rdz
Session.prune*s��"� �&�&�(�(�(r*c��	tj|��}nD#tj$r2}t	jtj|��|���Yd}~nd}~wwxYw|j|jur$tj
dt|��z���t|j
j�d|����}|�|gd�|D��z��dS)z�Remove the `instance` from this ``Session``.

        This will free all internal references to the instance.  Cascading
        will be applied according to the *expunge* cascade rule.

        rNz*Instance %s is not present in this Sessionr�c��g|]	\}}}}|��
Sr:r:)�.0r\r]r^r_s     r"�
<listcomp>z#Session.expunge.<locals>.<listcomp>Ss ��'L�'L�'L���1�c�4��'L�'L�'Lr*)rrHrrIrr�rJrr�rGrHrr�rXrrYr�)rMr2rr'r[s     r"r�zSession.expunge=s��	��-�h�7�7�E�E���|�	�	�	��K��)�(�3�3� #�
�
�
�
�
�
�
�
�
�����	����
��4�=�0�0��,�<�y��?O�?O�O���
���M� �1�1�)�U�C�C�
�
��	
���e�W�'L�'L�8�'L�'L�'L�L�M�M�M�M�MrQc��|D]�}||jvr|j�|���&|j�|��r6|j�|��|j�|d���v|jr |jj�|d����tj�	|||���dS)Nr{)
rrrar��contains_stater�rsr�r�r�r�)rM�statesr|rs    r"r�zSession._expunge_statesUs����		;�		;�E���	�!�!��	�
�
�e�$�$�$�$��"�1�1�%�8�8�
;��!�.�.�u�5�5�5��
�!�!�%��.�.�.�.��!�
;�� �)�-�-�e�T�:�:�:����-�-��D�|�	.�	
�	
�	
�	
�	
r*c��|jjpd}|D�]}t|��}|���}|��V|�|��}tj|d��r|jrtj|d��r$tj
dt|��z���|j�||_nk|j|kr`|j
�|��||jjvr|jj|d}n|j}||f|jj|<||_|j
�|��}|�E|�|��|kr,|����t%jd|�d���d|_���t*j�d�|D��|j
��|�|��|�)|�|j��D]}|||���t5|���|j��D]}|j�|���dS)	z�Register all persistent objects from a flush.

        This is used both for pending objects moving to the persistent
        state as well as already persistent objects.

        NraOInstance %s has a NULL identity key.  If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the mapped Column object is configured to expect these generated values.  Ensure also that this flush() is not occurring at an inappropriate time, such as within a load() event.rz)Identity map already had an identity for z|, replacing it with newly flushed object.   Are there load operations occurring inside of an event handler within the flush?Fc3�(K�|]
}||jfV��dSrS�r��rgrs  r"�	<genexpr>z/Session._register_persistent.<locals>.<genexpr>�s)����5�5�U�e�U�Z�
 �5�5�5�5�5�5r*)rK�pending_to_persistentr�obj�_identity_key_from_stater
�intersection�allow_partial_pks�
issupersetrr�rr�r�r�r�rur�rr��_orphaned_outside_of_sessionr�r��_commit_all_states�_register_alteredrrr~ra)	rMrkrqrrrr�instance_key�orig_key�olds	         r"�_register_persistentzSession._register_persistentds���!%�
� C� K�t���9	;�9	;�E�"�5�)�)�F��)�)�+�+�C���%�>�>�u�E�E���*�<��?�;�;��"�4��!�+�L��O�<�<��
�.�?�$�E�*�*�+�	�	�	��9�$� ,�E�I�I��Y�,�.�.��%�2�2�5�9�9�9��� 0� >�>�>�#'�#3�#A�%�#H��#K���#(�9�� �$�=�D�$�2�5�9�!-�E�I�
�'�/�/��6�6���O��7�7��<�<��L�L����	�	�-��I�I�0<�|�|�>����6;��2����1�1�5�5�f�5�5�5�t�7H�	
�	
�	
�	
���v�&�&�&� �,��,�,�T�Y�7�7�
3�
3��%�%�d�E�2�2�2�2���[�[�-�-�d�i�8�8�	!�	!�E��I�M�M�%� � � � �	!�	!r*c��|jr4|jr/|D].}||jvrd|jj|<�d|jj|<�+dSdSdS�NT)rIr�rrrt)rMrkrs   r"ryzSession._register_altered�sw���.�	:�4�3C�	:��
:�
:���D�I�%�%�37�D�$�)�%�0�0�59�D�$�+�E�2�2�	:�	:�	:�	:�
:�
:r*c�&�|jjpd}|D]}|jr|jrd|jj|<|�|���}|j�|��|j�|d��d|_|�|||����dSr)	rK�persistent_to_deletedrIr�rsrrr�r�ra)rMrkr�rrrs     r"�_remove_newly_deletedzSession._remove_newly_deleted�s��� $�
� C� K�t���	3�	3�E��2�
8�t�7G�
8�37�� �)�%�0�$�0��i�i�k�k����*�*�5�1�1�1��M���e�T�*�*�*�!�E�N�%�0�%�%�d�E�2�2�2��!	3�	3r*c� �|r|jr|�d��	tj|��}nD#tj$r2}t
jt	j|��|���Yd}~nd}~wwxYw|�	|��dS)z�Place an object in the ``Session``.

        Its state will be persisted to the database on the next flush
        operation.

        Repeated calls to ``add()`` will be ignored. The opposite of ``add()``
        is ``expunge()``.

        z
Session.add()rN)
r��_flush_warningrrHrrIrr�rJ�_save_or_update_state)rMr2�_warnrr's     r"r�zSession.add�s����	1�T�)�	1�����0�0�0�	��-�h�7�7�E�E���|�	�	�	��K��)�(�3�3� #�
�
�
�
�
�
�
�
�
�����	����	
�"�"�5�)�)�)�)�)s�5�A6�(A1�1A6c�v�|jr|�d��|D]}|�|d����dS)z:Add the given collection of instances to this ``Session``.zSession.add_all()F)r�N)r�r�r�)rM�	instancesr2s   r"r�zSession.add_all�sV����	5���� 3�4�4�4�!�	,�	,�H��H�H�X�U�H�+�+�+�+�	,�	,r*c���d|_|�|��t|��}|�d||j���D]\}}}}|�|���dS)NFzsave-update)�halt_on)rw�_save_or_update_implrrY�_contains_state)rMrrr\r]r^r_s       r"r�zSession._save_or_update_state�s���-2��*��!�!�%�(�(�(��u�%�%��%�6�6��5�$�*>� 7� 
� 
�	+�	+�O�A�q�#�t�
�%�%�c�*�*�*�*�	+�	+r*c�"�|jr|�d��	tj|��}nD#tj$r2}t
jt	j|��|���Yd}~nd}~wwxYw|�	||d���dS)zfMark an instance as deleted.

        The database delete operation occurs upon ``flush()``.

        zSession.delete()rNT)�head)
r�r�rrHrrIrr�rJ�_delete_impl�rMr2rr's    r"r�zSession.delete�s�����	4���� 2�3�3�3�	��-�h�7�7�E�E���|�	�	�	��K��)�(�3�3� #�
�
�
�
�
�
�
�
�
�����	����	
���%����5�5�5�5�5s�3�A4�(A/�/A4c���|j�(|r$tjdt|��z���dS|�||��}||jvrdS|j�|��|r|�||��|r-t|j
j�d|����}||j|<|r!|D] \}}}}	|�
||d���dSdS)N�Instance '%s' is not persistedr�F)r�rGrHr�_before_attachrsr�r��
_after_attachr�rXrrYr�)
rMrrrr��	to_attach�cascade_statesr\r]r^r_s
          r"r�zSession._delete_impls'���9���
��0�4�y��7G�7G�G�������'�'��s�3�3�	��D�M�!�!��F�����e�$�$�$��	+����u�c�*�*�*��	�"��
�$�5�5�h��F�F���N� #��
�e���	1�#1�
1�
1���1�c�4��!�!�#�q�%�0�0�0�0�	1�	1�
1�
1r*c�L�|jr|�d��i}i}|r|���t|��|j}	d|_|�t
j|��t
j|��|||���||_S#||_wxYw)a�
Copy the state of a given instance into a corresponding instance
        within this :class:`.Session`.

        :meth:`.Session.merge` examines the primary key attributes of the
        source instance, and attempts to reconcile it with an instance of the
        same primary key in the session.   If not found locally, it attempts
        to load the object from the database based on primary key, and if
        none can be located, creates a new instance.  The state of each
        attribute on the source instance is then copied to the target
        instance.  The resulting target instance is then returned by the
        method; the original source instance is left unmodified, and
        un-associated with the :class:`.Session` if not already.

        This operation cascades to associated instances if the association is
        mapped with ``cascade="merge"``.

        See :ref:`unitofwork_merging` for a detailed discussion of merging.

        .. versionchanged:: 1.1 - :meth:`.Session.merge` will now reconcile
           pending objects with overlapping primary keys in the same way
           as persistent.  See :ref:`change_3601` for discussion.

        :param instance: Instance to be merged.
        :param load: Boolean, when False, :meth:`.merge` switches into
         a "high performance" mode which causes it to forego emitting history
         events as well as all database access.  This flag is used for
         cases such as transferring graphs of objects into a :class:`.Session`
         from a second level cache, or to transfer just-loaded objects
         into the :class:`.Session` owned by a worker thread or process
         without re-querying the database.

         The ``load=False`` use case adds the caveat that the given
         object has to be in a "clean" state, that is, has no pending changes
         to be flushed - even if the incoming object is detached from any
         :class:`.Session`.   This is so that when
         the merge operation populates local attributes and
         cascades to related objects and
         collections, the values can be "stamped" onto the
         target object as is, without generating any history or attribute
         events, and without the need to reconcile the incoming data with
         any existing related objects or collections that might not
         be loaded.  The resulting objects from ``load=False`` are always
         produced as "clean", so it is only appropriate that the given objects
         should be "clean" as well, else this suggests a mis-use of the
         method.


        .. seealso::

            :func:`.make_transient_to_detached` - provides for an alternative
            means of "merging" a single object into the :class:`.Session`

        zSession.merge()F)�load�
_recursive�_resolve_conflict_map)	r�r�rCrr��_mergerrH�
instance_dict)rMr2r�r�r�r�s      r"r�z
Session.merge1s���n��	3���� 1�2�2�2��
� "���	��O�O�����h�����N�	�
	'�"�D�N��;�;��)�(�3�3��(��2�2��%�&;����'�D�N�N��Y�D�N�&�&�&�&s
�AB�	B#c���t|��}||vr||Sd}|j}|��||jvr$tjdt|��z��|st
jd���|�|��}tj
|dvo<tj|d��p!|j
otj|d��}	nd}	||jvr!	|j|}
n#t $rd}
YnwxYwd}
|
��|	r
||vr	||}
n�|sg|jrt
jd���|j���}
tj|
��}||_|�|��d}n5|	r3|�|j���|d��}
|
�Y|j���}
tj|
��}tj|
��}d}|�|��n(tj|
��}tj|
��}|
||<|
||<||ur�|j��|�|||jtj���}
|�|||jtj���}|
tjur?|tjur1|
|kr+t?j d|
�d	t|���d
|�d����|j!|_!|j"|_"|�#|��|j$D]}|�%||||||||���|s|�&||j��|r |j'j(�)|d��|
S)NFzrInstance %s is already pending in this Session yet is being merged again; this is probably not what you want to doz�merge() with load=False option does not support objects transient (i.e. unpersisted) objects.  flush() all changes on mapped instances before merging with load=False.rTz�merge() with load=False option does not support objects marked as 'dirty'.  flush() all changes on mapped instances before merging with load=False.��passivezVersion id 'z' on merged state z" does not match existing version 'zT'. Leave the version attribute unset when merging to update the most recent version.)*rr�rrrr�rrGrHrsr�	NEVER_SETr
rtrurvr�r!r��
class_manager�new_instancerHr�r	r �getr�r��version_id_col�_get_state_attr_by_column�PASSIVE_NO_INITIALIZE�PASSIVE_NO_RESULTr�StaleDataError�	load_path�load_options�_copy_callables�iterate_propertiesr��_commit_allrXrKr�)rMr�
state_dictr�r�r�rr�r��key_is_persistent�merged�merged_state�merged_dict�existing_version�merged_version�props                r"r�zSession._merge�s?���u�%�%���J����e�$�$����i���;���	�!�!��	��'��.�.�/�����
��0�"�����1�1�%�8�8�C� *� 4�C��F� B�!��*�3�q�6�2�2�2���,�9�%�0��Q��8�8�8�	
��!%���$�#�#�#�
��*�3�/�����
�
�
�����
�����F��>� �
?�S�,A�%A�%A�.�s�3����
?��>�� �4�K����
 �-�:�:�<�<��)�8��@�@��#&�� ��!�!�,�/�/�/�#���"�
?����F�M�2�2�6�6�s�1�v�>�>���>��)�6�6�8�8�F�%�4�V�<�<�L�$�2�6�:�:�K��L��&�&�|�4�4�4�4�%�4�V�<�<�L�$�2�6�:�:�K�"�
�5��%+��c�"���$�$��$�0�#)�#C�#C����)�&�<�	$D�$�$� �"(�!A�!A� ���)�&�<�	"B�"�"��%�J�,H�H�H�&�j�.J�J�J�(�N�:�:��,�,�-�,�,�%�l�3�3�3�3�*�N�N��
�
�
�&+�_�L�"�(-�(:�L�%�
�(�(��/�/�/��1�

�

���
�
���� ����)�	�	�	�	��	E��$�$�[�$�2C�D�D�D��	C�� �)�.�.�|�T�B�B�B��
s�
C+�+C:�9C:c��|j�|��s$tjdt	|��z���dS)Nz3Instance '%s' is not persistent within this Session)r�rjrGrHrrSs  r"rVzSession._validate_persistent	sM��� �/�/��6�6�	��,�E��E�"�"�#���
�	�	r*c�<�|j�$tjdt|��z���|���}|�||��}||jvr#||j|<t|j��|_|r|�	||��dSdS)NzGObject '%s' already has an identity - it can't be registered as pending)
r�rGrHrrrr�rr�len�insert_orderr�)rMrrrr�s    r"�
_save_implzSession._save_impl	s����9� ��,�4�6?��6F�6F�G���
�
�i�i�k�k���'�'��s�3�3�	���	�!�!�"�D�I�e��!$�T�Y���E���	+����u�c�*�*�*�*�*�	+�	+r*c�@�|j�$tjdt|��z���|jr2|r|jsdS|`n$tjdt|��z���|���}|�dS|�||��}|j�|d��|r|j	�
|��n|j	�|��|r|�||��dS|r|j
�||��dSdS)Nr�zsInstance '%s' has been deleted.  Use the make_transient() function to send this object back to the transient state.)r�rGrHrrs�	_attachedrrr�rar�r�r�r�rK�deleted_to_persistent)rMrr}rrr�s     r"r�zSession._update_impl+	s[���9���,�0�9�U�3C�3C�C���
��>�	��

�����F��N�N��0�.�1:�%�0@�0@�A�����i�i�k�k���;��F��'�'��s�3�3�	��
���%��&�&�&��	)���%�%�e�,�,�,�,���!�!�%�(�(�(��	=����u�c�*�*�*�*�*�
�	=��M�/�/��e�<�<�<�<�<�	=�	=r*c�l�|j�|�|��dS|�|��dSrS)r�r�r�rSs  r"r�zSession._save_or_update_implQ	s<���9���O�O�E�"�"�"�"�"����e�$�$�$�$�$r*c��tj|��}|�||��}d|_|r|�||��dSdS)a
Associate an object with this :class:`.Session` for related
        object loading.

        .. warning::

            :meth:`.enable_relationship_loading` exists to serve special
            use cases and is not recommended for general use.

        Accesses of attributes mapped with :func:`_orm.relationship`
        will attempt to load a value from the database using this
        :class:`.Session` as the source of connectivity.  The values
        will be loaded based on foreign key and primary key values
        present on this object - if not present, then those relationships
        will be unavailable.

        The object will be attached to this session, but will
        **not** participate in any persistence operations; its state
        for almost all purposes will remain either "transient" or
        "detached", except for the case of relationship loading.

        Also note that backrefs will often not work as expected.
        Altering a relationship-bound attribute on the target object
        may not fire off a backref event, if the effective value
        is what was already loaded from a foreign-key-holding value.

        The :meth:`.Session.enable_relationship_loading` method is
        similar to the ``load_on_pending`` flag on :func:`_orm.relationship`.
        Unlike that flag, :meth:`.Session.enable_relationship_loading` allows
        an object to remain transient while still being able to load
        related items.

        To make a transient object associated with a :class:`.Session`
        via :meth:`.Session.enable_relationship_loading` pending, add
        it to the :class:`.Session` using :meth:`.Session.add` normally.
        If the object instead represents an existing identity in the database,
        it should be merged using :meth:`.Session.merge`.

        :meth:`.Session.enable_relationship_loading` does not improve
        behavior when the ORM is used normally - object references should be
        constructed at the object level, not at the foreign key level, so
        that they are present in an ordinary way before flush()
        proceeds.  This method is not intended for general use.

        .. seealso::

            :paramref:`_orm.relationship.load_on_pending` - this flag
            allows per-relationship loading of many-to-ones on items that
            are pending.

            :func:`.make_transient_to_detached` - allows for an object to
            be added to a :class:`.Session` without SQL emitted, which then
            will unexpire attributes on access.

        TN)rrHr��
_load_pendingr�)rMrrrr�s    r"�enable_relationship_loadingz#Session.enable_relationship_loadingW	s`��n�)�#�.�.���'�'��s�3�3�	�"����	+����u�c�*�*�*�*�*�	+�	+r*c	���|j|jkrdS|jrC|jtvr5tjdt|���d|j�d|j�d����|j�||��dS)NFzObject 'z"' is already attached to session 'z' (this is 'z')T)rr�r rGrHrrK�
before_attach�rMrrrs   r"r�zSession._before_attach�	s�����t�}�,�,��5���	�� 0�I� =� =��,�,��U�#�#�#�#�U�%5�%5�%5�t�}�}�}�F���
�	
�
�#�#�D�%�0�0�0��tr*c��|j|_|jr|j�||_|j�||��|jr|j�||��dS|j�||��dSrS)	r�rr��_strong_objrK�after_attachr��detached_to_persistent�transient_to_pendingr�s   r"r�zSession._after_attach�	s����=����>�	$�e�/�7� #�E���
�"�"�4��/�/�/��9�	<��M�0�0��u�=�=�=�=�=��M�.�.�t�U�;�;�;�;�;r*c���	tj|��}nD#tj$r2}t	jtj|��|���Yd}~nd}~wwxYw|�|��S)z�Return True if the instance is associated with this session.

        The instance may be pending or persistent within the Session for a
        result of True.

        rN)rrHrrIrr�rJr�r�s    r"r�zSession.__contains__�	s���	��-�h�7�7�E�E���|�	�	�	��K��)�(�3�3� #�
�
�
�
�
�
�
�
�
�����	����
�#�#�E�*�*�*rQc��tt|j�����t|j�����z��S)zWIterate over all pending or persistent instances within this
        Session.

        )�iterr�rrr�r�rQs r"r�zSession.__iter__�	sK��
����!�!�#�#�$�$�t�D�,=�,D�,D�,F�,F�'G�'G�G�
�
�	
r*c�H�||jvp|j�|��SrS)rrr�rjrSs  r"r�zSession._contains_state�	s%����	�!�L�T�%6�%E�%E�e�%L�%L�Lr*c���|jrtjd���|���rdS	d|_|�|��d|_dS#d|_wxYw)a�Flush all the object changes to the database.

        Writes out all pending object creations, deletions and modifications
        to the database as INSERTs, DELETEs, UPDATEs, etc.  Operations are
        automatically ordered by the Session's unit of work dependency
        solver.

        Database operations will be issued in the current transactional
        context and do not affect the state of the transaction, unless an
        error occurs, in which case the entire transaction is rolled back.
        You may flush() as often as you like within a transaction to move
        changes from Python to the database's transaction buffer.

        For ``autocommit`` Sessions with no active manual transaction, flush()
        will create a transaction on the fly that surrounds the entire set of
        operations into the flush.

        :param objects: Optional; restricts the flush operation to operate
          only on elements that are in the given collection.

          This feature is for an extremely narrow set of use cases where
          particular objects may need to be operated upon before the
          full flush() occurs.  It is not intended for general use.

        zSession is already flushingNTF)rvrGrHr��_flush)rM�objectss  r"rwz
Session.flush�	st��6�>�	L��,�-J�K�K�K��>�>���	��F�	#�!�D�N��K�K�� � � �"�D�N�N�N��U�D�N�"�"�"�"s�A�	A!c�4�tjd|z��dS)Nz�Usage of the '%s' operation is not currently supported within the execution stage of the flush process. Results may not be consistent.  Consider using alternative event listeners or connection-level operations instead.)rr�)rM�methods  r"r�zSession._flush_warning�	s3���	�
F�IO�
O�	
�	
�	
�	
�	
r*c�V�|j���o|jo|jSrS)r��check_modifiedrsrrrQs r"r�zSession._is_clean�	s5���!�0�0�2�2�2�
��M�!�
��I�
�	
r*c�N�|j}|s.|js'|js |jj���dSt
|��}|jjr#|j�|||��|j}t|j��}t|j��}t|���
|��}|r�t��}|D]q}	tj|��}nD#tj$r2}	tjtj|��|	���Yd}	~	nd}	~	wwxYw|�|���rnd}t��}
|r<|�|���|���
|��}n(|�|���
|��}|D]�}t+|���|��}|o|j}
|r |
s|jr|�|g���O|�||
���}|s
Jd���|
�|����|r)|�|���
|
��}n|�
|
��}|D]%}|�|d���}|s
Jd����&|jsdS|�d���x|_}	d|_	|���d|_n#d|_wxYw|j� ||��|�!��|sv|jjrjtE|jj��}tFj$�%d�|jjD��|j���tj&d	|z��|j�'||��|�(��dS#tj)��5|�*d�
��ddd��YdS#1swxYwYYdSxYw)Nr)�isdeletez*Failed to add object to the flush context!T�rFc� �g|]}||jf��Sr:rnros  r"rhz"Session._flush.<locals>.<listcomp>^
s/�����!���
�+���r*)r�z�Attribute history events accumulated on %d previously clean instances within inner-flush event handlers have been reset, and will not result in database updates. Consider using set_committed_value() within inner-flush event handlers to avoid this warning.�r�)+�
_dirty_statesrsrrr�r�r�rrK�before_flushr~�
differencerrHrrIrr�rJr�rrtr�
_is_orphan�has_identityrwr��register_object�has_workr�r�r�r��after_flush�finalize_flush_changesr�r�r�rxr��after_flush_postexecr�r�r�)rMr��dirty�
flush_context�deleted�new�objsetr\rr'�	processed�proc�	is_orphan�is_persistent_orphan�_regr��len_s                 r"r�zSession._flush�	s ���"���	�T�]�	�4�9�	���'�-�-�/�/�/��F�&�t�,�,�
��=�%�	'��M�&�&�t�]�G�D�D�D��&�E��d�m�$�$���$�)�n�n���E�
�
�%�%�g�.�.���	��U�U�F��	
"�	
"���&�5�a�8�8�E�E���|�����K��1�!�4�4�(+������������������
�
�
�5�!�!�!�!�	
"��F��E�E�	��	8��9�9�U�#�#�0�0��8�8�C�C�G�L�L�D�D��9�9�U�#�#�.�.�w�7�7�D��	%�	%�E�%�e�,�,�7�7��>�>�I�#,�#C��1C� ��
%�,�
%��6�
%�
�$�$�e�W�-�-�-�-�$�4�4��$8�5�����I�I�I�I�I�t��
�
�e�$�$�$�$��	1��'�'��/�/�:�:�9�E�E�D�D��%�%�i�0�0�D��	F�	F�E� �0�0���0�F�F�D��E�E�E�E�E�4�E��%�	��F�26�*�*� �3=�3
�3
�	
�
�!�K�+	>�#'�D� �
-��%�%�'�'�'�',��$�$��u��$�,�,�,�,��M�%�%�d�M�:�:�:��0�0�2�2�2��
�t�0�:�
��4�,�6�7�7���&�9�9���%)�%6�%@����#'�"3�:�����	�H�
KO�O���� 
�M�.�.�t�]�C�C�C���� � � � � ��	>��"�$�$�
>�
>��$�$��$�=�=�=�
>�
>�
>�
>�
>�
>�
>�
>�
>�
>�
>�
>�
>����
>�
>�
>�
>�
>�
>�
>���sa�C*�*D+�9(D&�&D+�O�K8�0O�8	L�CO�P$�1P�P$�P	�P$�P	�P$c
��d�}d�|D��}|st||���}tj||��D]#\\}}}	|�||	|d||d���$dS)a�Perform a bulk save of the given list of objects.

        The bulk save feature allows mapped objects to be used as the
        source of simple INSERT and UPDATE operations which can be more easily
        grouped together into higher performing "executemany"
        operations; the extraction of data from the objects is also performed
        using a lower-latency process that ignores whether or not attributes
        have actually been modified in the case of UPDATEs, and also ignores
        SQL expressions.

        The objects as given are not added to the session and no additional
        state is established on them, unless the ``return_defaults`` flag
        is also set, in which case primary key attributes and server-side
        default values will be populated.

        .. versionadded:: 1.0.0

        .. warning::

            The bulk save feature allows for a lower-latency INSERT/UPDATE
            of rows at the expense of most other unit-of-work features.
            Features such as object management, relationship handling,
            and SQL clause support are **silently omitted** in favor of raw
            INSERT/UPDATES of records.

            **Please read the list of caveats at**
            :ref:`bulk_operations_caveats` **before using this method, and
            fully test and confirm the functionality of all code developed
            using these systems.**

        :param objects: a sequence of mapped object instances.  The mapped
         objects are persisted as is, and are **not** associated with the
         :class:`.Session` afterwards.

         For each object, whether the object is sent as an INSERT or an
         UPDATE is dependent on the same rules used by the :class:`.Session`
         in traditional operation; if the object has the
         :attr:`.InstanceState.key`
         attribute set, then the object is assumed to be "detached" and
         will result in an UPDATE.  Otherwise, an INSERT is used.

         In the case of an UPDATE, statements are grouped based on which
         attributes have changed, and are thus to be the subject of each
         SET clause.  If ``update_changed_only`` is False, then all
         attributes present within each object are applied to the UPDATE
         statement, which may help in allowing the statements to be grouped
         together into a larger executemany(), and will also reduce the
         overhead of checking history on attributes.

        :param return_defaults: when True, rows that are missing values which
         generate defaults, namely integer primary key defaults and sequences,
         will be inserted **one at a time**, so that the primary key value
         is available.  In particular this will allow joined-inheritance
         and other multi-table mappings to insert correctly without the need
         to provide primary key values ahead of time; however,
         :paramref:`.Session.bulk_save_objects.return_defaults` **greatly
         reduces the performance gains** of the method overall.

        :param update_changed_only: when True, UPDATE statements are rendered
         based on those attributes in each state that have logged changes.
         When False, all attributes present are rendered into the SET clause
         with the exception of primary key attributes.

        :param preserve_order: when True, the order of inserts and updates
         matches exactly the order in which the objects are given.   When
         False, common types of objects are grouped into inserts
         and updates, to allow for more batching opportunities.

         .. versionadded:: 1.3

        .. seealso::

            :ref:`bulk_operations`

            :meth:`.Session.bulk_insert_mappings`

            :meth:`.Session.bulk_update_mappings`

        c�"�|j|jdufSrS)rr�r
s r"r�z&Session.bulk_save_objects.<locals>.key�
s���L�%�)�4�"7�8�8r*c3�>K�|]}tj|��V��dSrS)rrH)rgrrs  r"rpz,Session.bulk_save_objects.<locals>.<genexpr>�
s-����H�H��j�/��4�4�H�H�H�H�H�Hr*)r�TFN)�sorted�	itertools�groupby�_bulk_save_mappings)
rMr��return_defaults�update_changed_only�preserve_orderr��
obj_statesr�isupdaterks
          r"r�zSession.bulk_save_objects|
s���n	9�	9�	9�I�H��H�H�H�
��	5��
��4�4�4�J�*3�*;�J��*L�*L�		�		�&��V�X���$�$������#��
�
�
�
�		�		r*c	�<�|�||dd|d|��dS)aFPerform a bulk insert of the given list of mapping dictionaries.

        The bulk insert feature allows plain Python dictionaries to be used as
        the source of simple INSERT operations which can be more easily
        grouped together into higher performing "executemany"
        operations.  Using dictionaries, there is no "history" or session
        state management features in use, reducing latency when inserting
        large numbers of simple rows.

        The values within the dictionaries as given are typically passed
        without modification into Core :meth:`_expression.Insert` constructs,
        after
        organizing the values within them across the tables to which
        the given mapper is mapped.

        .. versionadded:: 1.0.0

        .. warning::

            The bulk insert feature allows for a lower-latency INSERT
            of rows at the expense of most other unit-of-work features.
            Features such as object management, relationship handling,
            and SQL clause support are **silently omitted** in favor of raw
            INSERT of records.

            **Please read the list of caveats at**
            :ref:`bulk_operations_caveats` **before using this method, and
            fully test and confirm the functionality of all code developed
            using these systems.**

        :param mapper: a mapped class, or the actual :class:`_orm.Mapper`
         object,
         representing the single kind of object represented within the mapping
         list.

        :param mappings: a sequence of dictionaries, each one containing the
         state of the mapped row to be inserted, in terms of the attribute
         names on the mapped class.   If the mapping refers to multiple tables,
         such as a joined-inheritance mapping, each dictionary must contain all
         keys to be populated into all tables.

        :param return_defaults: when True, rows that are missing values which
         generate defaults, namely integer primary key defaults and sequences,
         will be inserted **one at a time**, so that the primary key value
         is available.  In particular this will allow joined-inheritance
         and other multi-table mappings to insert correctly without the need
         to provide primary
         key values ahead of time; however,
         :paramref:`.Session.bulk_insert_mappings.return_defaults`
         **greatly reduces the performance gains** of the method overall.
         If the rows
         to be inserted only refer to a single table, then there is no
         reason this flag should be set as the returned default information
         is not used.

        :param render_nulls: When True, a value of ``None`` will result
         in a NULL value being included in the INSERT statement, rather
         than the column being omitted from the INSERT.   This allows all
         the rows being INSERTed to have the identical set of columns which
         allows the full set of rows to be batched to the DBAPI.  Normally,
         each column-set that contains a different combination of NULL values
         than the previous row must omit a different series of columns from
         the rendered INSERT statement, which means it must be emitted as a
         separate statement.   By passing this flag, the full set of rows
         are guaranteed to be batchable into one batch; the cost however is
         that server-side defaults which are invoked by an omitted column will
         be skipped, so care must be taken to ensure that these are not
         necessary.

         .. warning::

            When this flag is set, **server side default SQL values will
            not be invoked** for those columns that are inserted as NULL;
            the NULL value will be sent explicitly.   Care must be taken
            to ensure that no server-side default functions need to be
            invoked for the operation as a whole.

         .. versionadded:: 1.1

        .. seealso::

            :ref:`bulk_operations`

            :meth:`.Session.bulk_save_objects`

            :meth:`.Session.bulk_update_mappings`

        FN�r�)rMr�mappingsr��render_nullss     r"r�zSession.bulk_insert_mappings�
s<��v	
� � ��������	
�	
�	
�	
�	
r*c	�<�|�||ddddd��dS)a�Perform a bulk update of the given list of mapping dictionaries.

        The bulk update feature allows plain Python dictionaries to be used as
        the source of simple UPDATE operations which can be more easily
        grouped together into higher performing "executemany"
        operations.  Using dictionaries, there is no "history" or session
        state management features in use, reducing latency when updating
        large numbers of simple rows.

        .. versionadded:: 1.0.0

        .. warning::

            The bulk update feature allows for a lower-latency UPDATE
            of rows at the expense of most other unit-of-work features.
            Features such as object management, relationship handling,
            and SQL clause support are **silently omitted** in favor of raw
            UPDATES of records.

            **Please read the list of caveats at**
            :ref:`bulk_operations_caveats` **before using this method, and
            fully test and confirm the functionality of all code developed
            using these systems.**

        :param mapper: a mapped class, or the actual :class:`_orm.Mapper`
         object,
         representing the single kind of object represented within the mapping
         list.

        :param mappings: a sequence of dictionaries, each one containing the
         state of the mapped row to be updated, in terms of the attribute names
         on the mapped class.   If the mapping refers to multiple tables, such
         as a joined-inheritance mapping, each dictionary may contain keys
         corresponding to all tables.   All those keys which are present and
         are not part of the primary key are applied to the SET clause of the
         UPDATE statement; the primary key values, which are required, are
         applied to the WHERE clause.


        .. seealso::

            :ref:`bulk_operations`

            :meth:`.Session.bulk_insert_mappings`

            :meth:`.Session.bulk_save_objects`

        TFNr�)rMrr�s   r"r�zSession.bulk_update_mappingsJs6��b	
� � ��H�d�E�5�%��	
�	
�	
�	
�	
r*c��t|��}d|_|�d���}	|rtj|||||��ntj||||||��|���nH#tj��5|�	d���ddd��n#1swxYwYYnxYwd|_dS#d|_wxYw)NTr�r�F)
rrvr�r�_bulk_update�_bulk_insertr�rr�r�)	rMrr�r��isstatesr�r�r�r�s	         r"r�zSession._bulk_save_mappingssG��"�&�)�)������j�j��j�6�6��	#��
��(�����'������(�����#� �
���
��� � � � ��	>��"�$�$�
>�
>��$�$��$�=�=�=�
>�
>�
>�
>�
>�
>�
>�
>�
>�
>�
>����
>�
>�
>�
>������#�D�N�N�N��U�D�N�"�"�"�"sB�AA7�6C�7B<�B/�#B<�/B3	�3B<�6B3	�7B<�:C�	C)z0.8z�The :paramref:`.Session.is_modified.passive` flag is deprecated and will be removed in a future release.  The flag is no longer used and is ignored.r�c� �t|��}|jsdS|j}|jjD]a}|st|jd��st|jd��s�/|j�||tj���\}}}	|s|	rdS�bdS)aZ
Return ``True`` if the given instance has locally
        modified attributes.

        This method retrieves the history for each instrumented
        attribute on the instance and performs a comparison of the current
        value to its previously committed value, if any.

        It is in effect a more expensive and accurate
        version of checking for the given instance in the
        :attr:`.Session.dirty` collection; a full test for
        each attribute's net "dirty" status is performed.

        E.g.::

            return session.is_modified(someobject)

        A few caveats to this method apply:

        * Instances present in the :attr:`.Session.dirty` collection may
          report ``False`` when tested with this method.  This is because
          the object may have received change events via attribute mutation,
          thus placing it in :attr:`.Session.dirty`, but ultimately the state
          is the same as that loaded from the database, resulting in no net
          change here.
        * Scalar attributes may not have recorded the previously set
          value when a new value was applied, if the attribute was not loaded,
          or was expired, at the time the new value was received - in these
          cases, the attribute is assumed to have a change, even if there is
          ultimately no net change against its database value. SQLAlchemy in
          most cases does not need the "old" value when a set event occurs, so
          it skips the expense of a SQL call if the old value isn't present,
          based on the assumption that an UPDATE of the scalar value is
          usually needed, and in those few cases where it isn't, is less
          expensive on average than issuing a defensive SELECT.

          The "old" value is fetched unconditionally upon set only if the
          attribute container has the ``active_history`` flag set to ``True``.
          This flag is set typically for primary key attributes and scalar
          object references that are not a simple many-to-one.  To set this
          flag for any arbitrary mapped column, use the ``active_history``
          argument with :func:`.column_property`.

        :param instance: mapped instance to be tested for pending changes.
        :param include_collections: Indicates if multivalued collections
         should be included in the operation.  Setting this to ``False`` is a
         way to detect only local-column based properties (i.e. scalar columns
         or many-to-one foreign keys) that would result in an UPDATE for this
         instance upon flush.
        :param passive: not used

        F�get_collection�get_historyr�T)	rr�r�rXr�hasattr�implr�	NO_CHANGE)
rMr2�include_collectionsr�r�dict_�attr�added�	unchangedr�s
          r"r�zSession.is_modified�s���x�X�&�&���~�	��5��
���M�,�	�	�D�'�
��D�I�'7�8�8�
��T�Y�
�6�6�
��*.�)�*?�*?��u�j�&:�+@�+�+�'�U�I�w��
��
��t�t�
��5r*c�(�|jo|jjS)a2True if this :class:`.Session` is in "transaction mode" and
        is not in "partial rollback" state.

        The :class:`.Session` in its default mode of ``autocommit=False``
        is essentially always in "transaction mode", in that a
        :class:`.SessionTransaction` is associated with it as soon as
        it is instantiated.  This :class:`.SessionTransaction` is immediately
        replaced with a new one as soon as it is ended, due to a rollback,
        commit, or close operation.

        "Transaction mode" does *not* indicate whether
        or not actual database connection resources are in use;  the
        :class:`.SessionTransaction` object coordinates among zero or more
        actual database transactions, and starts out with none, accumulating
        individual DBAPI connections as different data sources are used
        within its scope.   The best way to track when a particular
        :class:`.Session` has actually begun to use DBAPI resources is to
        implement a listener using the :meth:`.SessionEvents.after_begin`
        method, which will deliver both the :class:`.Session` as well as the
        target :class:`_engine.Connection` to a user-defined event listener.

        The "partial rollback" state refers to when an "inner" transaction,
        typically used during a flush, encounters an error and emits a
        rollback of the DBAPI connection.  At this point, the
        :class:`.Session` is in "partial rollback" and awaits for the user to
        call :meth:`.Session.rollback`, in order to close out the
        transaction stack.  It is in this "partial rollback" period that the
        :attr:`.is_active` flag returns False.  After the call to
        :meth:`.Session.rollback`, the :class:`.SessionTransaction` is
        replaced with a new one and :attr:`.is_active` returns ``True`` again.

        When a :class:`.Session` is used in ``autocommit=True`` mode, the
        :class:`.SessionTransaction` is only instantiated within the scope
        of a flush call, or when :meth:`.Session.begin` is called.  So
        :attr:`.is_active` will always be ``False`` outside of a flush or
        :meth:`.Session.begin` block in this mode, and will be ``True``
        within the :meth:`.Session.begin` block as long as it doesn't enter
        "partial rollback" state.

        From all the above, it follows that the only purpose to this flag is
        for application frameworks that wish to detect if a "rollback" is
        necessary within a generic error handling routine, for
        :class:`.Session` objects that would otherwise be in
        "partial rollback" mode.  In a typical integration case, this is also
        not necessary as it is standard practice to emit
        :meth:`.Session.rollback` unconditionally within the outermost
        exception catch.

        To track the transactional state of a :class:`.Session` fully,
        use event listeners, primarily the :meth:`.SessionEvents.after_begin`,
        :meth:`.SessionEvents.after_commit`,
        :meth:`.SessionEvents.after_rollback` and related events.

        )r�rTrQs r"rTzSession.is_active�s��p��>�D�$4�$>�>r*c�4�|j���S)z�The set of all persistent states considered dirty.

        This method returns all states that were modified including
        those that were possibly deleted.

        )r�r�rQs r"r�zSession._dirty_statesBs��� �.�.�0�0�0r*c�N��tj�fd��jD����S)aZThe set of all persistent instances considered dirty.

        E.g.::

            some_mapped_object in session.dirty

        Instances are considered dirty when they were modified but not
        deleted.

        Note that this 'dirty' calculation is 'optimistic'; most
        attribute-setting or collection modification operations will
        mark an instance as 'dirty' and place it in this set, even if
        there is no net change to the attribute's value.  At flush
        time, the value of each attribute is compared to its
        previously saved value, and if there's no net change, no SQL
        operation will occur (this is a more expensive operation so
        it's only done at flush time).

        To check if an instance has actionable net changes to its
        attributes, use the :meth:`.Session.is_modified` method.

        c�J��g|]}|�jv�|����� Sr:)rsrr)rgrrMs  �r"rhz!Session.dirty.<locals>.<listcomp>es8���
�
�
����
�-�-��	�	���-�-�-r*)r�IdentitySetr�rQs`r"r�z
Session.dirtyLsC���0��
�
�
�
�!�/�
�
�
�
�
�	
r*c�r�tjt|j�������S)zDThe set of all instances marked as 'deleted' within this ``Session``)rrr�rsr�rQs r"r�zSession.deletedls+�����T�]�%9�%9�%;�%;� <� <�=�=�=r*c�r�tjt|j�������S)zAThe set of all instances marked as 'new' within this ``Session``.)rrr�rrr�rQs r"r�zSession.newrs+�����T�Y�%5�%5�%7�%7� 8� 8�9�9�9r*)NTTTFFNNNTNN)FF)NNNFNrS)NNN)NNr�)T)TNN)FTTr�)Nr3r4r5r6�public_methodsr�deprecated_paramsrO�connection_callabler��memoized_propertyr�r�r�r�r�r�rhrdr�r�r�r�rr�r�r*r-rcr	r��contextmanagerr>rCr�r�r�rKrZr8rdr�r�r}ryr�r�r�r�r�r�r�r�rVr�r�r�r�r�r�r�r�r�rwr�r�r�r�r�r�r�r�rTr�r�r�r�r�r:r*r"rrks����������N�:�T��	
�(
�

�!���4���'+������!�
��I(�I(�I(�1��0I(�V���K�F�	�������> �> �> �> �@'�'�'�2(�(�(�(""�""�""�H#�#�#�*��
���
O
�O
�O
�O
�b	�	�	�	�J
�J
�J
�J
�X����
+�
+�
+� *� *� *�D.�.�.�
@�
@�
@����2%�%�%�8$�$�$�8A
�A
�A
�A
�F9�9�9��	��'�'����X�'�4A�A�A�&���]�]�]�]�~!C�!C�!C�F,3�,3�,3�,3�\.�.�.� � � ��T�_�
�	'���)�)�
��)�N�N�N�0

�

�

�

�P!�P!�P!�d:�:�:�3�3�3�(*�*�*�*�.,�,�,�+�+�+�6�6�6�& 1� 1� 1�DM'�M'�M'�M'�f��"�
S�S�S�S�j���
+�
+�
+�$=�$=�$=�$=�L%�%�%�;+�;+�;+�z
�
�
�	<�	<�	<�+�+�+� 
�
�
�M�M�M�$#�$#�$#�$#�L
�
�
�
�
�
�{>�{>�{>�{>�@� ��g�g�g�g�TEJ�c
�c
�c
�c
�J3
�3
�3
�j&#�&#�&#�P�T��
����I�I�I���I�V�7?�7?��X�7?�r�L���1�1��X�1��
�
��X�
�>�>�>��X�>�
�:�:��X�:�:�:r*rc�8�eZdZdZdeddddfd�Zd�Zd�Zd�ZdS)	ra3A configurable :class:`.Session` factory.

    The :class:`.sessionmaker` factory generates new
    :class:`.Session` objects when called, creating them given
    the configurational arguments established here.

    e.g.::

        # global scope
        Session = sessionmaker(autoflush=False)

        # later, in a local scope, create and use a session:
        sess = Session()

    Any keyword arguments sent to the constructor itself will override the
    "configured" keywords::

        Session = sessionmaker()

        # bind an individual session to a connection
        sess = Session(bind=connection)

    The class also includes a method :meth:`.configure`, which can
    be used to specify additional keyword arguments to the factory, which
    will take effect for subsequent :class:`.Session` objects generated.
    This is usually used to associate one or more :class:`_engine.Engine`
    objects
    with an existing :class:`.sessionmaker` factory before it is first
    used::

        # application starts
        Session = sessionmaker()

        # ... later
        engine = create_engine('sqlite:///foo.db')
        Session.configure(bind=engine)

        sess = Session()

    .. seealso::

        :ref:`session_getting` - introductory text on creating
        sessions using :class:`.sessionmaker`.

    NTFc��||d<||d<||d<||d<|�||d<||_t|j|fi��|_dS)alConstruct a new :class:`.sessionmaker`.

        All arguments here except for ``class_`` correspond to arguments
        accepted by :class:`.Session` directly.  See the
        :meth:`.Session.__init__` docstring for more details on parameters.

        :param bind: a :class:`_engine.Engine` or other :class:`.Connectable`
         with
         which newly created :class:`.Session` objects will be associated.
        :param class\_: class to use in order to create new :class:`.Session`
         objects.  Defaults to :class:`.Session`.
        :param autoflush: The autoflush setting to use with newly created
         :class:`.Session` objects.
        :param autocommit: The autocommit setting to use with newly created
         :class:`.Session` objects.
        :param expire_on_commit=True: the
         :paramref:`_orm.Session.expire_on_commit` setting to use
         with newly created :class:`.Session` objects.

        :param info: optional dictionary of information that will be available
         via :attr:`.Session.info`.  Note this dictionary is *updated*, not
         replaced, when the ``info`` parameter is specified to the specific
         :class:`.Session` construction operation.

         .. versionadded:: 0.9.0

        :param \**kw: all other keyword arguments are passed to the
         constructor of newly created :class:`.Session` objects.

        rgr�r�r�Nr�)rr$r3r )rMrgr r�r�r�r�rs        r"rOzsessionmaker.__init__�s_��P��6�
�#��;��%��<��!1�������B�v�J�����6�?�V�I�r�:�:����r*c��|j���D]Z\}}|dkr9d|vr5|���}|�|d��||d<�D|�||���[|jdi|��S)aeProduce a new :class:`.Session` object using the configuration
        established in this :class:`.sessionmaker`.

        In Python, the ``__call__`` method is invoked on an object when
        it is "called" in the same way as a function::

            Session = sessionmaker()
            session = Session()  # invokes sessionmaker.__call__()

        r�r:)rr��copyr��
setdefaultr )rM�local_kw�k�v�ds     r"�__call__zsessionmaker.__call__�s����G�M�M�O�O�	*�	*�D�A�q��F�{�{�v��1�1��F�F�H�H������&�)�*�*�*�#$��� � ��#�#�A�q�)�)�)�)��t�{�&�&�X�&�&�&r*c�:�|j�|��dS)z�(Re)configure the arguments for this sessionmaker.

        e.g.::

            Session = sessionmaker()

            Session.configure(bind=create_engine('sqlite://'))
        N)rr�)rM�new_kws  r"�	configurezsessionmaker.configure�s��	
����v�����r*c	��|jj�d|jj�dd�d�|j���D�����d�S)Nz(class_=r0c3�*K�|]\}}|�d|��V��dS)�=Nr:)rgr!r"s   r"rpz(sessionmaker.__repr__.<locals>.<genexpr>�s1����C�C�4�1�a����A�A�&�C�C�C�C�C�Cr*�))�	__class__r3r r9rr�rQs r"�__repr__zsessionmaker.__repr__�sV���N�#�#�#��K� � � ��I�I�C�C�4�7�=�=�?�?�C�C�C�C�C�C�C�
�	
r*)	r3r4r5r6rrOr$r'r-r:r*r"rrysu������,�,�`�����
�1;�1;�1;�1;�f'�'�'�(	�	�	�
�
�
�
�
r*rc�f�t���D]}|����dS)aOClose all sessions in memory.

    This function consults a global registry of all :class:`.Session` objects
    and calls :meth:`.Session.close` on them, which resets them to a clean
    state.

    This function is not for general use but may be useful for test suites
    within the teardown scheme.

    .. versionadded:: 1.3

    N)r r�r�)r�s r"r'r'
s8��� � �"�"�����
�
������r*c���tj|��}t|��}|r|�|g��|j���|jr|`|jr|`|jr|`dSdS)aMAlter the state of the given instance so that it is :term:`transient`.

    .. note::

        :func:`.make_transient` is a special-case function for
        advanced use cases only.

    The given mapped instance is assumed to be in the :term:`persistent` or
    :term:`detached` state.   The function will remove its association with any
    :class:`.Session` as well as its :attr:`.InstanceState.identity`. The
    effect is that the object will behave as though it were newly constructed,
    except retaining any attribute / collection values that were loaded at the
    time of the call.   The :attr:`.InstanceState.deleted` flag is also reset
    if this object had been deleted as a result of using
    :meth:`.Session.delete`.

    .. warning::

        :func:`.make_transient` does **not** "unexpire" or otherwise eagerly
        load ORM-mapped attributes that are not currently loaded at the time
        the function is called.   This includes attributes which:

        * were expired via :meth:`.Session.expire`

        * were expired as the natural effect of committing a session
          transaction, e.g. :meth:`.Session.commit`

        * are normally :term:`lazy loaded` but are not currently loaded

        * are "deferred" via :ref:`deferred` and are not yet loaded

        * were not present in the query which loaded this object, such as that
          which is common in joined table inheritance and other scenarios.

        After :func:`.make_transient` is called, unloaded attributes such
        as those above will normally resolve to the value ``None`` when
        accessed, or an empty collection for a collection-oriented attribute.
        As the object is transient and un-associated with any database
        identity, it will no longer retrieve these values.

    .. seealso::

        :func:`.make_transient_to_detached`

    N)	rrHr#r��expired_attributesr��	callablesr�rs)r2rr�s   r"�make_transientr2
s���\
�%�h�/�/�E��u���A��#�	���5�'�"�"�"�
��"�"�$�$�$�
����O��y���I��~���N�N�N��r*c�6�tj|��}|js|jrt	jd���|j�|��|_|jr|`|�	|j
��|�|j
|j��dS)a�Make the given transient instance :term:`detached`.

    .. note::

        :func:`.make_transient_to_detached` is a special-case function for
        advanced use cases only.

    All attribute history on the given instance
    will be reset as though the instance were freshly loaded
    from a query.  Missing attributes will be marked as expired.
    The primary key attributes of the object, which are required, will be made
    into the "key" of the instance.

    The object can then be added to a session, or merged
    possibly with the load=False flag, at which point it will look
    as if it were loaded that way, without emitting SQL.

    This is a special use case function that differs from a normal
    call to :meth:`.Session.merge` in that a given persistent state
    can be manufactured without any SQL calls.

    .. versionadded:: 0.9.5

    .. seealso::

        :func:`.make_transient`

        :meth:`.Session.enable_relationship_loading`

    zGiven object must be transientN)
rrHrr�rGrHrrsrsr�r�rW�unloaded_expirable)r2rs  r"�make_transient_to_detachedr5T
s���>
�%�h�/�/�E���K�5�9�K��(�)I�J�J�J���5�5�e�<�<�E�I��~���N�	���e�j�!�!�!�	���U�Z��)A�B�B�B�B�Br*c���	tj|��}t|��S#tj$r3}tjtj|��|���Yd}~dSd}~wwxYw)z�Return the :class:`.Session` to which the given instance belongs.

    This is essentially the same as the :attr:`.InstanceState.session`
    accessor.  See that attribute for details.

    rN)rrHr#rrIrr�rJ)r2rr's   r"r1r1}
s���%��)�(�3�3���e�$�$�$��
�<�
�
�
����%�h�/�/��	
�	
�	
�	
�	
�	
�	
�	
�	
�	
�����
���s�%�A'�(A"�"A')6r6r�r�rx�rrrrrr	rr��baserr
rrrrr�deprecated_interfacesr�
unitofworkrrrGrr�
inspectionrrr5�__all__�WeakValueDictionaryr r#�objectr%�symbolr;r<r=r>r?rrrr'r2r5r1�counterr�r:r*r"�<module>rAsm��8�7�����
�
�
�
�����������������������������������������������"�"�"�"�"�"�������������������������������������3�3�3�3�3�3�&�&�&�&�&�&������������������������� � � � � � �������"�"�"�"�"�"�P�
O�
O��'�G�'�)�)�	�?�
�
�
�!(�!(�!(�!(�!(�6�!(�!(�!(�H
���X�	�	���4�;�z�"�"���D�K��$�$�	��4�;�z�"�"��	���X�	�	��C�C�C�C�C��C�C�C�LK(:�K(:�K(:�K(:�K(:�"�K(:�K(:�K(:�\PF
�F
�F
�F
�F
�'�F
�F
�F
�R���$=�=�=�@&C�&C�&C�R%�%�%�&�������r*

Hacked By AnonymousFox1.0, Coded By AnonymousFox