Sh3ll
OdayForums


Server : LiteSpeed
System : Linux premium84.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User : claqxcrl ( 523)
PHP Version : 8.1.32
Disable Function : NONE
Directory :  /opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/orm/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/orm/__pycache__/session.cpython-312.pyc
�

���g�����UdZddlmZddlZddlmZddlZddlZddlZddlm	Z	ddlm
Z
ddlmZddlmZdd	lm
Z
dd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$dd lm%Z&dd!l'm(Z(dd"l'm)Z)dd#l'm*Z*dd$l'm+Z+dd%l'm,Z,dd&l-m.Z.dd'l-m/Z/dd(l-m0Z0dd)l-m1Z1dd*l-m2Z2dd+l-m3Z3dd,l-m4Z4dd-l-m5Z5dd.l-m6Z6dd/lm7Z7dd0lm8Z8dd1l"m9Z9dd2l$m:Z:dd3l%m;Z;dd4l<m=Z=dd5l<m>Z>dd6l<m?Z?dd7l@mAZAd8d9lmBZBd8dlm!ZCd8d:lmDZDd8d;lmEZEd8d<lBmFZFd8d=lBmGZGd8d>lHmIZId8d?lJmKZKd8d@lJmLZLd8dAlMmNZNd8dBlMmOZOd8dClDmPZPd8dDlDmQZQd8dElDmRZRd8dFlDmSZSd8dGlDmTZTd8dHlDmUZUd8dIlVmWZWd8dJlVmXZXd8dKlYmZZZd8dLl[m\Z\d8dMl[m]Z]d8dNlEm^Z^d8dOl_m`Z`d8dPl_maZaej0r�ddQl'mbZbddRl'mcZcddSl'mdZdddTl'meZeddUlfmgZgddVlfmhZhddWlimjZjddXlkmlZlddYl$mmZmd8dZlBmnZnd8d[lBmoZod8d\lBmpZpd8d]lBmqZqd8d^lrmsZsd8d_lrmtZtd8d`lumvZvd8dalumwZwd8dblumxZxd8dclumyZyd8ddlzm{Z{d8delJm|Z|d8dfl}m~Z~d8dgl}mZd8dhl}m�Z�d8dil}m�Z�d8djl}m�Z�d8dkl}m�Z�d8dll}m�Z�d8dml}m�Z�d8dnl}m�Z�d8dol}m�Z�d8dpl}m�Z�d8dqlVm�Z�d8drlVm�Z�d8dsl�m�Z�d8dtl�m�Z�d8dul�m�Z�d8dvl[m�Z�d8dwl[m�Z�edxe	�y�Z�gdz�Z�e�j,�Z�d{e�d|<	e�e&_�ee	ee	d}ffZ�ee�e	fZ�eee(d~fZ�eee	dd�e�fZ�ed�Z�e`d�Z�Gd��d�ea�Z�d�d��Z�Gd��d��Z�Gd��d�e>�Z�e�e��\Z�Z�Z�Z�Z�Z�Gd��d�eE�jV�Z�Gd��d�e�Z�Gd��d�e=eI�Z�Gd��d�e�Z�Gd��d�e�eL�Z�ed�d��y�Z�Gd��d�e�e
e��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�eE�jn�Z�y)�z1Provides the Session class and related utilities.�)�annotationsN)�Enum)�Any)�Callable)�cast)�Dict)�Generic)�Iterable)�Iterator)�List)�NoReturn)�Optional)�overload)�Sequence)�Set)�Tuple)�Type)�
TYPE_CHECKING)�TypeVar)�Union�)�
attributes)�bulk_persistence)�context)�descriptor_props)�exc)�identity)�loading)�query��state)�_O)�insp_is_mapper)�is_composite_class)�
is_orm_option)�is_user_defined_option)�_class_to_mapper)�	_none_set)�
_state_mapper)�instance_str)�LoaderCallableStatus)�
object_mapper)�object_state)�PassiveFlag)�	state_str)�
FromStatement)�ORMCompileState)�IdentityMap)�Query)�
InstanceState)�_StateChange)�_StateChangeState)�_StateChangeStates)�UOWTransaction�)�engine)�sql)�util)�
Connection)�Engine)�TransactionalContext)�
dispatcher)�EventTarget)�inspect)�Inspectable)�	coercions)�dml)�roles)�Select)�TableClause)�visitors)�_NoArg)�CompileState)�Table)�ForUpdateArg)�LABEL_STYLE_TABLENAME_PLUS_COL)�IdentitySet)�Literal)�Protocol)�_EntityType)�_IdentityKeyType)�
_InstanceDict)�OrmExecuteOptionsParameter)�	ORMOption)�UserDefinedOption)�Mapper)�PathRegistry)�RowReturningQuery)�CursorResult)�Result)�Row)�
RowMapping)�Transaction)�TwoPhaseTransaction)�_CoreAnyExecuteParams)�_CoreSingleExecuteParams)�_ExecuteOptions)�CoreExecuteOptionsParameter)�ScalarResult)�_InstanceLevelDispatch)�_ColumnsClauseArgument)�	_InfoType)�_T0)�_T1)�_T2)�_T3)�_T4)�_T5)�_T6)�_T7)�_TypedColumnClauseArgument)�
Executable)�ExecutableOption)�
UpdateBase)�
ClauseElement)�TypedColumnsClauseRole)�ForUpdateParameter)�TypedReturnsRows�_T)�bound)�Session�SessionTransaction�sessionmaker�ORMExecuteState�close_all_sessions�make_transient�make_transient_to_detached�object_sessionz)weakref.WeakValueDictionary[int, Session]�	_sessions.�
Mapper[_O]�Mapper[Any]rH)r>r=)�conditional_savepoint�
rollback_only�
control_fully�create_savepointc�,�eZdZdZ		d							dd�Zy)�_ConnectionCallableProtoa�a callable that returns a :class:`.Connection` given an instance.

    This callable, when present on a :class:`.Session`, is called only from the
    ORM's persistence mechanism (i.e. the unit of work flush process) to allow
    for connection-per-instance schemes (i.e. horizontal sharding) to be used
    as persistence time.

    This callable is not present on a plain :class:`.Session`, however
    is established when using the horizontal sharding extension.

    Nc��y�N�)�self�mapper�instance�kws    �G/opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/orm/session.py�__call__z!_ConnectionCallableProto.__call__�s��
��NN)r��Optional[Mapper[Any]]r�zOptional[object]r�r�returnr=)�__name__�
__module__�__qualname__�__doc__r�r�r�r�r�r��s:��
�)-�%)��%��#���	�

�r�r�c��|jS)z[Given an :class:`.InstanceState`, return the :class:`.Session`
    associated, if any.
    ��sessionr s r��_state_sessionr��s���=�=�r�c���eZdZdZeejdd�d
d���Zeejd�		ddddd�											dd���Z	ed
d	��Z
y)�_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�y)zClose *all* sessions in memory.N)r)�clss r��	close_allz_SessionClassMethods.close_all�s
��	�r�zsqlalchemy.orm.utilN�r��row�identity_tokenc�^�tjjj|||||��S)zZReturn an identity key.

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

        r�)r<�	preloaded�orm_util�identity_key)r��class_�identr�r�r�s      r�r�z!_SessionClassMethods.identity_key�s5�� �~�~�&�&�3�3�����)�4�
�	
r�c��t|�S)zxReturn the :class:`.Session` to which an object belongs.

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

        )r�)r�r�s  r�r�z#_SessionClassMethods.object_session�s���h�'�'r��r��Noner�)r�zOptional[Type[Any]]r��Union[Any, Tuple[Any, ...]]r��
Optional[Any]r�z%Optional[Union[Row[Any], RowMapping]]r�r�r�z_IdentityKeyType[Any]�r��objectr��Optional[Session])r�r�r�r��classmethodr<�
deprecatedr��preload_moduler�r�r�r�r�r�r��s���L���T�_�_�
�	/���
���
��T���.�/�'+�-1�
�
#'�59�(,�
�#�
�+�
�
 �
�3�

�&�
�
�
�0��
�,�(��(r�r�c�$�eZdZdZdZdZdZdZdZy)�SessionTransactionStaterr9����N)	r�r�r��ACTIVE�PREPARED�	COMMITTED�DEACTIVE�CLOSED�PROVISIONING_CONNECTIONr�r�r�r�r��s!��
�F��H��I��H�
�F��r�r�c�6�eZdZUdZdZded<	ded<	ded<	d	ed
<	d	ed<	ded
<	ded<ded<ded<ded<														d.d�Zd/d�Z				d0									d1d�Ze	d2d��Z
e	d3d��Ze	d4d��Ze	d4d��Z
e	d4d��Ze	d4d��Ze	d4d ��Ze	d4d!��Ze	d4d"��Ze	d4d#��Zd5d$�Z		d6d%�Ze	d7d&��Ze	d8d'��Ze	d4d(��Ze	d4d)��Ze			d9d*��Ze			d:d+��Ze	d;d,��Ze	d<d-��Zy)=r~a8Represents a call to the :meth:`_orm.Session.execute` method, as passed
    to the :meth:`.SessionEvents.do_orm_execute` event hook.

    .. versionadded:: 1.4

    .. seealso::

        :ref:`session_execute_events` - top level documentation on how
        to use :meth:`_orm.SessionEvents.do_orm_execute`

    )r��	statement�
parameters�execution_options�local_execution_options�bind_argumentsr��_compile_state_cls�_starting_event_idx�_events_todo�_update_execution_optionsr{r�rrr��Optional[_CoreAnyExecuteParams]r�rcr�r��_BindArgumentsr��Optional[Type[ORMCompileState]]r��intr�z	List[Any]r��Optional[_ExecuteOptions]r�c��||_||_||_||_|jj|�|_||_||_t|�|_
y)zhConstruct a new :class:`_orm.ORMExecuteState`.

        this object is constructed internally.

        N)r�r�r�r��_execution_options�unionr�r�r��listr�)r�r�r�r�r�r��compile_state_cls�events_todos        r��__init__zORMExecuteState.__init__`s\�����"���$���'8��$�!*�!=�!=�!C�!C��"
���-���"3��� ��-��r�c�:�|j|jdzdS)Nr)r�r��r�s r��_remaining_eventsz!ORMExecuteState._remaining_eventszs!��� � ��!9�!9�A�!=�!?�@�@r�Nc	���|�|j}t|j�}|r|j|�d|d<|r�|jr�g}td|j�}tj|td|��D]d\}}	|�|	�.tjdt|��dt|��d���t|�}|j|	�|j|��fnGttd|j��}|jtd|��n|j}|j}
|r|
j|�}
|jj!|||
||��S)	a�Execute the statement represented by this
        :class:`.ORMExecuteState`, without re-invoking events that have
        already proceeded.

        This method essentially performs a re-entrant execution of the current
        statement for which the :meth:`.SessionEvents.do_orm_execute` event is
        being currently invoked.    The use case for this is for event handlers
        that want to override how the ultimate
        :class:`_engine.Result` object is returned, such as for schemes that
        retrieve results from an offline cache or which concatenate results
        from multiple executions.

        When the :class:`_engine.Result` object is returned by the actual
        handler function within :meth:`_orm.SessionEvents.do_orm_execute` and
        is propagated to the calling
        :meth:`_orm.Session.execute` method, the remainder of the
        :meth:`_orm.Session.execute` method is preempted and the
        :class:`_engine.Result` object is returned to the caller of
        :meth:`_orm.Session.execute` immediately.

        :param statement: optional statement to be invoked, in place of the
         statement currently represented by :attr:`.ORMExecuteState.statement`.

        :param params: optional dictionary of parameters or list of parameters
         which will be merged into the existing
         :attr:`.ORMExecuteState.parameters` of this :class:`.ORMExecuteState`.

         .. versionchanged:: 2.0 a list of parameter dictionaries is accepted
            for executemany executions.

        :param execution_options: optional dictionary of execution options
         will be merged into the existing
         :attr:`.ORMExecuteState.execution_options` of this
         :class:`.ORMExecuteState`.

        :param bind_arguments: optional dictionary of bind_arguments
         which will be merged amongst the current
         :attr:`.ORMExecuteState.bind_arguments`
         of this :class:`.ORMExecuteState`.

        :return: a :class:`_engine.Result` object with ORM-level results.

        .. seealso::

            :ref:`do_orm_execute_re_executing` - background and examples on the
            appropriate usage of :meth:`_orm.ORMExecuteState.invoke_statement`.


        T�_sa_skip_eventszList[Dict[str, Any]]zgCan't apply executemany parameters to statement; number of parameter sets passed to Session.execute() (zW) does not match number of parameter sets given to ORMExecuteState.invoke_statement() (�)zDict[str, Any])r�r��_parent_execute_state)r��dictr��update�is_executemanyrr��	itertools�zip_longest�sa_exc�InvalidRequestError�len�appendr�r�r��_execute_internal)r�r��paramsr�r��_bind_arguments�_params�exec_many_parameters�_existing_params�_new_paramsr�s           r��invoke_statementz ORMExecuteState.invoke_statement}s���r�����I��t�2�2�3����"�"�>�2�-1��)�*���"�"���'+�*�D�O�O�(�$�6?�5J�5J�(��/��8�6�1�$�k�(�/�;�3F�$�8�8�2�25�6J�2K�1L�M �!$�F��}�A�/���(,�,<�'=�$�$�+�+�K�8��N�N�#3�4�6�"�t�$4�d�o�o�F�G�����t�$4�f�=�>��o�o�G�!�9�9���!3�!9�!9�:K�!L���|�|�-�-���0�*�"&�.�
�	
r�c�>�|jjdd�}|S)a�Return the :class:`_orm.Mapper` that is the primary "bind" mapper.

        For an :class:`_orm.ORMExecuteState` object invoking an ORM
        statement, that is, the :attr:`_orm.ORMExecuteState.is_orm_statement`
        attribute is ``True``, this attribute will return the
        :class:`_orm.Mapper` that is considered to be the "primary" mapper
        of the statement.   The term "bind mapper" refers to the fact that
        a :class:`_orm.Session` object may be "bound" to multiple
        :class:`_engine.Engine` objects keyed to mapped classes, and the
        "bind mapper" determines which of those :class:`_engine.Engine` objects
        would be selected.

        For a statement that is invoked against a single mapped class,
        :attr:`_orm.ORMExecuteState.bind_mapper` is intended to be a reliable
        way of getting this mapper.

        .. versionadded:: 1.4.0b2

        .. seealso::

            :attr:`_orm.ORMExecuteState.all_mappers`


        r�N)r��get)r��mps  r��bind_mapperzORMExecuteState.bind_mapper�s!��4%)�$7�$7�$;�$;�H�d�$K���	r�c���|jsgSt|jttf�r�g}t�}|jjD]l}|d}|s�t|d��}|s�|js�(|j|vs�7|j|j�|j|j��n|S|jjr|jr
|jgSgS)aReturn a sequence of all :class:`_orm.Mapper` objects that are
        involved at the top level of this statement.

        By "top level" we mean those :class:`_orm.Mapper` objects that would
        be represented in the result set rows for a :func:`_sql.select`
        query, or for a :func:`_dml.update` or :func:`_dml.delete` query,
        the mapper that is the main subject of the UPDATE or DELETE.

        .. versionadded:: 1.4.0b2

        .. seealso::

            :attr:`_orm.ORMExecuteState.bind_mapper`



        �entityF)�raiseerr)
�is_orm_statement�
isinstancer�rGr0�set�column_descriptionsrBr��addr��is_dmlr�)r��result�seen�d�ent�insps      r��all_mapperszORMExecuteState.all_mapperss���&�$�$��I�
������(?�
@��F��5�D��^�^�7�7����k���"�3��7�D��������4�0G�������-��
�
�d�k�k�2�
8��M�
�^�^�
"�
"�t�'7�'7��$�$�%�%��Ir�c��|jduS)a�return True if the operation is an ORM statement.

        This indicates that the select(), insert(), update(), or delete()
        being invoked contains ORM entities as subjects.   For a statement
        that does not have ORM entities and instead refers only to
        :class:`.Table` metadata, it is invoked as a Core SQL statement
        and no ORM-level automation takes place.

        N)r�r�s r�r�z ORMExecuteState.is_orm_statement)s���&�&�d�2�2r�c�6�t|jt�S)z�return True if the parameters are a multi-element list of
        dictionaries with more than one dictionary.

        .. versionadded:: 2.0

        )r�r�r�r�s r�r�zORMExecuteState.is_executemany6s���$�/�/�4�0�0r�c�.�|jjS)a8return True if this is a SELECT operation.

        .. versionchanged:: 2.0.30 - the attribute is also True for a
           :meth:`_sql.Select.from_statement` construct that is itself against
           a :class:`_sql.Select` construct, such as
           ``select(Entity).from_statement(select(..))``

        )r��	is_selectr�s r�r
zORMExecuteState.is_select@s���~�~�'�'�'r�c�.�|jjS)areturn True if this operation is a
        :meth:`_sql.Select.from_statement` operation.

        This is independent from :attr:`_orm.ORMExecuteState.is_select`, as a
        ``select().from_statement()`` construct can be used with
        INSERT/UPDATE/DELETE RETURNING types of statements as well.
        :attr:`_orm.ORMExecuteState.is_select` will only be set if the
        :meth:`_sql.Select.from_statement` is itself against a
        :class:`_sql.Select` construct.

        .. versionadded:: 2.0.30

        )r��is_from_statementr�s r�rz!ORMExecuteState.is_from_statementLs���~�~�/�/�/r�c�^�|jjxr|jjS)a9return True if this is an INSERT operation.

        .. versionchanged:: 2.0.30 - the attribute is also True for a
           :meth:`_sql.Select.from_statement` construct that is itself against
           a :class:`_sql.Insert` construct, such as
           ``select(Entity).from_statement(insert(..))``

        )r�r�	is_insertr�s r�rzORMExecuteState.is_insert]�#���~�~�$�$�A����)A�)A�Ar�c�^�|jjxr|jjS)a9return True if this is an UPDATE operation.

        .. versionchanged:: 2.0.30 - the attribute is also True for a
           :meth:`_sql.Select.from_statement` construct that is itself against
           a :class:`_sql.Update` construct, such as
           ``select(Entity).from_statement(update(..))``

        )r�r�	is_updater�s r�rzORMExecuteState.is_updateirr�c�^�|jjxr|jjS)a8return True if this is a DELETE operation.

        .. versionchanged:: 2.0.30 - the attribute is also True for a
           :meth:`_sql.Select.from_statement` construct that is itself against
           a :class:`_sql.Delete` construct, such as
           ``select(Entity).from_statement(delete(..))``

        )r�r�	is_deleter�s r�rzORMExecuteState.is_deleteurr�c�j�t|jtjtjf�Sr�)r�r�rE�Update�Deleter�s r��_is_crudzORMExecuteState._is_crud�s ���$�.�.�3�:�:�s�z�z�*B�C�Cr�c�D�|jj|�|_y)z3Update the local execution options with new values.N)r�r��r��optss  r��update_execution_optionsz(ORMExecuteState.update_execution_options�s��'+�'C�'C�'I�'I�$�'O��$r�c���|jsy	|jj}|�+|j	t
jj�r|Sy#t$rYywxYwr�)r
r��_compile_options�AttributeErrorr�rr1�default_compile_optionsrs  r��_orm_compile_optionsz$ORMExecuteState._orm_compile_options�sb���~�~��	��>�>�2�2�D�������#�#�;�;�!
��K����	��	�s�A�	A�Ac�.�|jjS)a�An :class:`.InstanceState` that is using this statement execution
        for a lazy load operation.

        The primary rationale for this attribute is to support the horizontal
        sharding extension, where it is available within specific query
        execution time hooks created by this extension.   To that end, the
        attribute is only intended to be meaningful at **query execution
        time**, and importantly not any time prior to that, including query
        compilation time.

        )�load_options�_lazy_loaded_fromr�s r��lazy_loaded_fromz ORMExecuteState.lazy_loaded_from�s��� � �2�2�2r�c�@�|j�}|�|jSy)z�Return the :class:`.PathRegistry` for the current load path.

        This object represents the "path" in a query along relationships
        when a particular object or collection is being loaded.

        N)r �
_current_pathrs  r��loader_strategy_pathz$ORMExecuteState.loader_strategy_path�s'���(�(�*�����%�%�%�r�c�F�|j�}|duxr|jS)aqReturn True if the operation is refreshing column-oriented
        attributes on an existing ORM object.

        This occurs during operations such as :meth:`_orm.Session.refresh`,
        as well as when an attribute deferred by :func:`_orm.defer` is
        being loaded, or an attribute that was expired either directly
        by :meth:`_orm.Session.expire` or via a commit operation is being
        loaded.

        Handlers will very likely not want to add any options to queries
        when such an operation is occurring as the query should be a straight
        primary key fetch which should not have any additional WHERE criteria,
        and loader options travelling with the instance
        will have already been added to the query.

        .. versionadded:: 1.4.0b2

        .. seealso::

            :attr:`_orm.ORMExecuteState.is_relationship_load`

        N)r �_for_refresh_staters  r��is_column_loadzORMExecuteState.is_column_load�s(��0�(�(�*���4��;�D�$;�$;�;r�c�f�|j�}|�y|j}|duxr
|jS)azReturn True if this load is loading objects on behalf of a
        relationship.

        This means, the loader in effect is either a LazyLoader,
        SelectInLoader, SubqueryLoader, or similar, and the entire
        SELECT statement being emitted is on behalf of a relationship
        load.

        Handlers will very likely not want to add any options to queries
        when such an operation is occurring, as loader options are already
        capable of being propagated to relationship loaders and should
        be already present.

        .. seealso::

            :attr:`_orm.ORMExecuteState.is_column_load`

        NF)r r'�is_root)r�r�paths   r��is_relationship_loadz$ORMExecuteState.is_relationship_load�s<��(�(�(�*���<���(�(���4��4����$4�4r�c��|jstjd��|jj	dt
jj�}|S)z=Return the load_options that will be used for this execution.zRThis ORM execution is not against a SELECT statement so there are no load options.�_sa_orm_load_options)r
r�r�r�r�r�QueryContext�default_load_options)r��los  r�r"zORMExecuteState.load_options�sV���~�~��,�,�0��
�
�"�"�&�&�"�G�$8�$8�$M�$M�
�	��	r�c��|jstjd��|jj	dt
jj�}|S)zNReturn the update_delete_options that will be used for this
        execution.z_This ORM execution is not against an UPDATE or DELETE statement so there are no update options.�_sa_orm_update_options)rr�r�r�r�r�BulkUDCompileState�default_update_options)r��uos  r��update_delete_optionsz%ORMExecuteState.update_delete_optionssW���}�}��,�,�<��
�
�"�"�&�&�$��/�/�F�F�
�	��	r�c��|jjD�cgc]}t|�r|js|��c}Scc}wr�)r��
_with_optionsr%�_is_compile_state�r��opts  r��_non_compile_orm_optionsz(ORMExecuteState._non_compile_orm_options sC���~�~�3�3�
�3���S�!�#�*?�*?�
�3�
�	
��
s� <c�j�|jjD�cgc]}t|�r|��c}Scc}w)zzThe sequence of :class:`.UserDefinedOptions` that have been
        associated with the statement being invoked.

        )r�r;r&r=s  r��user_defined_optionsz$ORMExecuteState.user_defined_options(s;���~�~�3�3�
�3��%�c�*�
�3�
�	
��
s�0)r�r{r�rrr�r�r�rcr�r�r�r�r��%List[_InstanceLevelDispatch[Session]])r�rB)NNNN)
r�zOptional[Executable]r�r�r�z$Optional[OrmExecuteOptionsParameter]r��Optional[_BindArguments]r��Result[Any])r�r�)r�zSequence[Mapper[Any]]�r��bool)rrr�r�)r�zwOptional[Union[context.ORMCompileState.default_compile_options, Type[context.ORMCompileState.default_compile_options]]])r��Optional[InstanceState[Any]])r�zOptional[PathRegistry])r�zaUnion[context.QueryContext.default_load_options, Type[context.QueryContext.default_load_options]])r�z�Union[bulk_persistence.BulkUDCompileState.default_update_options, Type[bulk_persistence.BulkUDCompileState.default_update_options]])r�zSequence[ORMOption])r�zSequence[UserDefinedOption])r�r�r�r��	__slots__�__annotations__r�r�r��propertyr�rr�r�r
rrrrrrr r$r'r*r.r"r9r?rAr�r�r�r~r~
s���
��I���+����0�/�%�'�&�
�-�,�
�#�"��8�7�����8�8�.��.��.�4�	.�
+�.�'�
.�;�.�;�.�4A�
+/�26�BF�37�h
�'�h
�0�h
�@�	h
�
1�h
�
�
h
�T����8�"��"�H�
3��
3��1��1��	(��	(��0��0� �	B��	B��	B��	B��	B��	B��D��D�P��
��,�3��3������<��<�4�5��5�2��
����,��
����.�
��
��	
��	
r�r~c�&�eZdZdZdZ	dZ	dZ	dZy)�SessionTransactionOriginz�indicates the origin of a :class:`.SessionTransaction`.

    This enumeration is present on the
    :attr:`.SessionTransaction.origin` attribute of any
    :class:`.SessionTransaction` object.

    .. versionadded:: 2.0

    rrr9r�N)r�r�r�r��	AUTOBEGIN�BEGIN�BEGIN_NESTED�SUBTRANSACTIONr�r�r�rLrL5s)����I�/�
�E�H��L�F��N�6r�rLc�D�eZdZUdZdZded<ded<ded<d	ed
<ded<d
ed<d
ed<d
ed<ded<ded<	dZded<		d-					d.d�Z						d/d�Ze	d0d��Z
e	d1d��Ze	d1d��Ze
jej fej$�	d-							d2d��Ze
jej fej$�d3d4d��Z	d-			d5d�Zd6d �Zd3d7d!�Zd6d"�Ze
jej fej$�						d8d#��Zd6d$�Ze
jej fej6�d6d%��Ze
jej ej6fej:�d3d9d&��Ze
jej ej>ej6fej:�	d:					d;d'��Z e
jejBej:�d3d<d(��Z"d=d)�Z#d1d*�Z$d1d+�Z%d1d,�Z&y)>r|a�A :class:`.Session`-level transaction.

    :class:`.SessionTransaction` is produced from the
    :meth:`_orm.Session.begin`
    and :meth:`_orm.Session.begin_nested` methods.   It's largely an internal
    object that in modern use provides a context manager for session
    transactions.

    Documentation on interacting with :class:`_orm.SessionTransaction` is
    at: :ref:`unitofwork_transaction`.


    .. versionchanged:: 1.4  The scoping and API methods to work with the
       :class:`_orm.SessionTransaction` object directly have been simplified.

    .. seealso::

        :ref:`unitofwork_transaction`

        :meth:`.Session.begin`

        :meth:`.Session.begin_nested`

        :meth:`.Session.rollback`

        :meth:`.Session.commit`

        :meth:`.Session.in_transaction`

        :meth:`.Session.in_nested_transaction`

        :meth:`.Session.get_transaction`

        :meth:`.Session.get_nested_transaction`


    NzOptional[BaseException]�_rollback_exceptionzKDict[Union[Engine, Connection], Tuple[Connection, Transaction, bool, bool]]�_connectionsr{r��Optional[SessionTransaction]�_parentr��_statez5weakref.WeakKeyDictionary[InstanceState[Any], object]�_new�_deleted�_dirtyz>weakref.WeakKeyDictionary[InstanceState[Any], Tuple[Any, Any]]�
_key_switchesrL�originFrF�nestedc�P�tj|�||_i|_||_|t
jux|_}||_|jtjurtjd��|r)|stjd��|j|_n|t
j ur|�J�|�J�t"j$|_|j)�||j_|jj,j/|j|�y)Nz_This Session has been permanently closed and is unable to handle any more transaction requests.zOCan't start a SAVEPOINT transaction when no existing transaction is in progress)r?�_trans_ctx_checkr�rSrUrLrOr\r[�_close_state�_SessionCloseStater�r�r��_nested_transaction�_previous_nested_transactionrPr�r�rV�_take_snapshot�_transaction�dispatch�after_transaction_create)r�r�r[�parentr\s     r�r�zSessionTransaction.__init__�s��	�-�-�g�6����������%�)A�)N�)N�N�N���f�������#5�#<�#<�<��,�,�;��
�
���0�0�1���
18�0K�0K�D�-�
�/�>�>�
>��%�%�%��>�!�>�-�4�4�������%)����!������6�6�t�|�|�T�Jr�c��|tjurE|jr$tjd|j��d���tj
d��|tjurtjd��|tjurtj
dd���tj
d|jj��d	���)
Nz�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: �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.zThis transaction is closedzVThis session is provisioning a new connection; concurrent operations are not permitted�iscezThis session is in 'z?' state; no further SQL can be emitted within this transaction.)r�r�rRr��PendingRollbackErrorr�r��ResourceClosedErrorr��name�lower)r��operation_namer!s   r��_raise_for_prerequisite_statez0SessionTransaction._raise_for_prerequisite_state�s����+�4�4�4��'�'��1�1�0�15�0H�0H�/I�	K�
 �
���0�0�>���
�-�4�4�
4��,�,�-I�J�J�
�-�E�E�
E��,�,�/���
��,�,�&�u�z�z�'7�'7�'9�&:�;F�F��
r�c��|jS)aaThe 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"
        (an internal marker object used by the flush process) 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.

        )rUr�s r�rgzSessionTransaction.parent�s���|�|�r�c�Z�|jduxr|jtjuSr�)r�rVr�r�r�s r��	is_activezSessionTransaction.is_active�s-��
�L�L��$�
>����6�=�=�=�	
r�c�8�|jxs
|jSr�)r\rUr�s r��_is_transaction_boundaryz+SessionTransaction._is_transaction_boundarys���{�{�.�$�,�,�.�.r�c�`�|jj|fi|��}|j||�Sr�)r��get_bind�_connection_for_bind)r��bindkeyr��kwargs�binds     r��
connectionzSessionTransaction.connections3��%�t�|�|�$�$�W�7��7���(�(��/@�A�Ar�c�z�t|j|rtj|�Stj|�Sr�)r|r�rLrOrP)r�r\s  r��_beginzSessionTransaction._beginsE��"��L�L��)�5�5�
�
�	
�
.�<�<��
�	
r�c��|}d}|rJ||fz
}|j|ur	|S|j�tjd|z��|j}|r�J|S)Nr�z4Transaction %s is not on the active transaction list)rUr�r�)r��upto�currentrs    r��_iterate_self_and_parentsz,SessionTransaction._iterate_self_and_parentsst����13����w�j� �F����$�&���
����(��0�0�J�����
"�/�/����
r�c�J�|jsU|j}|�J�|j|_|j|_|j|_|j
|_y|jtjtjfv}|s0|jjs|jj�tj�|_tj�|_tj�|_tj�|_yr�)rvrUrWrXrYrZr[rLrNrMr��	_flushing�flush�weakref�WeakKeyDictionary)r�rg�is_begins   r�rcz!SessionTransaction._take_snapshot2s����,�,��\�\�F��%�%�%����D�I�"�O�O�D�M� �-�-�D�K�!'�!5�!5�D����;�;�$�*�*�$�.�.�#
�
������ 6� 6��L�L��� ��-�-�/��	��1�1�3��
��/�/�1���$�6�6�8��r�c��|jsJ�t|j�j|jj�}|jj|d��|jj�D]^\}\}}|jjj|�||_
||vs�:|jjj|��`t|j�j|jj�D]}|jj|d���!|jjrJ�|jjj�D]Y}|r|js||j vs� |j#|j$|jjj&��[y)zmRestore the restoration state taken before a transaction began.

        Corresponds to a rollback.

        T��to_transient)�revert_deletionN)rvr�rWr�r��_expunge_statesrZ�items�identity_map�safe_discard�key�replacerX�_update_impl�
all_states�modifiedrY�_expirer��	_modified)r��
dirty_only�
to_expunge�s�oldkey�newkeys      r��_restore_snapshotz$SessionTransaction._restore_snapshotHs^���,�,�,�,�����^�)�)�$�,�,�*;�*;�<�
����$�$�Z�d�$�C�#'�#5�#5�#;�#;�#=��A����
�L�L�%�%�2�2�1�5��A�E��
�"����)�)�1�1�!�4�$>��T�]�]�#�)�)�$�,�,�*?�*?�@�A��L�L�%�%�a��%�>�A��<�<�(�(�(�(����*�*�5�5�7�A�����q�D�K�K�/?��	�	�!�&�&�$�,�,�";�";�"E�"E�F�8r�c�<�|jsJ�|js�|jjr�|jjj�D]<}|j
|j|jjj��>tjjt|j�|j�|jj�y|jr�|j}|�J�|j j#|j �|j$j#|j$�|jj#|j�|j&j#|j&�yy)zjRemove the restoration state taken before a transaction began.

        Corresponds to a commit.

        N)rvr\r��expire_on_commitr�r�r�r�r��statelibr4�_detach_statesr�rX�clearrUrWr�rYrZ)r�r�rgs   r��_remove_snapshotz#SessionTransaction._remove_snapshoths���,�,�,�,��{�{�t�|�|�<�<��\�\�.�.�9�9�;���	�	�!�&�&�$�,�,�";�";�"E�"E�F�<�
�"�"�1�1��T�]�]�#�T�\�\�
�
�M�M���!�
�[�[��\�\�F��%�%�%��K�K���t�y�y�)��M�M� � ����-��O�O�"�"�4�=�=�1�� � �'�'��(:�(:�;�
r�c���||jvr)|rtjd�|j|dStj|_d}d}	|jr?|jj||�}|jsr|tj|_St|tj�r/|}|j|jvr'tjd��|j�}d}	|r|j di|��}|j"j$r|j�|j'�}n�|jr|j)�}n�|j+�r�|j"j,}|dk(r0|j/�rd}nd}|rtjd	|�d
��|dvr9|j/�r|j1�}n|j3�}|dk(r0d}n-|dk(r|j)�}nJ|��|j5�}t|tj�}||||fx|j|<|j|j<|j"j6j9|j"||�|tj|_S#|r|j;��xYw#tj|_wxYw)
NzOConnection is already established for the given bind; execution_options ignoredrFTzMSession already has a Connection associated for the given Connection's Enginer�r�r�z�The engine provided as bind produced a connection that is already in a transaction. This is usually caused by a core event, such as 'engine_connect', that has left a transaction open. The effective join transaction mode used by this session is z9. To silence this warning, do not leave transactions open)r�r�r�)rSr<�warnr�r�rVrUryr\r�r�r:r=r�r��connectr�r��twophase�begin_twophase�begin_nested�in_transaction�join_transaction_mode�in_nested_transaction� _get_required_nested_transaction�_get_required_transaction�beginre�after_begin�close)	r�r|r��
local_connect�
should_commit�conn�transactionr��bind_is_connections	         r�ryz'SessionTransaction._connection_for_bind�s����4�$�$�$� ��	�	�<���$�$�T�*�1�-�-�-�E�E����
��
�X	9��|�|��|�|�8�8��+����{�{��d2�8�8�D�K�a�d�F�$5�$5�6��D��{�{�d�&7�&7�7�$�8�8�@���
 �<�<�>�D�$(�M�C
�$�1�4�1�1�F�4E�F�D��<�<�(�(�T�\�\�-A�
#'�"5�"5�"7�K��[�[�"&�"3�"3�"5�K��(�(�*�,0�L�L�,N�,N�)�,�0G�G��5�5�7�4F�1�4C�1�(� �I�I�!L�$9�";�<J�
!J�	�-�1�� �5�5�7� $� E� E� G�(�+/�*H�*H�*J�K�0�O�C�,1�M�.�2D�D�&*�&7�&7�&9��;�&;�;�u�"&�*�*�,�K�&0��f�6G�6G�%H�"���!�*�*�	L���!�!�$�'�$�*;�*;�D�K�K�*H����%�%�1�1�$�,�,��d�K��1�8�8�D�K��%
�!��J�J�L���2�8�8�D�K�s-�5K	�AK	�9D)J1�"A9K	�1K�K	�	K c��|j�|jjstjd��|j�y)NzD'twophase' mode not enabled, or not root transaction; can't prepare.)rUr�r�r�r��
_prepare_implr�s r��preparezSessionTransaction.prepare�s>���<�<�#�4�<�<�+@�+@��,�,�!��
�	
���r�c�|�|j�|jr/|jjj	|j�|jj
}|�J�||ur'|j
|��D]}|j��|jjs[td�D]8}|jj�rn1|jj��:tjd��|j�]|jjrG	t|j j#��D]}t%d|d�j'��!	t.j0|_y#t)j*�5|j-�ddd�n#1swYnxYwY�TxYw)N�r��dzrOver 100 subsequent flushes have occurred within session.commit() - is an after_flush() hook creating new objects?r`r)rUr\r�re�
before_commitrdr��commitr��range�	_is_cleanr�r�
FlushErrorr�r�rS�valuesrr�r<�safe_reraise�rollbackr�r�rV)r��stx�subtransaction�_flush_guard�ts     r�r�z SessionTransaction._prepare_impl�sV���<�<��4�;�;��L�L�!�!�/�/����=��l�l�'�'�������d�?�"%�"?�"?�T�"?�"J���%�%�'�#K��|�|�%�%� %�c�
���<�<�)�)�+�����"�"�$�!+�
�n�n�,����<�<��D�L�L�$9�$9�
$��T�.�.�5�5�7�8�A��.��!��5�=�=�?�9�.�6�6����	
$��&�&�(��M�M�O�)�(�(�s%�!AE=�=F;�F-�$	F;�-F6	�2F;c��|jtjur8|jtj�5|j	�ddd�|j
�|jr�t|jj��D]\}}}}|s�|j��tj|_|jjj|j�|j�|jtj �5|j#�ddd�|r*|j
r|j
jd��yyy#1swY��xYw#1swY�CxYw)NT��_to_root)rVr�r��
_expect_stater�rUr\r�rSr�r�r�r�re�after_commitr�r�r�)r�r�r��transr��	autocloses      r�r�zSessionTransaction.commits��
�;�;�5�>�>�>��#�#�$;�$D�$D�E��"�"�$�F��<�<��4�;�;�9<��!�!�(�(�*�:�5��e�]�I�!��L�L�N�	:�2�;�;�D�K��L�L�!�!�.�.�t�|�|�<��!�!�#�
�
�
� 7� >� >�
?��J�J�L�@������L�L�����.�%�8�%F�E��@�
?�s�E&� E3�&E0�3E<c���|jj}|�J�||ur'|j|��D]}|j��|}d}|jt
jt
jfvr�|j�D]�}|j�|jr�	t|jj��D]}|dj��t
j|_|jjj!|j�t
j|_|j'|j��|}nt
j|_��|j}	|sA|	j)�s1t+j,d�|j'|j��|j/t
j0�5|j�ddd�|jr(|r&t#j$�d|j_|r|dr|dj5|d��|	jj7|	|�|r*|jr|jjd��yyy#t#j$�}Y���xYw#t
j|_|j'|j��wxYw#1swY��xYw)Nr�r)r�z\Session's state has been changed on a non-active transaction - this state will be discarded.r9Tr�)r�rdr�r�rVr�r�r�rUr\r�rSr�r�r�re�after_rollback�sys�exc_infor�r�r<r�r�r�rR�with_traceback�after_soft_rollback)
r��_capture_exceptionr�r�r��boundary�rollback_errr�r��sesss
          r�r�zSessionTransaction.rollback5sp���l�l�'�'�������d�?�"%�"?�"?�T�"?�"J���$�$�&�#K������;�;�#�*�*�#�,�,�
�
� $�=�=�?���&�&�.�+�2D�2D��!$�[�%=�%=�%D�%D�%F�!G�A��a�D�M�M�O�"H�.E�-M�-M��*����-�-�<�<�T�\�\�J�.E�-M�-M��*�#�5�5�'2�'9�'9�6�� +�H��)@�)I�)I�K�&�% @�(�|�|���D�N�N�$4�
�I�I�%�
�

�&�&�(�/�/�&�B�
�
�
� 7� >� >�
?��J�J�L�@��<�<�.�/2�|�|�~�a�/@�D�L�L�,��L��O��q�/�0�0��a��A�A��
�
�)�)�$��5������L�L�!�!�4�!�0�%�8��G6�'*�|�|�~���-D�-M�-M��*�#�5�5�'2�'9�'9�6���(@�
?�s%�"A?J�K!�J(�%J+�+3K�!K*c��|jr|j|j_|j|j_t
|jj��D]c\}}}}|r|j�|j�|r|jr|j�|s�G|j��T|j��etj|_|j}|jj!||�yr�)r\rbr�rarUrdr�rSr��
invalidatertr�r�r�rVre�after_transaction_end)r�r�r}r�r�r�r�s       r�r�zSessionTransaction.closezs����;�;��1�1�
�L�L�,�%)�L�L����!�AD����$�$�&�B
�=�J��]�I��d�l�l�2��%�%�'���!6�!6��!�!�#��T�\�\�1�� � �"�B
�.�4�4����|�|��	
�
�
�+�+�D�$�7r�c��|jSr�r�r�s r��_get_subjectzSessionTransaction._get_subject�s���|�|�r�c�:�|jtjuSr�)rVr�r�r�s r��_transaction_is_activez)SessionTransaction._transaction_is_active�����{�{�5�<�<�<�<r�c�:�|jtjuSr�)rVr�r�r�s r��_transaction_is_closedz)SessionTransaction._transaction_is_closed�r�r�c�2�|jttfvSr�)rVr�r�r�s r��_rollback_can_be_calledz*SessionTransaction._rollback_can_be_called�s���{�{�9�f�"5�5�5r�r�)r�r{r[rLrgrT)rp�strr!r6r�r
�r�rTrE)rzr�r�r�r{rr�r=�F�r\rFr�r|)r�rTr�zIterable[SessionTransaction]r�)r�rFr�r�)r|�_SessionBindr��%Optional[CoreExecuteOptionsParameter]r�r=)r�rFr�r��FF)r�rFr�rFr�r�)r�rFr�r�)r�r{)'r�r�r�r�rRrIr\r�rqrJrgrtrvr5�declare_statesr�r�r7�	NO_CHANGEr}rr�rcr�r�ryr�r�r�r�r�r�r��ANYr�r�r�r�r�r�r�r�r|r|MsB��$�L48��0�7�����
)�)�#�#�
?�?�C�C�A�A���
%�$���F�D��
� 04�	)K��)K�)�)K�-�	)K�V�!��*;��	��B���� �
��
��/��/�!�\� � �	 �	'�	'�)�+=�+G�+G��8<�B�&�B�5�B��	B�

�B��B�!�\� � �	 �	'�	'�)�+=�+G�+G��	
��	
�48��0��	%��&9�,G�@<�0!�\� � �	 �	'�	'�)�+=�+G�+G��j9��j9�A�j9�
�	j9��j9�X�!�\� � �	 �	'�	'�)�+B�+K�+K��7��7�@!�\� � �	 �	'�	'�)@�)I�)I�J��&�&��/�	�/�.!�\� � �#�*�*�#�,�,�#�,�,�	
�
	 �&�&�
�BG�;1�"&�;1�:>�;1�	
�;1��;1�z!�\� � ���� 7� >� >��8��8�>�=�=�6r�r|c��eZdZdZdZdZy)r`rr9r�N)r�r�r�r�r��CLOSE_IS_RESETr�r�r�r`r`�s��
�F�
�F��Nr�r`c�~�eZdZUdZdZded<ded<	ded<ded	<d
ed<ded
<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<ded<	d�d!d!d!d!dd d!d d dd"ejd#�																									d�d$�Zd Z	d%ed&<d Z
d'ed(<d�d)�Zd�d*�Ze
jd�d+��Zd�d,�Zd�d-�Zd�d.�Zd�d/�Zej*d�d0��Zd�d�d1�Zd�d�d2�Zd�d3�Zd�d4�Zd�d5�Zd�d6�Z		d�					d�d7�Z	d�							d�d8�Ze	d�ej@d d d d9d:�															d�d;��Z!e	d�ej@d d d d9d:�															d�d<��Z!	d�ej@d d d dd:�															d�d=�Z!e	d�ej@d d d d>�													d�d?��Z"e	d�ej@d d d d>�													d�d@��Z"e	d�ej@d d d d>�													d�dA��Z"	d�ej@d d d d>�													d�dB�Z"e	d�ej@d dC�											d�dD��Z#e	d�ej@d dC�											d�dE��Z#	d�ej@d dC�											d�dF�Z#e	d�ej@d dC�											d�dG��Z$e	d�ej@d dC�											d�dH��Z$	d�ej@d dC�											d�dI�Z$d�dJ�Z%d�dK�Z&d�dL�Z'd�d�dM�Z(d�dN�Z)d�dO�Z*						d�dP�Z+d�dQ�Z,	d�d d d ddR�													d�dS�Z-ed�dT��Z.e				d�dU��Z.e						d�dV��Z.e								d�dW��Z.e										d�dX��Z.e												d�dY��Z.e														d�dZ��Z.e																d�d[��Z.e																		d�d\��Z.e						d�d]��Z.						d�d^�Z.d e/j`d ej@d f															d�d_�Z1ejde
jd�d`���Z3ejhjkdae6jn�d�db��Z8		d�							d�dc�Z9d�dd�Z:	d�					d�de�Z;						d�df�Z<	d�					d�dg�Z=d�dh�Z>	d�					d�di�Z?d�dj�Z@d�dk�ZA				d�dl�ZBd�d�dm�ZCd�dn�ZDd�do�ZEd�dp�ZF								d�dq�ZGd dd d ej@d dr�																	d�ds�ZHd dd d ej@d dr�																	d�dt�ZId dd d ej@d dr�																			d�du�ZJd!d dv�							d�dw�ZKd dx�													d�dy�ZLd�dz�ZMd�d{�ZN	d�					d�d|�ZOd�d}�ZPd�d~�ZQd�d�ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d�d��ZWd�d��ZXd�d��ZYd�d�d��ZZ			d�									d�d��Z[		d�									d�d��Z\						d�d��Z]																d�d��Z^	d�					d�d��Z_e`d�d���Zae`d�d���Zbe`d�d���Zce`d�d���Zde`d�d���Zey )�r{a	Manages persistence operations for ORM-mapped objects.

    The :class:`_orm.Session` is **not safe for use in concurrent threads.**.
    See :ref:`session_faq_threadsafe` for background.

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


    Fzdispatcher[Session]rer2r�zDict[InstanceState[Any], Any]rWrXz#Optional[Union[Engine, Connection]]r|z#Dict[_SessionBindKey, _SessionBind]�_Session__bindsrFr��_warn_on_eventsrTrdrar��hash_key�	autoflushr��enable_baked_queriesr��JoinTransactionModer�zType[Query[Any]]�
_query_clsr`r_NTr�)r��futurer��	autobeginr��bindsr��info�	query_cls�
autocommitr��close_resets_onlyc�6�|rtjd��tj�|_|stjd��i|_i|_||_i|_d|_	d|_
d|_d|_t�|_||_||_||_||_|
dt&j(fvrt*j,|_nt*j0|_|r+|t2j4vrtjd|�d���||_||_|
r|
nt:j<|_|	r|j@jC|	�|�*|jE�D]\}}|jG||��|tH|j<y)a�+Construct a new :class:`_orm.Session`.

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

        :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.

           .. seealso::

               :ref:`session_flushing` - additional background on autoflush

        :param autobegin: Automatically start transactions (i.e. equivalent to
           invoking :meth:`_orm.Session.begin`) when database access is
           requested by an operation.   Defaults to ``True``.    Set to
           ``False`` to prevent a :class:`_orm.Session` from implicitly
           beginning transactions after construction, as well as after any of
           the :meth:`_orm.Session.rollback`, :meth:`_orm.Session.commit`,
           or :meth:`_orm.Session.close` methods are called.

           .. versionadded:: 2.0

           .. seealso::

                :ref:`session_autobegin_disable`

        :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+psycopg2://engine1"),
                    SomeDeclarativeBase: create_engine(
                        "postgresql+psycopg2://engine2"
                    ),
                    some_mapper: create_engine("postgresql+psycopg2://engine3"),
                    some_table: create_engine("postgresql+psycopg2://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: legacy; defaults to ``True``.
           A parameter 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``, caching as used by
           this particular extension is disabled.

           .. versionchanged:: 1.4 The ``sqlalchemy.ext.baked`` extension is
              legacy and is not used by any of SQLAlchemy's internals. This
              flag therefore only affects applications that are making explicit
              use of this extension within their own code.

        :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 future: Deprecated; this flag is always True.

          .. seealso::

            :ref:`migration_20_toplevel`

        :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`.

        :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 autocommit: the "autocommit" keyword is present for backwards
            compatibility but must remain at its default value of ``False``.

        :param join_transaction_mode: Describes the transactional behavior to
          take when a given bind is a :class:`_engine.Connection` that
          has already begun a transaction outside the scope of this
          :class:`_orm.Session`; in other words the
          :meth:`_engine.Connection.in_transaction()` method returns True.

          The following behaviors only take effect when the :class:`_orm.Session`
          **actually makes use of the connection given**; that is, a method
          such as :meth:`_orm.Session.execute`, :meth:`_orm.Session.connection`,
          etc. are actually invoked:

          * ``"conditional_savepoint"`` - this is the default.  if the given
            :class:`_engine.Connection` is begun within a transaction but
            does not have a SAVEPOINT, then ``"rollback_only"`` is used.
            If the :class:`_engine.Connection` is additionally within
            a SAVEPOINT, in other words
            :meth:`_engine.Connection.in_nested_transaction()` method returns
            True, then ``"create_savepoint"`` is used.

            ``"conditional_savepoint"`` behavior attempts to make use of
            savepoints in order to keep the state of the existing transaction
            unchanged, but only if there is already a savepoint in progress;
            otherwise, it is not assumed that the backend in use has adequate
            support for SAVEPOINT, as availability of this feature varies.
            ``"conditional_savepoint"`` also seeks to establish approximate
            backwards compatibility with previous :class:`_orm.Session`
            behavior, for applications that are not setting a specific mode. It
            is recommended that one of the explicit settings be used.

          * ``"create_savepoint"`` - the :class:`_orm.Session` will use
            :meth:`_engine.Connection.begin_nested()` in all cases to create
            its own transaction.  This transaction by its nature rides
            "on top" of any existing transaction that's opened on the given
            :class:`_engine.Connection`; if the underlying database and
            the driver in use has full, non-broken support for SAVEPOINT, the
            external transaction will remain unaffected throughout the
            lifespan of the :class:`_orm.Session`.

            The ``"create_savepoint"`` mode is the most useful for integrating
            a :class:`_orm.Session` into a test suite where an externally
            initiated transaction should remain unaffected; however, it relies
            on proper SAVEPOINT support from the underlying driver and
            database.

            .. tip:: When using SQLite, the SQLite driver included through
               Python 3.11 does not handle SAVEPOINTs correctly in all cases
               without workarounds. See the sections
               :ref:`pysqlite_serializable` and :ref:`aiosqlite_serializable`
               for details on current workarounds.

          * ``"control_fully"`` - the :class:`_orm.Session` will take
            control of the given transaction as its own;
            :meth:`_orm.Session.commit` will call ``.commit()`` on the
            transaction, :meth:`_orm.Session.rollback` will call
            ``.rollback()`` on the transaction, :meth:`_orm.Session.close` will
            call ``.rollback`` on the transaction.

            .. tip:: This mode of use is equivalent to how SQLAlchemy 1.4 would
               handle a :class:`_engine.Connection` given with an existing
               SAVEPOINT (i.e. :meth:`_engine.Connection.begin_nested`); the
               :class:`_orm.Session` would take full control of the existing
               SAVEPOINT.

          * ``"rollback_only"`` - the :class:`_orm.Session` will take control
            of the given transaction for ``.rollback()`` calls only;
            ``.commit()`` calls will not be propagated to the given
            transaction.  ``.close()`` calls will have no effect on the
            given transaction.

            .. tip:: This mode of use is equivalent to how SQLAlchemy 1.4 would
               handle a :class:`_engine.Connection` given with an existing
               regular database transaction (i.e.
               :meth:`_engine.Connection.begin`); the :class:`_orm.Session`
               would propagate :meth:`_orm.Session.rollback` calls to the
               underlying transaction, but not :meth:`_orm.Session.commit` or
               :meth:`_orm.Session.close` calls.

          .. versionadded:: 2.0.0rc1

        :param close_resets_only: Defaults to ``True``. Determines if
          the session should reset itself after calling ``.close()``
          or should pass in a no longer usable state, disabling re-use.

          .. versionadded:: 2.0.22 added flag ``close_resets_only``.
            A future SQLAlchemy version may change the default value of
            this flag to ``False``.

          .. seealso::

            :ref:`session_closing` - Detail on the semantics of
            :meth:`_orm.Session.close` and :meth:`_orm.Session.reset`.

        z&autocommit=True is no longer supportedzCThe 'future' parameter passed to Session() may only be set to True.FNTz.invalid selection for join_transaction_mode: "�")%r��
ArgumentErrorr�WeakInstanceDictr�rWrXr|r�r�r�rdra�_new_sessionidr�r�r�r�r�rJ�NO_ARGr`r�r_r�r��__args__r�r�rr3r�r�r�r��	_add_bindr�)r�r|r�r�r�r�r�r�r�r�r�rr�rr�s               r�r�zSession.__init__�s���n��&�&�8��
�%�5�5�7�����&�&�5��
�
��	���
���	�������$��� ���#'�� �&�(��
�"���"��� 0���$8��!���v�}�}� 5�5� 2� A� A�D�� 2� 9� 9�D��!�%�&�/�/�0��&�&��)�*�!�-��
�&;��"� ��
�'0�)�e�k�k�����I�I���T�"���"�[�[�]�	��T����s�D�)�+�$(�	�$�-�-� r�zOptional[TransactionalContext]�_trans_context_managerz"Optional[_ConnectionCallableProto]�connection_callablec��|Sr�r�r�s r��	__enter__zSession.__enter__s���r�c�$�|j�yr�)r�)r��type_�value�	tracebacks    r��__exit__zSession.__exit__s���
�
�r�c#�K�|5|j�5|��ddd�ddd�y#1swY�xYw#1swYyxYw�wr��r�r�s r��_maker_context_managerzSession._maker_context_managers0����
������
���T�����T�s(�A�8�,�8�	A�5	�8�A�Ac��|jduS)z�Return True if this :class:`_orm.Session` has begun a transaction.

        .. versionadded:: 1.4

        .. seealso::

            :attr:`_orm.Session.is_active`


        N)rdr�s r�r�zSession.in_transactions��� � ��,�,r�c��|jduS)z�Return True if this :class:`_orm.Session` has begun a nested
        transaction, e.g. SAVEPOINT.

        .. versionadded:: 1.4

        N�rar�s r�r�zSession.in_nested_transaction(s���'�'�t�3�3r�c�p�|j}|�'|j�|j}|�
|j��|S)zaReturn the current root transaction in progress, if any.

        .. versionadded:: 1.4

        )rdrU�r�r�s  r��get_transactionzSession.get_transaction1s=���!�!����E�M�M�$=��M�M�E���E�M�M�$=��r�c��|jS)zcReturn the current nested transaction in progress, if any.

        .. versionadded:: 1.4

        rr�s r��get_nested_transactionzSession.get_nested_transaction<s���'�'�'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.

        r�r�s r�r�zSession.infoEs	���	r�c���|j�a|s!|jstjd��t	||rt
jnt
j�}|j|usJ�|S|jS)Nz]Autobegin is disabled on this Session; please call session.begin() to start a new transaction)rdr�r�r�r|rLrNrM)r�r�r�s   r��_autobegin_tzSession._autobegin_tRs�����$������0�0�A���'���-�2�2�1�;�;��E��$�$��-�-�-��L�� � � r�c���|j}|�|jd��}|s|S|�J�|r+|j|��}|j|usJ�||_|St	j
d��)a�Begin a transaction, or nested transaction,
        on this :class:`.Session`, if one is not already begun.

        The :class:`_orm.Session` object features **autobegin** behavior,
        so that normally it is not necessary to call the
        :meth:`_orm.Session.begin`
        method explicitly. However, it may be used in order to control
        the scope of when the transactional state is begun.

        When used to begin the outermost transaction, an error is raised
        if this :class:`.Session` is already inside of a transaction.

        :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_explicit_begin` for
         an example.

        .. seealso::

            :ref:`session_autobegin`

            :ref:`unitofwork_transaction`

            :meth:`.Session.begin_nested`


        Tr�r\z/A transaction is already begun on this Session.)rdr rrar�r�)r�r\r�s   r�r�z
Session.beginfs���F�!�!���=��%�%�D�%�1�E����� � � ���L�L��L�/�E��$�$��-�-�-�',�D�$���	�,�,�A��
r�c�&�|jd��S)atBegin 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. For asyncio use cases, see the section
            :ref:`aiosqlite_serializable`.

        Tr"rr�s r�r�zSession.begin_nested�s��0�z�z��z�&�&r�c�V�|j�y|jjd��y)a{Rollback the current transaction in progress.

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

        The method always rolls back
        the topmost database transaction, discarding any nested
        transactions that may be in progress.

        .. seealso::

            :ref:`session_rollback`

            :ref:`unitofwork_transaction`

        NTr�)rdr�r�s r�r�zSession.rollback�s*�� ���$�����&�&��&�5r�c�d�|j}|�|j�}|jd��y)aeFlush pending changes and commit the current transaction.

        When the COMMIT operation is complete, all objects are fully
        :term:`expired`, erasing their internal contents, which will be
        automatically re-loaded when the objects are next accessed. In the
        interim, these objects are in an expired state and will not function if
        they are :term:`detached` from the :class:`.Session`. Additionally,
        this re-load operation is not supported when using asyncio-oriented
        APIs. The :paramref:`.Session.expire_on_commit` parameter may be used
        to disable this behavior.

        When there is no transaction in place for the :class:`.Session`,
        indicating that no operations were invoked on this :class:`.Session`
        since the previous call to :meth:`.Session.commit`, the method will
        begin and commit an internal-only "logical" transaction, that does not
        normally affect the database unless pending flush changes were
        detected, but will still invoke event handlers and object expiration
        rules.

        The outermost database transaction is committed unconditionally,
        automatically releasing any SAVEPOINTs in effect.

        .. seealso::

            :ref:`session_committing`

            :ref:`unitofwork_transaction`

            :ref:`asyncio_orm_avoid_lazyloads`

        NTr�)rdr r�rs  r�r�zSession.commit�s1��@�!�!���=��%�%�'�E�
���d��#r�c�`�|j}|�|j�}|j�y)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.

        N)rdr r�rs  r�r�zSession.prepare�s+���!�!���=��%�%�'�E�
�
�
�r�c��|r'|jdd�}|�#|jdi|��}n|j�}|j||��S)a"Return a :class:`_engine.Connection` object corresponding to this
        :class:`.Session` object's transactional state.

        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).

        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_arguments: dictionary of bind arguments.  May include
         "mapper", "bind", "clause", other custom arguments that are passed
         to :meth:`.Session.get_bind`.

        :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.

         .. seealso::

            :ref:`session_transaction_isolation`

        r|N�r�r�)�poprxry)r�r�r�r|s    r�r}zSession.connections[��F�!�%�%�f�d�3�D��|�$�t�}�}�6�~�6���=�=�?�D��(�(��/�)�
�	
r�c��tj|�|j}|�|j�}|j	||�Sr�)r?r^rdr ry)r�r:r�r�r�s     r�ryzSession._connection_for_bind3sD��	�-�-�d�3��!�!���=��%�%�'�E��)�)�&�2C�D�Dr�.)r�r�r��
_add_event�_scalar_resultc��yr�r��r�r�r�r�r�r�r+r,s        r�r�zSession._execute_internal@s��r�c��yr�r�r.s        r�r�zSession._execute_internalMs��r�c	�T�tjtj|�}|si}nt	|�}|j
j
dd�dk(r8tj|d�}tr0t|tj�sJ�d}|jd|�tj|�}|r|j!�}	n'|j"j$}	|rt'|	�|gz}	|	r�|�|j)|||||d�\}}t+|||||||	�}
t-|	�D].\}}||
_||
�}
|
s�|r|
j1�cS|
cS|
j2}|
j4}|�|j)|||||d�\}}|j6di|��}|j9|�}|r0|s.trt;t<|�}|j1||xsi|��S|r|j?|||xsi|||�}n|jA||xsi|��}|r|j1�S|S)N�compile_state_plugin�orm�clauseTFr(r�)!rD�expectrF�
StatementRoler��_propagate_attrsr�rK�_get_plugin_class_for_pluginrr�r�AbstractORMCompileState�
setdefaultr<�coerce_to_immutabledictr�re�do_orm_executer��orm_pre_session_execr~�	enumerater��scalarr�r�rxryrrb�orm_execute_statement�execute)r�r�r�r�r�r�r+r,r�r��orm_exec_state�idx�fn�	fn_resultr|r�rs                 r�r�zSession._execute_internalZs����$�$�U�%8�%8�)�D�	���N�!�.�1�N�
�&�&�*�*�+A�4�H��
�!-� I� I��5�!���!�%�w�'F�'F����!%���%�%�h�	�:� �8�8�9J�K�� �/�A�A�C�K��-�-�6�6�K��"�;�/�:�,�>��� �,�&�:�:����%�"��
���%�-����!��!���N�%�[�1���R�58��2�35�n�3E�	��%�(�/�/�1�1�(�(�2�'�0�0�I� .� F� F���(�"�6�6����!���
�
��!��t�}�}�.�~�.���(�(��.���"3���6��?���;�;��6�<�R�;L���
��"3�"I�"I�����"�!���
#�F��\�\��6�<�R�;L�"��F���=�=�?�"��Mr��r�r�r�r+c��yr�r��r�r�r�r�r�r�r+s       r�r@zSession.execute�s��r�c��yr�r�rGs       r�r@zSession.execute�s�� r�c��yr�r�rGs       r�r@zSession.execute�s��r�c�0�|j||||||��S)a�Execute a SQL expression construct.

        Returns a :class:`_engine.Result` object representing
        results of the statement execution.

        E.g.::

            from sqlalchemy import select

            result = session.execute(select(User).where(User.id == 5))

        The API contract of :meth:`_orm.Session.execute` is similar to that
        of :meth:`_engine.Connection.execute`, the :term:`2.0 style` version
        of :class:`_engine.Connection`.

        .. versionchanged:: 1.4 the :meth:`_orm.Session.execute` method is
           now the primary point of ORM statement execution when using
           :term:`2.0 style` ORM usage.

        :param statement:
            An executable statement (i.e. an :class:`.Executable` expression
            such as :func:`_expression.select`).

        :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 execution_options: optional dictionary of execution options,
         which will be associated with the statement execution.  This
         dictionary can provide a subset of the options that are accepted
         by :meth:`_engine.Connection.execution_options`, and may also
         provide additional options understood only in an ORM context.

         .. seealso::

            :ref:`orm_queryguide_execution_options` - ORM-specific execution
            options

        :param bind_arguments: dictionary of additional arguments to determine
         the bind.  May include "mapper", "bind", or other custom arguments.
         Contents of this dictionary are passed to the
         :meth:`.Session.get_bind` method.

        :return: a :class:`_engine.Result` object.


        rE�r�rGs       r�r@zSession.execute	s/��x�%�%���/�)�"7�!�
&�
�	
r�)r�r�c��yr�r��r�r�r�r�r�r�s      r�r>zSession.scalarF	s��r�c��yr�r�rMs      r�r>zSession.scalarQ	s��r�c�2�|j||f||dd�|��S)z�Execute a statement and return a scalar result.

        Usage and parameters are the same as that of
        :meth:`_orm.Session.execute`; the return result is a scalar Python
        value.

        T)r�r�r,rKrMs      r�r>zSession.scalar\	s9��"&�t�%�%���
�0�)��
��

�	
r�c��yr�r�rMs      r��scalarszSession.scalarsv	s��r�c��yr�r�rMs      r�rQzSession.scalars�	s�� r�c�N�|j|f|||dd�|��j�S)a�Execute a statement and return the results as scalars.

        Usage and parameters are the same as that of
        :meth:`_orm.Session.execute`; the return result is a
        :class:`_result.ScalarResult` filtering object which
        will return single elements rather than :class:`_row.Row` objects.

        :return:  a :class:`_result.ScalarResult` object

        .. versionadded:: 1.4.24 Added :meth:`_orm.Session.scalars`

        .. versionadded:: 1.4.26 Added :meth:`_orm.scoped_session.scalars`

        .. seealso::

            :ref:`orm_queryguide_select_orm_entities` - contrasts the behavior
            of :meth:`_orm.Session.execute` to :meth:`_orm.Session.scalars`

        F)r�r�r�r,)r�rQrMs      r�rQzSession.scalars�	s@��:&�t�%�%��
��/�)� �
��

��'�)�	r�c�(�|jd��y)a�Close out the transactional resources and ORM objects used by this
        :class:`_orm.Session`.

        This expunges all ORM objects associated with this
        :class:`_orm.Session`, ends any transaction in progress and
        :term:`releases` any :class:`_engine.Connection` objects which this
        :class:`_orm.Session` itself has checked out from associated
        :class:`_engine.Engine` objects. The operation then leaves the
        :class:`_orm.Session` in a state which it may be used again.

        .. tip::

            In the default running mode the :meth:`_orm.Session.close`
            method **does not prevent the Session from being used again**.
            The :class:`_orm.Session` itself does not actually have a
            distinct "closed" state; it merely means
            the :class:`_orm.Session` will release all database connections
            and ORM objects.

            Setting the parameter :paramref:`_orm.Session.close_resets_only`
            to ``False`` will instead make the ``close`` final, meaning that
            any further action on the session will be forbidden.

        .. versionchanged:: 1.4  The :meth:`.Session.close` method does not
           immediately create a new :class:`.SessionTransaction` object;
           instead, the new :class:`.SessionTransaction` is created only if
           the :class:`.Session` is used again for a database operation.

        .. seealso::

            :ref:`session_closing` - detail on the semantics of
            :meth:`_orm.Session.close` and :meth:`_orm.Session.reset`.

            :meth:`_orm.Session.reset` - a similar method that behaves like
            ``close()`` with  the parameter
            :paramref:`_orm.Session.close_resets_only` set to ``True``.

        F�r�N��_close_implr�s r�r�z
Session.close�	s��N	
���E��*r�c�*�|jdd��y)aClose out the transactional resources and ORM objects used by this
        :class:`_orm.Session`, resetting the session to its initial state.

        This method provides for same "reset-only" behavior that the
        :meth:`_orm.Session.close` method has provided historically, where the
        state of the :class:`_orm.Session` is reset as though the object were
        brand new, and ready to be used again.
        This method may then be useful for :class:`_orm.Session` objects
        which set :paramref:`_orm.Session.close_resets_only` to ``False``,
        so that "reset only" behavior is still available.

        .. versionadded:: 2.0.22

        .. seealso::

            :ref:`session_closing` - detail on the semantics of
            :meth:`_orm.Session.close` and :meth:`_orm.Session.reset`.

            :meth:`_orm.Session.close` - a similar method will additionally
            prevent re-use of the Session when the parameter
            :paramref:`_orm.Session.close_resets_only` is set to ``False``.
        FT)r��is_resetNrVr�s r��resetz
Session.reset�	s��.	
���E�D��9r�c�(�|jd��y)a�Close 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 each :class:`_engine.Connection` object
        that is currently in use for a transaction (typically there is only
        one connection unless the :class:`_orm.Session` is used with
        multiple engines).

        This can be called when the database is known to be in a state where
        the connections are no longer safe to be used.

        Below illustrates a scenario when using `gevent
        <https://www.gevent.org/>`_, which can produce ``Timeout`` exceptions
        that may mean the underlying connection should be discarded::

            import gevent

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

        The method additionally does everything that :meth:`_orm.Session.close`
        does, including that all ORM objects are expunged.

        TrUNrVr�s r�r�zSession.invalidate�	s��D	
���D��)r�c��|s1|jtjurtj|_|j	�|j
�1|j
j
�D]}|j|��yyr�)r_r`r�r��expunge_allrdr�r�)r�r�rYr�s    r�rWzSession._close_impl
sl���D�-�-�1C�1J�1J�J� 2� 9� 9�D���������(�#�0�0�J�J�L���!�!�*�-� M�)r�c�&�|jj�t|j�z}|jj	�tj�|_i|_i|_tjj||�y)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�rW�_killrrrXr�r4r�)r�r�s  r�r]zSession.expunge_all 
sl���&�&�1�1�3�d�4�9�9�o�E�
������!�$�5�5�7�����	���
����-�-�j�$�?r�c���	t|�}trt|t�sJ�t|t�r||j
|<yt
|�r:||j
|j<|jD]}||j
|<�ytjd|z��#tj$rB}t|t�stjd|z�|�||j
|<Yd}~yd}~wwxYw)Nz!Not an acceptable bind target: %s)
rBrr�rCrHr�r#r��_all_tablesr�r�NoInspectionAvailable�type)r�r�r|r�_selectable�errs      r�r	zSession._add_bind0
s���	��3�<�D��!�$��4�4�4��$��,�%)����T�"���%�,0����T�[�[�)�#'�#3�#3�K�04�D�L�L��-�$4��*�*�7�#�=����%�+�+�	)��c�4�(��*�*�7�#�=����%)����S�!��
	)�s�B"�"C7�58C2�2C7c�(�|j||�y)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	)r�r�r|s   r�r�zSession.bind_mapperI
s��8	
���v�t�$r�c�(�|j||�y)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`


        Nrg)r��tabler|s   r��
bind_tablezSession.bind_tableg
s��4	
���u�d�#r�)r3r|r��_sa_skip_for_implicit_returningc�J�|r|S|js|jr|jS|�/|�-|jr|jStjd��|�
	t	|�}nd}|jr�|rH|jjD]!}	|	|jvs�|j|	cS|�|j}|��|jjdd�}
|
�D|
jjjD]!}	|	|jvs�|j|	cSt!j"|�D]9}||jvs�t$rt
|t&�sJ�|j|cS|jr|jSg}|�|j(d|���|�|j(d�tjddj+|��d���#tj
$r,}t
|t�rtj|�|��d}~wwxYw)	aG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 mapped class or corresponding :class:`_orm.Mapper` instance.
          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.�plugin_subjectzmapper zSQL expressionz&Could not locate a bind configured on �, z or this Session.)r�r|r��UnboundExecutionErrorrBrbr�rcr�UnmappedClassErrorr��__mro__�persist_selectabler6r�r�rI�iteraterrLr��join)
r�r�r3r|r�rkr��inspected_mapperrer�rm�objrs
             r�rxzSession.get_bind�
s ��h��K����$�)�)��9�9��
�>�f�n��y�y��y�y� ��2�2�!�����
�#*�6�?� � $���<�<� �+�2�2�:�:�C��d�l�l�*�#�|�|�C�0�0�;��>�-�@�@�F��!�!'�!8�!8�!<�!<�$�d�"��"�-�-�4�4�;�;�C�C���$�,�,�.�#'�<�<��#4�4� D�$�+�+�F�3�C��d�l�l�*�(�#-�c�5�#9�9�#9�#�|�|�C�0�0�	4��9�9��9�9�����'��G�N�N�W�%5�$6�7�8����G�N�N�+�,��*�*�4��y�y��!�"�"3�
5�
�	
��]�/�/�
��f�d�+��0�0��8�c�A���	
�s�G#�#H"�6'H�H"c��yr�r�)r��_entitys  r�rz
Session.query"s��<?r�c��yr�r�)r��_colexprs  r�rz
Session.query%s��(+r�c��yr�r�)r��_Session__ent0�_Session__ent1s   r�rz
Session.query/s��.1r�c��yr�r�)r�r|r}�_Session__ent2s    r�rz
Session.query4s��36r�c��yr�r�)r�r|r}r�_Session__ent3s     r�rz
Session.query9s��8;r�c��yr�r�)r�r|r}rr��_Session__ent4s      r�rz
Session.queryBs��=@r�c��yr�r�)r�r|r}rr�r��_Session__ent5s       r�rz
Session.queryLs	��BEr�c��yr�r�)r�r|r}rr�r�r��_Session__ent6s        r�rz
Session.queryWs	��GJr�c	��yr�r�)	r�r|r}rr�r�r�r��_Session__ent7s	         r�rz
Session.querycs	��LOr�c��yr�r��r��entitiesr{s   r�rz
Session.queryrs��r�c�*�|j||fi|��S)a�Return a new :class:`_query.Query` object corresponding to this
        :class:`_orm.Session`.

        Note that the :class:`_query.Query` object is legacy as of
        SQLAlchemy 2.0; the :func:`_sql.select` construct is now used
        to construct ORM queries.

        .. seealso::

            :ref:`unified_tutorial`

            :ref:`queryguide_toplevel`

            :ref:`query_api_toplevel` - legacy API doc

        )r�r�s   r�rz
Session.queryws��(�t���x��8��8�8r�c�\�|j||��}tj||||�}	|	S)ayLocate an object in the identity map.

        Given a primary key identity, constructs an identity key and then
        looks in the session's identity map.  If present, the object may
        be run through unexpiration rules (e.g. load unloaded attributes,
        check if was deleted).

        e.g.::

            obj = session._identity_lookup(inspect(SomeClass), (1,))

        :param mapper: mapper in use
        :param primary_key_identity: the primary key we are searching for, as
         a tuple.
        :param identity_token: identity token that should be used to create
         the identity key.  Used as is, however overriding subclasses can
         repurpose this in order to interpret the value in a special way,
         such as if None then look among multiple target tokens.
        :param passive: passive load flag passed to
         :func:`.loading.get_from_identity`, which impacts the behavior if
         the object is found; the object may be validated and/or unexpired
         if the flag allows for SQL to be emitted.
        :param lazy_loaded_from: an :class:`.InstanceState` that is
         specifically asking for this identity as a related identity.  Used
         for sharding schemes where there is a correspondence between an object
         and a related object being lazy-loaded (or otherwise
         relationship-loaded).

        :return: None if the object is not found in the identity map, *or*
         if the object was unexpired and found to have been deleted.
         if passive flags disallow SQL and the object is expired, returns
         PASSIVE_NO_RESULT.   In all other cases the instance is returned.

        .. versionchanged:: 1.4.0 - the :meth:`.Session._identity_lookup`
           method was moved from :class:`_query.Query` to
           :class:`.Session`, to avoid having to instantiate the
           :class:`_query.Query` object.


        )r�)�identity_key_from_primary_keyr�get_from_identity)
r�r��primary_key_identityr��passiver$r�r�r��return_values
          r��_identity_lookupzSession._identity_lookup�s=��f�2�2� ��3�
��
�0�0��v�s�G�L���r�c#�bK�|j}d|_	|��||_y#||_wxYw�w)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�)r�r�s  r��no_autoflushzSession.no_autoflush�s0����*�N�N�	����	'��J�&�D�N��Y�D�N�s�/�#�/�	,�/z�This warning originated from the Session 'autoflush' process, which was invoked automatically in response to a user-initiated operation. Consider using ``no_autoflush`` context manager if this warning happended while initializing objects.c��|jr|js	|j�yyy#tj$r<}|jd�|j
tj�d��d}~wwxYw)Nz�raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurelyr9)	r�r�r�r��StatementError�
add_detailr�r�r�)r��es  r��
_autoflushzSession._autoflush�so���>�>�$�.�.�
:��
�
��#1�>���(�(�

:�
���5��
�&�&�s�|�|�~�a�'8�9�9��

:�s�-�A<�7A7�7A<c��	tj|�}|j||�|j
�|ik(rtjd��tj|�}tjt|��}tj|||j |||ddd��		�!tj"dt%|�z��y#tj$r}tj|�|�d}~wwxYw)a
Expire and refresh attributes on the given instance.

        The selected attributes will first be expired as they would when using
        :meth:`_orm.Session.expire`; then a SELECT statement will be issued to
        the database to refresh column-oriented attributes with the current
        value available in the current transaction.

        :func:`_orm.relationship` oriented attributes will also be immediately
        loaded if they were already eagerly loaded on the object, using the
        same eager loading strategy that they were loaded with originally.

        .. versionadded:: 1.4 - the :meth:`_orm.Session.refresh` method
           can also refresh eagerly loaded attributes.

        :func:`_orm.relationship` oriented attributes that would normally
        load using the ``select`` (or "lazy") loader strategy will also
        load **if they are named explicitly in the attribute_names
        collection**, emitting a SELECT statement for the attribute using the
        ``immediate`` loader strategy.  If lazy-loaded relationships are not
        named in :paramref:`_orm.Session.refresh.attribute_names`, then
        they remain as "lazy loaded" attributes and are not implicitly
        refreshed.

        .. versionchanged:: 2.0.4  The :meth:`_orm.Session.refresh` method
           will now refresh lazy-loaded :func:`_orm.relationship` oriented
           attributes for those which are named explicitly in the
           :paramref:`_orm.Session.refresh.attribute_names` collection.

        .. tip::

            While the :meth:`_orm.Session.refresh` method is capable of
            refreshing both column and relationship oriented attributes, its
            primary focus is on refreshing of local column-oriented attributes
            on a single instance. For more open ended "refresh" functionality,
            including the ability to refresh the attributes on many objects at
            once while having explicit control over relationship loader
            strategies, use the
            :ref:`populate existing <orm_queryguide_populate_existing>` feature
            instead.

        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.   Refreshing
        attributes usually only makes sense at the start of a transaction
        where database rows have not yet been accessed.

        :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.

        .. seealso::

            :ref:`session_expire` - introductory material

            :meth:`.Session.expire`

            :meth:`.Session.expire_all`

            :ref:`orm_queryguide_populate_existing` - allows any ORM query
            to refresh objects as they would be loaded normally.

        Nzqwith_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_props�require_pk_colsr��is_user_refreshzCould not refresh instance '%s')r�instance_stater�NO_STATE�UnmappedInstanceError�
_expire_stater�r�rrM�_from_argumentr;�selectr,r�
load_on_identr�r�r*)r�r��attribute_namesr�r!re�stmts       r��refreshzSession.refresh�s��V	?��-�-�h�7�E�	
���5�/�2�	
�����b� ��&�&�3��
�'�5�5�o�F���J�J�}�X�'>�?���!�!����	�	�#� /� /� $�"� $�

��
� �,�,�1�L��4J�J��
�!
��1�|�|�	?��+�+�H�5�3�>��	?�s�C�C?�$C:�:C?c��|jj�D]2}|j|j|jj��4y)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` is not usually needed,
        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��r�r!s  r��
expire_allzSession.expire_allts<��@�&�&�1�1�3�E��M�M�%�*�*�d�&7�&7�&A�&A�B�4r�c��	tj|�}|j||�y#tj$r}tj|�|�d}~wwxYw)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`

        N)rr�rr�r�r�)r�r�r�r!res     r��expirezSession.expire�sS��N	?��-�-�h�7�E�	
���5�/�2���|�|�	?��+�+�H�5�3�>��	?�s�*�A�A�Ac��|j|�|r|j|j|�yt|jj
j
d|��}|j|�|D]\}}}}|j|��y)Nzrefresh-expire)�_validate_persistent�_expire_attributesr�r��managerr��cascade_iterator�_conditional_expire)r�r!r��cascaded�o�m�st_�dct_s        r�r�zSession._expire_state�s���
	
�!�!�%�(���$�$�U�Z�Z��A���
�
�$�$�5�5�6F��N��H�
�$�$�U�+�#+���1�c�4��(�(��-�$,r�c���|jr1|j|j|jj�y||j
vr-|j
j
|�|j|�yy)z5Expire a state if persistent, else expunge if pendingN)r�r�r�r�r�rWr)�_detach)r�r!r�s   r�r�zSession._conditional_expire�sV��
�9�9��M�M�%�*�*�d�&7�&7�&A�&A�B�
�d�i�i�
��I�I�M�M�%� ��M�M�$�� r�c
���	tj|�}|j
|jur!tjdt|�z��t|jjjd|��}|j|g|D����cgc]	\}}}}|��c}}}}z�y#tj$r}tj|�|�d}~wwxYwcc}}}}w)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.

        Nz*Instance %s is not present in this Session�expunge)rr�rr�r��
session_idr�r�r�r/r�r�r�r�r�)	r�r�r!rer�r�r�r�r�s	         r�r�zSession.expunge�s���	?��-�-�h�7�E����4�=�=�0��,�,�<�y��?O�O��
���M�M� � �1�1�)�U�C�
��	
���e�W�8�'L�8���1�c�4��8�'L�L�M���|�|�	?��+�+�H�5�3�>��	?��(Ms�B.�C�.C�C�Cc��|D]�}||jvr|jj|��-|jj|�r8|jj	|�|j
j|d���|js��|jj
j|d���tjj|||��y)Nr�)
rWr)r��contains_stater�rXrdr�r4r�)r��statesr�r!s    r�r�zSession._expunge_states�s����E���	�	�!��	�	�
�
�e�$��"�"�1�1�%�8��!�!�.�.�u�5��
�
�!�!�%��.��"�"��!�!�*�*�.�.�u�d�;��	���-�-��D�|�	.�	
r�c��|jjxsd}|D�]�}t|�}|j�}|��"|j	|�}tj|d�r|jrtj|d�r!tjdt|�z��|j�||_n|j|k7rp|jj|�|j}|�J�||j vr|j |d}n|j}||f|j |<||_|jj#|�}	|	�=|j	|	�|k(r)|	j��t%j&d|�d��d|_���t*j,j/d�|D�|j�|j1|�|�)|j
|j2�D]}|||��
t5|�j
|j2�D]}|j2j7|��y)	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�8K�|]}||jf���y�wr�)r�)�.0r!s  r��	<genexpr>z/Session._register_persistent.<locals>.<genexpr>M
s����5�f�U�e�U�Z�Z�
 �f�s�)re�pending_to_persistentr)rv�_identity_key_from_stater(�intersection�allow_partial_pks�
issupersetrr�r/r�r�r�rdrZr�r<r��_orphaned_outside_of_sessionr�r4�_commit_all_states�_register_alteredrWr�r))
r�r�r�r!r�rv�instance_keyr��orig_key�olds
          r��_register_persistentzSession._register_persistent
s(��!%�
�
� C� C� K�t���E�"�5�)�F��)�)�+�C���%�>�>�u�E���*�*�<��?�;�"�4�4� �+�+�L��O�<��.�.�?�$�E�*�+�	�	��9�9�$� ,�E�I��Y�Y�,�.��%�%�2�2�5�9� �-�-�E� �,�,�,��� 3� 3�3�#(�#6�#6�u�#=�a�#@��#(�9�9�� �$�2�E�'�'��.�!-�E�I�
�'�'�/�/��6���O��7�7��<��L����	�-��I�I�0<�>��6;��2�u�x	���1�1�5�f�5�t�7H�7H�	
�	
���v�&� �,��,�,�T�Y�Y�7��%�d�E�2�8���[�-�-�d�i�i�8�E��I�I�M�M�%� �9r�c��|jrI|D]C}||jvrd|jj|<�+d|jj|<�Eyy�NT)rdrWrY)r�r�r!s   r�r�zSession._register_alteredZ
sR��������D�I�I�%�48�D�%�%�*�*�5�1�6:�D�%�%�,�,�U�3�	 �r�c�H�|jjxsd}|D]�}|jrd|jj|<|�|j	�}|j
j
|�|jj|d�d|_|��{|||���yr�)re�persistent_to_deletedrdrXrvr�r�r))r�r�r�r!rvs     r��_remove_newly_deletedzSession._remove_newly_deletedb
s���!%�
�
� C� C� K�t���E�� � �48��!�!�*�*�5�1�$�0��i�i�k�����*�*�5�1��M�M���e�T�*�!�E�N�%�0�%�d�E�2�!r�c���|r|jr|jd�	tj|�}|j|�y#tj
$r}t	j|�|�d}~wwxYw)a�Place an object into this :class:`_orm.Session`.

        Objects that are in the :term:`transient` state when passed to the
        :meth:`_orm.Session.add` method will move to the
        :term:`pending` state, until the next flush, at which point they
        will move to the :term:`persistent` state.

        Objects that are in the :term:`detached` state when passed to the
        :meth:`_orm.Session.add` method will move to the :term:`persistent`
        state directly.

        If the transaction used by the :class:`_orm.Session` is rolled back,
        objects which were transient when they were passed to
        :meth:`_orm.Session.add` will be moved back to the
        :term:`transient` state, and will no longer be present within this
        :class:`_orm.Session`.

        .. seealso::

            :meth:`_orm.Session.add_all`

            :ref:`session_adding` - at :ref:`session_basics`

        z
Session.add()N)r��_flush_warningrr�rr�r��_save_or_update_state)r�r��_warnr!res     r�r�zSession.addx
sk��2�T�)�)�����0�	?��-�-�h�7�E�	
�"�"�5�)���|�|�	?��+�+�H�5�3�>��	?�s�A�A6�A1�1A6c�r�|jr|jd�|D]}|j|d���y)a2Add the given collection of instances to this :class:`_orm.Session`.

        See the documentation for :meth:`_orm.Session.add` for a general
        behavioral description.

        .. seealso::

            :meth:`_orm.Session.add`

            :ref:`session_adding` - at :ref:`session_basics`

        zSession.add_all()F)r�N)r�r�r�)r��	instancesr�s   r��add_allzSession.add_all�
s6�������� 3�4�!�H��H�H�X�U�H�+�"r�c��d|_|j|�t|�}|jd||j��D]\}}}}|j|��y)NFzsave-update)�halt_on)r��_save_or_update_implr)r��_contains_state)r�r!r�r�r�r�r�s       r�r�zSession._save_or_update_state�
sa��-2��*��!�!�%�(��u�%��%�6�6��5�$�*>�*>� 7� 
�O�A�q�#�t�
�%�%�c�*� 
r�c���|jr|jd�	tj|�}|j||d��y#tj
$r}t	j|�|�d}~wwxYw)aVMark an instance as deleted.

        The object is assumed to be either :term:`persistent` or
        :term:`detached` when passed; after the method is called, the
        object will remain in the :term:`persistent` state until the next
        flush proceeds.  During this time, the object will also be a member
        of the :attr:`_orm.Session.deleted` collection.

        When the next flush proceeds, the object will move to the
        :term:`deleted` state, indicating a ``DELETE`` statement was emitted
        for its row within the current transaction.   When the transaction
        is successfully committed,
        the deleted object is moved to the :term:`detached` state and is
        no longer present within this :class:`_orm.Session`.

        .. seealso::

            :ref:`session_deleting` - at :ref:`session_basics`

        zSession.delete()NT)�head)r�r�rr�rr�r��_delete_impl�r�r�r!res    r��deletezSession.delete�
sq��*������ 2�3�	?��-�-�h�7�E�	
���%����5���|�|�	?��+�+�H�5�3�>��	?�s�A	�	A7�A2�2A7c���|j�$|r!tjdt|�z��y|j	||�}||j
vry|jj|�|r|j||�|r0t|jjjd|��}nd}||j
|<|r*tr|�J�|D]\}}}}	|j||d��yy)N�Instance '%s' is not persistedr�F)r�r�r�r/�_before_attachrXr�r��
_after_attachr�r�r�r�rr�)
r�r!rvr��	to_attach�cascade_statesr�r�r�r�s
          r�r�zSession._delete_impl�
s����9�9����0�0�4�y��7G�G�����'�'��s�3�	��D�M�M�!�������e�$�����u�c�*��"��
�
�$�$�5�5�h��F��N�"�N�"��
�
�e����%�1�1�1�#1���1�c�4��!�!�#�q�%�0�$2�r���options�populate_existingr�r�r�r�c�R�|j||tj||||||��	S)a�Return an instance based on the given primary key identifier,
        or ``None`` if not found.

        E.g.::

            my_user = session.get(User, 5)

            some_object = session.get(VersionedFoo, (5, 10))

            some_object = session.get(VersionedFoo, {"id": 5, "version_id": 10})

        .. versionadded:: 1.4 Added :meth:`_orm.Session.get`, which is moved
           from the now legacy :meth:`_orm.Query.get` method.

        :meth:`_orm.Session.get` is special in that it provides direct
        access to the identity map of the :class:`.Session`.
        If the given primary key identifier is present
        in the local identity map, the object is returned
        directly from this collection and no SQL is emitted,
        unless the object has been marked fully expired.
        If not present,
        a SELECT is performed in order to locate the object.

        :meth:`_orm.Session.get` also will perform a check if
        the object is present in the identity map and
        marked as expired - a SELECT
        is emitted to refresh the object as well as to
        ensure that the row is still present.
        If not, :class:`~sqlalchemy.orm.exc.ObjectDeletedError` is raised.

        :param entity: a mapped class or :class:`.Mapper` indicating the
         type of entity to be loaded.

        :param ident: A scalar, tuple, or dictionary representing the
         primary key.  For a composite (e.g. multiple column) primary key,
         a tuple or dictionary should be passed.

         For a single-column primary key, the scalar calling form is typically
         the most expedient.  If the primary key of a row is the value "5",
         the call looks like::

            my_object = session.get(SomeClass, 5)

         The tuple form contains primary key values typically in
         the order in which they correspond to the mapped
         :class:`_schema.Table`
         object's primary key columns, or if the
         :paramref:`_orm.Mapper.primary_key` configuration parameter were
         used, in
         the order used for that parameter. For example, if the primary key
         of a row is represented by the integer
         digits "5, 10" the call would look like::

             my_object = session.get(SomeClass, (5, 10))

         The dictionary form should include as keys the mapped attribute names
         corresponding to each element of the primary key.  If the mapped class
         has the attributes ``id``, ``version_id`` as the attributes which
         store the object's primary key value, the call would look like::

            my_object = session.get(SomeClass, {"id": 5, "version_id": 10})

        :param options: optional sequence of loader options which will be
         applied to the query, if one is emitted.

        :param populate_existing: causes the method to unconditionally emit
         a SQL query and refresh the object with the newly loaded data,
         regardless of whether or not the object is already present.

        :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.

        :param execution_options: optional dictionary of execution options,
         which will be associated with the query execution if one is emitted.
         This dictionary can provide a subset of the options that are
         accepted by :meth:`_engine.Connection.execution_options`, and may
         also provide additional options understood only in an ORM context.

         .. versionadded:: 1.4.29

         .. seealso::

            :ref:`orm_queryguide_execution_options` - ORM-specific execution
            options

        :param bind_arguments: dictionary of additional arguments to determine
         the bind.  May include "mapper", "bind", or other custom arguments.
         Contents of this dictionary are passed to the
         :meth:`.Session.get_bind` method.

         .. versionadded: 2.0.0rc1

        :return: The object instance, or ``None``.

        r�)�	_get_implr�load_on_pk_identity)	r�r�r�r�r�r�r�r�r�s	         r�r�zSession.get�
s<��^�~�~����'�'��/�+�)�/�)��

�
	
r�c
�f�|j||||||||��}	|	�tjd��|	S)a<Return exactly one instance based on the given primary key
        identifier, or raise an exception if not found.

        Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query
        selects no rows.

        For a detailed documentation of the arguments see the
        method :meth:`.Session.get`.

        .. versionadded:: 2.0.22

        :return: The object instance.

        .. seealso::

            :meth:`.Session.get` - equivalent method that instead
              returns ``None`` if no row was found with the provided primary
              key

        r�z&No row was found when one was required)r�r��
NoResultFound)
r�r�r�r�r�r�r�r�r�r�s
          r��get_onezSession.get_onezsU��B�8�8����/�+�)�/�)��	
�����&�&�8��
��r�c	���t��r?t��tjvr$tjt��}
|
���t	|�}|�|j
st
jd|z��t�t�}|stj�dg���t��t|j�k7r8t
jddjd�|jD��z��|rf|j }
|
r9t#|
�j%��}|rt���|D]
}�|�|
|<�	t'�fd�|j(D���|sS|j,sG|�E|j/|�|||	�	�}|�t||j0�sy|S|t2j4usJ�t6j8j:}|r|d
|iz
}t=j>|�jAtB�}|�tEjF|�|_$|r|jJ|�}|||�||||	��S#t*$r>}t
jddjd�|j(D��z�|�d}~wwxYw)Nz(Expected mapped class or mapper, got: %r)�defaultzoIncorrect number of values in identifier to formulate primary key for session.get(); primary key columns are %s�,c3�&K�|]	}d|z���y�w�z'%s'Nr�)r��cs  r�r�z$Session._get_impl.<locals>.<genexpr>�s����#K�8J�1�F�Q�J�8J�s�c3�<�K�|]}�|j���y�wr��r�)r��propr�s  �r�r�z$Session._get_impl.<locals>.<genexpr>�s"�����,� :��)����2� :�s�z�Incorrect names of values in identifier to formulate primary key for session.get(); primary key attribute names are %s (synonym names are also accepted)c3�:K�|]}d|jz���y�wr�r�)r�rs  r�r�z$Session._get_impl.<locals>.<genexpr>�s!�����$>�D�����)�$>�s�)r�r�r��_populate_existing)r"r�r�r�)&r$rcr�_composite_gettersrB�	is_mapperr�rr�r�r<�to_listr��primary_keyr�rt�_pk_synonymsr�r�r��_identity_key_props�KeyError�always_refreshr�r�r+�PASSIVE_CLASS_MISMATCHrr1r2r;r��set_label_stylerNrMr��_for_update_argr�)r�r�r��
db_load_fnr�r�r�r�r�r��getterr��is_dict�pk_synonyms�correct_keys�krer�r"r�s  `                 r�r�zSession._get_impl�s����
�3�4��)�*��2�2�3�&�8�8��)�*��F�$*�*>�#?� �'.�v����>��!1�!1��&�&�:�V�C��
��1�4�8���#'�<�<�$�t�f�$� ��#�$��F�,>�,>�(?�?��,�,���8�8�#K��8J�8J�#K�K�L��
�� �-�-�K��"�;�/�<�<�(� �� �+/�0D�+E�(�)��0��3�-�[��^�<�*�

�'+�,� &� :� :�,�(�$�""��)�)��'��,�,��$�-�"3�-�-��H��#�"�(�F�M�M�:�����#7�#N�#N�N�N�N��+�+�@�@����1�3D�E�E�L��J�J�v�&�6�6�*�
�	��&�(4�(C�(C��)�I�%��)�	�)�)�7�3�I���� �%�)�/�)�
�	
��i�	
��0�0�E��h�h��$*�$>�$>��������	
�s�
I�	J�
9J�J)�loadr�c�F�|jr|jd�i}i}|r|j�t|�|j}	d|_|jt
j|�t
j|�||||��||_S#||_wxYw)aCopy 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.

        :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.
        :param options: optional sequence of loader options which will be
         applied to the :meth:`_orm.Session.get` method when the merge
         operation loads the existing version of the object from the database.

         .. versionadded:: 1.4.24


        .. seealso::

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

        zSession.merge()F)rr��
_recursive�_resolve_conflict_map)	r�r�r�r,r��_mergerr��
instance_dict)r�r�rr�rrr�s       r��mergez
Session.merge,s���|������ 1�2�79�
�EG����O�O���h���N�N�	�	'�"�D�N��;�;��)�)�(�3��(�(��2���%�&;�
��'�D�N��Y�D�N�s
�AB�	B )r�c��t|�}||vrtt||�Sd}|j}	|	��||jvr!tjdt|�z�|stjd��|j|�}	tj|	dvxrBtj|	d�xs'|jxrtj |	d�}
nd}
|	|j"vr	|j"|	}nd}|��|
r|	|vrtt||	�}n�|sk|j&rtjd��|j(j+�}t-j.|�}|	|_|j1|�d}n'|
r%|j3|j4|	d|	d|��}|�X|j(j+�}t-j.|�}t-j6|�}
d}|j9|�n*t-j.|�}t-j6|�}
|||<|||	<||u�r|j:��|j=|||j:t>j@�	�}|j=||
|j:t>j@�	�}|tjBur?|tjBur-||k7r(tEjFd
|�dt|��d|�d
���|jH|_$|jJ|_%|jM|�|jND]}|jQ|||||
|||��|sB|jS|
|j"�|jTjVjY|d�|r&|jTjVj[|d�|S#t$$rd}Y���wxYw)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.r9)r�r��r�z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.).r)rr"r�rWr<r�r/r�r�r�r+�	NEVER_SETr(r�r�r�r�r	r��
class_manager�new_instancerr�r�r�r�rr��version_id_col�_get_state_attr_by_columnr.�PASSIVE_NO_INITIALIZE�PASSIVE_NO_RESULTr�StaleDataError�	load_pathr"�_copy_callables�iterate_propertiesr�_commit_allr�re�_sa_event_merge_wo_loadr)r�r!�
state_dictr�rrrr�rr��key_is_persistent�merged�merged_state�merged_dict�existing_version�merged_versionrs                 r�rzSession._merge�s��+�5�1���J����J�u�-�.�.����i�i���;���	�	�!��	�	��'��.�/����0�0�"����1�1�%�8�C� 4� >� >�c��G�!�!��*�*�3�q�6�2�2���,�,�9�%�0�0��Q��8�8�

�!%���$�#�#�#�
��*�*�3�/��
�F��>� �S�,A�%A��b�"7��"<�=����>�>� �4�4�K���
 �-�-�:�:�<��)�8�8��@��#&�� ��!�!�,�/�#��"�����M�M���F�#&�q�6�#�	"����>��)�)�6�6�8�F�%�4�4�V�<�L�$�2�2�6�:�K��L��&�&�|�4�%�4�4�V�<�L�$�2�2�6�:�K�"�
�5��%+��c�"���$��$�$�0�#)�#C�#C����)�)�'�=�=�	$D�$� �"(�!A�!A� ���)�)�'�=�=�	"B�"��%�/�A�A�B�&�/�A�A�B�(�N�:��,�,�-�%�l�3�*��
�
�&+�_�_�L�"�(-�(:�(:�L�%�
�(�(��/��1�1���
�
���� ����)�	�2���$�$�[�$�2C�2C�D�� � �)�)�A�A��d�
��� � �)�)�.�.�|�T�B��
��e�
���
�s�5O�O�Oc�|�|jj|�s!tjdt	|�z��y)Nz3Instance '%s' is not persistent within this Session)r�r�r�r�r/r�s  r�r�zSession._validate_persistent)s>��� � �/�/��6��,�,�E��E�"�#��
�7r�c�:�|j�!tjdt|�z��|j	�}|j||�}||jvr)||j|<t|j�|_|r|j||�yy)NzGObject '%s' already has an identity - it can't be registered as pending)
r�r�r�r/rvr�rWr��insert_orderr�)r�r!rvr�s    r��
_save_implzSession._save_impl0s����9�9� ��,�,�4�6?��6F�G��
�
�i�i�k���'�'��s�3�	���	�	�!�"�D�I�I�e��!$�T�Y�Y��E������u�c�*�r�c�8�|j�!tjdt|�z��|jr3|r|j
sy|`n!tjdt|�z��|j
�}|�y|j||�}|jj|d�|r|jj|�n|jj|�|r|j||�y|r|jj||�yy)Nr�zsInstance '%s' has been deleted.  Use the make_transient() function to send this object back to the transient state.)r�r�r�r/rX�	_attachedrvr�r)r�r�r�r�re�deleted_to_persistent)r�r!r�rvr�s     r�r�zSession._update_impl?s���9�9���,�,�0�9�U�3C�C��
��>�>�������N��0�0�.�1:�%�0@�A����i�i�k���;���'�'��s�3�	��
�
���%��&�����%�%�e�,����!�!�%�(�����u�c�*�
��M�M�/�/��e�<�r�c�b�|j�|j|�y|j|�yr�)r�r4r�r�s  r�r�zSession._save_or_update_implgs&���9�9���O�O�E�"����e�$r�c���	tj|�}|j||�}d|_|r|j||�yy#tj$r}tj|�|�d}~wwxYw)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.

        NT)rr�rr�r�r��
_load_pendingr�)r�rvr!rer�s     r��enable_relationship_loadingz#Session.enable_relationship_loadingmsu��n	:��-�-�c�2�E��'�'��s�3�	�"�������u�c�*����|�|�	:��+�+�C�0�c�9��	:�s�A�A4�A/�/A4c	�D�|j�|j|jk(ry|jrN|jtvr<t	j
dt
|��d|j�d|j�d���|jj||�y)NFzObject 'z"' is already attached to session 'z' (this is 'z')T)	r r�r�r�r�r�r/re�
before_attach�r�r!rvs   r�r�zSession._before_attach�s����������t�}�}�,������ 0� 0�I� =��,�,��U�#�U�%5�%5�t�}�}�F��
�	
�
�
�#�#�D�%�0�r�c�&�|j|_|jr|j�||_|jj||�|jr|jj||�y|jj||�yr�)	r�r�r��_strong_objre�after_attachr��detached_to_persistent�transient_to_pendingr>s   r�r�zSession._after_attach�sk���=�=����>�>�e�/�/�7� #�E���
�
�"�"�4��/��9�9��M�M�0�0��u�=��M�M�.�.�t�U�;r�c��	tj|�}|j|�S#tj$r}tj|�|�d}~wwxYw)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.

        N)rr�rr�r�r�r�s    r��__contains__zSession.__contains__�sS��	?��-�-�h�7�E��#�#�E�*�*���|�|�	?��+�+�H�5�3�>��	?�s�(�A�A�Ac��tt|jj��t|jj��z�S)zWIterate over all pending or persistent instances within this
        Session.

        )�iterr�rWr�r�r�s r��__iter__zSession.__iter__�s?��
�����!�!�#�$�t�D�,=�,=�,D�,D�,F�'G�G�
�	
r�c�X�||jvxs|jj|�Sr�)rWr�r�r�s  r�r�zSession._contains_state�s'����	�	�!�L�T�%6�%6�%E�%E�e�%L�Lr�c��|jrtjd��|j�ry	d|_|j	|�d|_y#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.

        :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)r�r�r�r��_flush)r��objectss  r�r�z
Session.flush�sQ��.�>�>��,�,�-J�K�K��>�>���	#�!�D�N��K�K�� �"�D�N��U�D�N�s�A�	Ac�4�tjd|z�y)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.)r<r�)r��methods  r�r�zSession._flush_warnings!���	�	�
F�IO�
O�	
r�c�t�|jj�xr|jxr
|jSr�)r��check_modifiedrXrWr�s r�r�zSession._is_clean
s9���!�!�0�0�2�2�
��M�M�!�
��I�I�
�	
r�c�F�|j}|s=|js1|js%|jjj�yt
|�}|jjr)|jj|||�|j}t|j�}t|j�}t|�j|�}|r9t�}|D])}	tj|�}|j!|��+nd}t�}
|r0|j#|�j%|�j|�}n |j#|�j|�}|D]|}t'|�j)|�}|xr|j*}
|r!|
s|j,r|j/|g��P|j1||
��}|sJd��|
j!|��~|r!|j%|�j|
�}n|j|
�}|D]}|j1|d��}|r�Jd��|j2sy|j5�j7�x|_}	d|_	|j=�d|_|jj?||�|jA�|s�|jjr�tC|jj�}tDjFjI|jjD�cgc]}||jJf��c}|j��tMjNd|z�|jjQ||�|jS�y#tj$r}	tj|�|	�d}	~	wwxYw#d|_wxYwcc}w#tMjT�5|jWd��ddd�Yy#1swYYyxYwxYw)N)�isdeletez*Failed to add object to the flush context!TF)rz�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_statesrXrWr�r�r�r8re�before_flushr��
differencerr�rr�r�r�r�r�r)�
_is_orphan�has_identityr�r��register_object�has_workr rr�r�r@�after_flush�finalize_flush_changesr�r�r4r�r�r<r��after_flush_postexecr�r�r�)r�rL�dirty�
flush_context�deleted�new�objsetr�r!re�	processed�proc�	is_orphan�is_persistent_orphan�_regr��len_s                 r�rKzSession._flushs����"�"���T�]�]�4�9�9����'�'�-�-�/��&�t�,�
��=�=�%�%��M�M�&�&�t�]�G�D��&�&�E��d�m�m�$���$�)�)�n���E�
�%�%�g�.����U�F���@�&�5�5�a�8�E��
�
�5�!�
��F��E�	���9�9�U�#�0�0��8�C�C�G�L�D��9�9�U�#�.�.�w�7�D��E�%�e�,�7�7��>�I�#,�#C��1C�1C� ��,��6�6��$�$�e�W�-�$�4�4��$8�5����I�I�I�t��
�
�e�$�!�&��'�'��/�:�:�9�E�D��%�%�i�0�D��E� �0�0���0�F�D��E�E�E�4���%�%��26�2C�2C�2E�2L�2L�2N�N�
�!�K�+	>�#'�D� �
-��%�%�'�',��$��M�M�%�%�d�M�:��0�0�2��t�0�0�:�:��4�,�,�6�6�7���&�&�9�9�&*�%6�%6�%@�%@��%@�E���
�
�+�%@��#'�"3�"3�:���	�	�H�
KO�O�� 
�M�M�.�.�t�]�C���� ��m�|�|�@��3�3�A�6�C�?��@��h(-��$����4	>��"�"�$��$�$��$�=�%�$�$�sh�,N�>O �O�BO �1O�AO �O�1O�O�	O�O � P �6P�	P �P	�P �P c
��d�|D�}|st|d���}				d	d�}tj||�D] \\}}}	|j||	|d||d���"y)
a�Perform a bulk save of the given list of objects.

        .. legacy::

            This method is a legacy feature as of the 2.0 series of
            SQLAlchemy.   For modern bulk INSERT and UPDATE, see
            the sections :ref:`orm_queryguide_bulk_insert` and
            :ref:`orm_queryguide_bulk_update`.

            For general INSERT and UPDATE of existing ORM mapped objects,
            prefer standard :term:`unit of work` data management patterns,
            introduced in the :ref:`unified_tutorial` at
            :ref:`tutorial_orm_data_manipulation`.  SQLAlchemy 2.0
            now uses :ref:`engine_insertmanyvalues` with modern dialects
            which solves previous issues of bulk INSERT slowness.

        :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.  It is strongly
         advised to please use the standard :meth:`_orm.Session.add_all`
         approach.

        :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.

        .. seealso::

            :doc:`queryguide/dml`

            :meth:`.Session.bulk_insert_mappings`

            :meth:`.Session.bulk_update_mappings`

        c3�FK�|]}tj|����y�wr�)rr�)r�rvs  r�r�z,Session.bulk_save_objects.<locals>.<genexpr>�s����H���j�/�/��4��s�!c�H�t|j�|jdufSr�)�idr�r�r s r��<lambda>z+Session.bulk_save_objects.<locals>.<lambda>�s��2�e�l�l�#3�U�Y�Y�d�5J�"Kr�r�c�6�|j|jdufSr�)r�r�r s r��grouping_keyz/Session.bulk_save_objects.<locals>.grouping_key�s���L�L�%�)�)�4�"7�8�8r�TF��isupdate�isstates�return_defaults�update_changed_only�render_nullsN)r!�InstanceState[_O]r�zTuple[Mapper[_O], bool])�sortedr��groupby�_bulk_save_mappings)
r�rLrsrt�preserve_order�
obj_statesror�rqr�s
          r��bulk_save_objectszSession.bulk_save_objects�s���VI��H�
��
 ��K��J�
	9�$�	9�
$�	9�
+4�*;�*;���+
�&��V�X��
�$�$���!�� /�$7�"�
%�
�+
r�c	�4�|j||dd|d|��y)a=Perform a bulk insert of the given list of mapping dictionaries.

        .. legacy::

            This method is a legacy feature as of the 2.0 series of
            SQLAlchemy.   For modern bulk INSERT and UPDATE, see
            the sections :ref:`orm_queryguide_bulk_insert` and
            :ref:`orm_queryguide_bulk_update`.  The 2.0 API shares
            implementation details with this method and adds new features
            as well.

        :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, the INSERT process will be altered
         to ensure that newly generated primary key values will be fetched.
         The rationale for this parameter is typically to enable
         :ref:`Joined Table Inheritance <joined_inheritance>` mappings to
         be bulk inserted.

         .. note:: for backends that don't support RETURNING, the
            :paramref:`_orm.Session.bulk_insert_mappings.return_defaults`
            parameter can significantly decrease performance as INSERT
            statements can no longer be batched.   See
            :ref:`engine_insertmanyvalues`
            for background on which backends are affected.

        :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.

        .. seealso::

            :doc:`queryguide/dml`

            :meth:`.Session.bulk_save_objects`

            :meth:`.Session.bulk_update_mappings`

        FrpN�ry)r�r��mappingsrsrus     r��bulk_insert_mappingszSession.bulk_insert_mappings�s-��R	
� � �����+� %�%�	!�	
r�c	�4�|j||ddddd��y)aaPerform a bulk update of the given list of mapping dictionaries.

        .. legacy::

            This method is a legacy feature as of the 2.0 series of
            SQLAlchemy.   For modern bulk INSERT and UPDATE, see
            the sections :ref:`orm_queryguide_bulk_insert` and
            :ref:`orm_queryguide_bulk_update`.  The 2.0 API shares
            implementation details with this method and adds new features
            as well.

        :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::

            :doc:`queryguide/dml`

            :meth:`.Session.bulk_insert_mappings`

            :meth:`.Session.bulk_save_objects`

        TFrpNr~)r�r�rs   r��bulk_update_mappingszSession.bulk_update_mappingsGs-��L	
� � �����!� %��	!�	
r�c��t|�}d|_|j�j�}	|rt	j
|||||��nt	j||||||��|j�d|_y#tj�5|jd��ddd�n#1swYnxYwY�HxYw#d|_wxYw)NT)rrrt)rrrsrurSF)r'r�r rr�_bulk_update�_bulk_insertr�r<r�r�)	r�r�rrqrrrsrtrur�s	         r�ryzSession._bulk_save_mappingsws���"�&�)������'�'�)�0�0�2��	#�� �-�-����%�(;��!�-�-����%�$3�!-�
�
��� �#�D�N��		>��"�"�$��$�$��$�=�%�$�$���#�D�N�s0�AB�C�B4�+	C�4B=	�9C�C�	Cc�L�t|�}|jsy|j}|jjD]g}|st|jd�st|jd�s�2|jj||tj��\}}}|s|s�gyy)aD
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 flushed or 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.

        F�get_collection�get_historyrT)
r-r�r�r�r�hasattr�implr�r.r�)	r�r��include_collectionsr!�dict_�attr�added�	unchangedr`s	         r��is_modifiedzSession.is_modified�s���j�X�&���~�~���
�
���M�M�,�,�D�'��D�I�I�'7�8��T�Y�Y�
�6��*.�)�)�*?�*?��u�k�&;�&;�+@�+�'�U�I�w����-�r�c�N�|jduxs|jjS)a4True if this :class:`.Session` not in "partial rollback" state.

        .. versionchanged:: 1.4 The :class:`_orm.Session` no longer begins
           a new transaction immediately, so this attribute will be False
           when the :class:`_orm.Session` is first instantiated.

        "partial rollback" state typically indicates that the flush process
        of the :class:`_orm.Session` has failed, and that the
        :meth:`_orm.Session.rollback` method must be emitted in order to
        fully roll back the transaction.

        If this :class:`_orm.Session` is not in a transaction at all, the
        :class:`_orm.Session` will autobegin when it is first used, so in this
        case :attr:`_orm.Session.is_active` will return True.

        Otherwise, if this :class:`_orm.Session` is within a transaction,
        and that transaction has not been rolled back internally, the
        :attr:`_orm.Session.is_active` will also return True.

        .. seealso::

            :ref:`faq_session_rollback`

            :meth:`_orm.Session.in_transaction`

        N)rdrtr�s r�rtzSession.is_active�s&��8� � �D�(�G�D�,=�,=�,G�,G�Gr�c�6�|jj�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�rTr�s r�rTzSession._dirty_states
s��� � �.�.�0�0r�c��t|jD�cgc] }||jvr|j���"c}�Scc}w)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.

        )rOrTrXrvr�s  r�r^z
Session.dirtysK��0�"�/�/�
�/�E���
�
�-��	�	��/�
�
�	
��
s�%Ac�n�tjt|jj	���S)zDThe set of all instances marked as 'deleted' within this ``Session``)r<rOr�rXr�r�s r�r`zSession.deleted4s'������T�]�]�%9�%9�%;� <�=�=r�c�n�tjt|jj	���S)zAThe set of all instances marked as 'new' within this ``Session``.)r<rOr�rWr�r�s r�razSession.new:s'������T�Y�Y�%5�%5�%7� 8�9�9r�r�)r|�Optional[_SessionBind]r�rFr��
Literal[True]r�rFr�rFr�rFr�z-Optional[Dict[_SessionBindKey, _SessionBind]]r�rFr��Optional[_InfoType]r�zOptional[Type[Query[Any]]]rzLiteral[False]r�r�rzUnion[bool, _NoArg])r��_Sr�r�)rrrrrrr�r�)r�r�r�zIterator[_S]rEr�)r�rhr�)r�rFr�r|r�)r�r|r�r�)r�rCr�r�r�r=)r:r�r�r�r�rr�r=)r�rrr��"Optional[_CoreSingleExecuteParams]r�rUr�rCr�r�r+r�r,r�r�r)r�rrr�r�r�rUr�rCr�r�r+r�r,rFr�rD)r�rrr�r�r�rUr�rCr�r�r+r�r,rFr�r)r�zTypedReturnsRows[_T]r�r�r�rUr�rCr�r�r+r�r�z
Result[_T])r�rtr�r�r�rUr�rCr�r�r+r�r�zCursorResult[Any])r�rrr�r�r�rUr�rCr�r�r+r�r�rD)r��TypedReturnsRows[Tuple[_T]]r�r�r�rUr�rCr�rr�zOptional[_T])r�rrr�r�r�rUr�rCr�rr�r)r�r�r�r�r�rUr�rCr�rr�zScalarResult[_T])r�rrr�r�r�rUr�rCr�rr�zScalarResult[Any])r�rFrYrFr�r�)r��_SessionBindKeyr|r�r�r�)r��_EntityBindKey[_O]r|r�r�r�)rirHr|r�r�r�)r�zOptional[_EntityBindKey[_O]]r3zOptional[ClauseElement]r|r�r��Optional[bool]rkrFr�rr�zUnion[Engine, Connection])rxz_EntityType[_O]r�z	Query[_O])rzzTypedColumnsClauseRole[_T]r�zRowReturningQuery[Tuple[_T]])r|�
_TCCA[_T0]r}�
_TCCA[_T1]r�z"RowReturningQuery[Tuple[_T0, _T1]])r|r�r}r�r�
_TCCA[_T2]r�z'RowReturningQuery[Tuple[_T0, _T1, _T2]])
r|r�r}r�rr�r��
_TCCA[_T3]r�z,RowReturningQuery[Tuple[_T0, _T1, _T2, _T3]])r|r�r}r�rr�r�r�r��
_TCCA[_T4]r�z1RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4]])r|r�r}r�rr�r�r�r�r�r��
_TCCA[_T5]r�z6RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5]])r|r�r}r�rr�r�r�r�r�r�r�r��
_TCCA[_T6]r�z;RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5, _T6]])r|r�r}r�rr�r�r�r�r�r�r�r�r�r�z
_TCCA[_T7]r�z@RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7]])r�z_ColumnsClauseArgument[Any]r{rr�z
Query[Any])r�r�r�r�r�rr�r.r$rGr�rUr�rCr�z)Union[Optional[_O], LoaderCallableStatus])r�zIterator[Session])r�r�r��Optional[Iterable[str]]r�rwr�r�)r�r�r�r�r�r�)r!�InstanceState[Any]r�r�r�r�)r!r�r�r�r�r��r�r�r�r�)r��Iterable[InstanceState[Any]]r�rFr�r�)r�zSet[InstanceState[Any]]r�r�)r�r�r�r�)T)r�r�r�rFr�r�)r��Iterable[object]r�r�)r!r�r�r�)r!r�rvr�r�rFr�r�)r�r�r��_PKIdentityArgumentr��Optional[Sequence[ORMOption]]r�rFr�rwr�r�r�rUr�rCr��Optional[_O])r�r�r�r�r�r�r�rFr�rwr�r�r�rUr�rCr�r")r�r�r�r�rzCallable[..., _O]r�z$Optional[Sequence[ExecutableOption]]r�rFr�rwr�r�r�rUr�rCr�r�)r�r"rrFr�r�r�r")r!rvr*rTr�r�rrFrzDict[Any, object]rz#Dict[_IdentityKeyType[Any], object]r�r")r!r�r�rFr�r�)rvr�r�r�)r!r�rvr�r�rF)r!r�rvr�r�r�)r�r�r�rF)r�zIterator[object])r!r�r�rF)rLzOptional[Sequence[Any]]r�r�)rNrr�r�)rLzOptional[Sequence[object]]r�r�)FTT)
rLr�rsrFrtrFrzrFr�r�r�)
r�r�r�Iterable[Dict[str, Any]]rsrFrurFr�r�)r�r�rr�r�r�)r�r�rz<Union[Iterable[InstanceState[_O]], Iterable[Dict[str, Any]]]rqrFrrrFrsrFrtrFrurFr�r�)r�r�r�rFr�rF)r�r�)r�rO)fr�r�r�r��_is_asynciorIrJrr�r
rr
r�
contextlib�contextmanagerrr�r�rrr<�memoized_propertyr�r r�r�r�r�r�r}ryr�
EMPTY_DICTr�r@r>rQr�rZr�rWr]r	r�rjrxrr.�PASSIVE_OFFr��non_memoized_propertyr��langhelpers�tag_method_for_warningsr��	SAWarningr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr�r4r�r�r;r�r�rErHr�r�r�r�rKr|r�r�ryr�rJrtrTr^r`rar�r�r�r{r{�s*����K�!�!����(�'�+�+�
-�-�
0�0��O���.�.�5�5��M��O������N�.�.� � �$�$�(,�k(�� $�!%���?C�%)�$(�04�%*�5L�17���k(�$�k(��	k(�
�k(��
k(��k(��k(�=�k(�#�k(�"�k(�.�k(�#�k(� 3�k(�/�k(�\	>B��:�A�>B��;�B���������
-�4�	�(�
���
��
�!�(5�n'�46�*$$�L�&48�CG�.
�0�.
�A�.
�
�	.
�fDH�E��E�A�E��	E�

�E��6:�
�
9=���37�/3�$(�(+�
��
�3�
�
6�
�1�
� -�
�"�
�&�
�

�
��
��37�
�
9=���37�/3�$(�"�
��
�0�
�
6�
�1�
� -�
�"�
��
�
�
��
�37�A�
9=���37�/3�$(�$�A��A�0�A�
6�A�1�
A� -�A�"�A��A�

�A�F�37�	�
9=���37�/3�$(�	�'�	�0�	�
6�	�1�
	� -�	�"�	�
�	��	��37�	 �
9=���37�/3�$(�	 ��	 �0�	 �
6�	 �1�
	 � -�	 �"�	 �
�	 ��	 ��37�	�
9=���37�/3�$(�	��	�0�	�
6�	�1�
	� -�	�"�	�
�	��	�37�C
�
9=���37�/3�$(�C
��C
�0�C
�
6�C
�1�
C
� -�C
�"�C
�
�C
�J�6:��
9=���37�
�.��3��
6��1�
���
�����6:��
9=���37�
���3��
6��1�
���

����6:�
�
9=���37�

��
�3�
�
6�
�1�

��
�

�
�4�37��
9=���37�
�.��0��
6��1�
���
�����37� �
9=���37�
 �� �0� �
6� �1�
 �� �
� �� �37�$�
9=���37�
$��$�0�$�
6�$�1�
$��$�
�$�L'+�R:�2"*�H.�@� �2%�(�%�0<�%�	
�%�<$�<04�]
�+/�'+�*.�05�]
�,�]
�(�	]
�
%�]
�(�
]
�*.�]
��]
�
#�]
�~�?��?�
�+�2�+�	%�+��+��1� �1�*4�1�	+�1��1��6� �6�*4�6�>H�6�	0�6��6��;��;��;��	;�
�;�
6�
;��;��@��@��@��	@�
�@��
@�
;�@��@��E��E��E��	E�
�E��
E��E�
@�E��E��	J��	J��	J��		J�
�	J��
	J��	J��	J�
E�	J��	J��
O��
O��
O��	
O�
�
O��
O��
O��
O��
O�
J�
O��
O���4��@C��	����9�4�9�@C�9�	�9�4#�*�6�6�9=�8<���37�9��9�:�9��	9�
�9�7�
9�6�9�1�9�
3�9�v
������'�� �'�4
���-�-�	8�	����:��:�&48�.2�	w��w�1�w�,�	w�

�w�r!C�HLP�+3��+3�1H�+3�	
�+3�Z.�!�.�1�.�
�	.�&FJ�	 �'�	 �4B�	 �	
�	 �N�,JO�
�2�
�BF�
�	
�
�"Q!�f;�3�2�3�	
�3�,!*�F,�(+�6�>%1�'�%1�.4�%1�<@�%1�	
�%1�X26�"'�.2�(,�8<���37�y
�"�y
�#�y
�
/�y
� �
y
�,�y
�&�y
�6�y
�1�y
�
�y
�@26�"'�.2�(,�8<���37�1�"�1�#�1�
/�1� �
1�,�1�&�1�6�1�1�1�
�1�r9=�"'�.2�(,�8<���37�}
�"�}
�2�}
�&�	}
�6�
}
� �}
�,�}
�&�}
�6�}
�1�}
�
�}
�F�15�U'��U'��	U'�
/�U'�
�
U'�x26�d� �d�"�d�
/�d��
d�&�d� C�d�
�d�L�
+� BG�&=�'�&=�:>�&=�	
�&=�P%�?+�B�"	<�+�
�M� #�D
�
�u>�t!&�$(�#�g�!�g��g�"�	g�
�g�
�
g�Z!&�"�Q
��Q
�+�Q
��	Q
�
�Q
�
�
Q
�f.
�!�.
�-E�.
�	
�.
�`'#��'#�O�'#�
�'#��
'#��'#�"�'#��'#�
�'#�T=A�J��J�59�J�	
�J�X�H��H�:�1��1��
��
�>�>��>�
�:��:r�r{r�c���eZdZUdZded<e	ddddd�											dd��Ze	ddddd�											dd��Z	ded	d	dd
�											dd�Zdd�Zdd
�Z	dd�Z
dd�Zy)r}a�
A 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.::

        from sqlalchemy import create_engine
        from sqlalchemy.orm import sessionmaker

        # an Engine, which the Session will use for connection
        # resources
        engine = create_engine("postgresql+psycopg2://scott:tiger@localhost/")

        Session = sessionmaker(engine)

        with Session() as session:
            session.add(some_object)
            session.add(some_other_object)
            session.commit()

    Context manager use is optional; otherwise, the returned
    :class:`_orm.Session` object may be closed explicitly via the
    :meth:`_orm.Session.close` method.   Using a
    ``try:/finally:`` block is optional, however will ensure that the close
    takes place even if there are database errors::

        session = Session()
        try:
            session.add(some_object)
            session.add(some_other_object)
            session.commit()
        finally:
            session.close()

    :class:`.sessionmaker` acts as a factory for :class:`_orm.Session`
    objects in the same way as an :class:`_engine.Engine` acts as a factory
    for :class:`_engine.Connection` objects.  In this way it also includes
    a :meth:`_orm.sessionmaker.begin` method, that provides a context
    manager which both begins and commits a transaction, as well as closes
    out the :class:`_orm.Session` when complete, rolling back the transaction
    if any errors occur::

        Session = sessionmaker(engine)

        with Session.begin() as session:
            session.add(some_object)
            session.add(some_other_object)
        # commits transaction, closes session

    .. versionadded:: 1.4

    When calling upon :class:`_orm.sessionmaker` to construct a
    :class:`_orm.Session`, keyword arguments may also be passed to the
    method; these arguments will override that of the globally configured
    parameters.  Below we use a :class:`_orm.sessionmaker` bound to a certain
    :class:`_engine.Engine` to produce a :class:`_orm.Session` that is instead
    bound to a specific :class:`_engine.Connection` procured from that engine::

        Session = sessionmaker(engine)

        # bind an individual session to a connection

        with engine.connect() as connection:
            with Session(bind=connection) as session:
                ...  # work with session

    The class also includes a method :meth:`_orm.sessionmaker.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, sessionmaker does not have
        # an engine bound yet
        Session = sessionmaker()

        # ... later, when an engine URL is read from a configuration
        # file or other events allow the engine to be created
        engine = create_engine("sqlite:///foo.db")
        Session.configure(bind=engine)

        sess = Session()
        # work with session

    .. seealso::

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

    �Type[_S]r�.)r�r�r�c��yr�r��r�r|r�r�r�r�r�s       r�r�zsessionmaker.__init__�s��r�c��yr�r�)r�r|r�r�r�r�s      r�r�zsessionmaker.__init__�s��r�NT)r�r�r�r�c�x�||d<||d<||d<|�||d<||_t|j|fi�|_y)a<Construct 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.

         .. seealso::

            :ref:`session_flushing` - additional background on autoflush

        :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.

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

        r|r�r�Nr�)r�rcr�r�r�s       r�r�zsessionmaker.__init__�sP��R��6�
�#��;��!1�������B�v�J�����6�?�?�V�I�r�:��r�c�0�|�}|j�S)amProduce a context manager that both provides a new
        :class:`_orm.Session` as well as a transaction that commits.


        e.g.::

            Session = sessionmaker(some_engine)

            with Session.begin() as session:
                session.add(some_object)

            # commits transaction, closes session

        .. versionadded:: 1.4


        )r)r�r�s  r�r�zsessionmaker.begin�s��&�&���-�-�/�/r�c���|jj�D]J\}}|dk(r.d|vr*|j�}|j|d�||d<�9|j	||��L|j
di|��S)apProduce 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(some_engine)
            session = Session()  # invokes sessionmaker.__call__()

        r�r�)r�r��copyr�r9r�)r��local_kwr�vrs     r�r�zsessionmaker.__call__sv���G�G�M�M�O�D�A�q��F�{�v��1��F�F�H������&�)�*�#$��� ��#�#�A�q�)�
$��t�{�{�&�X�&�&r�c�:�|jj|�y)z�(Re)configure the arguments for this sessionmaker.

        e.g.::

            Session = sessionmaker()

            Session.configure(bind=create_engine("sqlite://"))
        N)r�r�)r��new_kws  r��	configurezsessionmaker.configures��	
�����v�r�c	���|jj�d|jj�ddjd�|jj�D���d�S)Nz(class_=rnc3�0K�|]\}}|�d|�����y�w)�=Nr�)r�rr�s   r�r�z(sessionmaker.__repr__.<locals>.<genexpr>(s����C�?�4�1�a��A�&�?�s�r�)�	__class__r�r�rtr�r�r�s r��__repr__zsessionmaker.__repr__$sB���N�N�#�#��K�K� � ��I�I�C�4�7�7�=�=�?�C�C�
�	
r�).)r|r�r�r�r�rFr�rFr�r�r�r)r�z'sessionmaker[Session]'r|r�r�rFr�rFr�r�r�rr�)r�z%contextlib.AbstractContextManager[_S])r�rr�r�)r�rr�r�)r�r�)r�r�r�r�rIrr�r{r�r�r�r�r�r�r�r}r}Ds?��\�|
��
�(+�	�
�!$�$'�	�$�	��		�
�	��
	�"�	��	��	��(+���!$�$'�
�%��$���	�
��"�
�����(,�1;�#��!%�$(�1;�$�1;��	1;�
�1;��
1;�"�1;��1;�f0�,'�(	�
r�r}c�V�tj�D]}|j��y)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�rr,s ��� � �"���
�
��#r�c��tj|�}t|�}|r|j|g�|jj�|jr|`|jr|`|jr|`yy)aoAlter 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" (see :ref:`orm_queryguide_column_deferral`) 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)	rr�r�r��expired_attributesr��	callablesr�rX)r�r!r�s   r�r�r�>sq��^
�%�%�h�/�E��u��A��	���5�'�"�
���"�"�$�
����O��y�y��I��~�~��N�r�c�f�tj|�}|js|jrt	j
d��|jj|�|_|jr|`|j|j�|j|j|j�y)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.

    .. seealso::

        :func:`.make_transient`

        :meth:`.Session.enable_relationship_loading`

    zGiven object must be transientN)
rr�r�r�r�r�r�r�rXr(r�r��unloaded)r�r!s  r�r�r�s���:
�%�%�h�/�E����5�9�9��(�(�)I�J�J����5�5�e�<�E�I��~�~��N�	���e�j�j�!�	���U�Z�Z����8r�c��	tj|�}t|�S#tj$r}tj
|�|�d}~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.

    N)rr�r�rr�r�)r�r!res   r�r�r��sM��%��)�)�(�3���e�$�$���<�<�;��'�'��1�s�:��;�s�"�A�A�A)r!r�r�r�r�r�r�)�r��
__future__rr��enumrr�r��typingrrrrr	r
rrr
rrrrrrrrrr��rrrrrrrrr!r��_typingr"r#r$r%r&�baser'r(r)r*r+r,r-r.r/r0r1r2r3r4�
state_changesr5r6r7�
unitofworkr8r:r�r;r<r=r>�engine.utilr?�eventr@rA�
inspectionrBrCrDrErFrGrHrI�sql.baserJrK�
sql.schemarL�sql.selectablerMrNrO�util.typingrPrQrRrSrTrU�
interfacesrVrWr�rX�
path_registryrYrZr[r\r]r^�engine.baser_r`�engine.interfacesrarbrcrd�
engine.resultrerf�sql._typingrgrhrirjrkrlrmrnrorprq�_TCCArrrs�sql.dmlrt�sql.elementsru�	sql.rolesrvrwrxry�__all__�WeakValueDictionaryr�rIr�r�r��_EntityBindKeyr�r�r�r�r�r�r��tupler�r�r�r�r�r��
MemoizedSlotsr~rLr|r`r{r�r}rr�r�r��counterrr�r�r��<module>r�s��8�"����
�
���������������� ��������������#�'�"�+�"����&�����"�$�!�� �'�,�-�&�������.��� �$��������#��)�;��!�"�	���$�)�&�3�%�-��+�(�%���#�)�1�9�<�3�?�,�.�4�'�!�!�!�!�!�!�!�!�A�%�+�$�,�2�3�1��T����	�� �G���!�
�4�������C��s�C�x��0�1���c�3�h����t�B�x��-�.����S�	�=�-��D�E���+�,�������x��*�/(�/(�d �/� �JO��J�F���)�X�v�/F�
h
�d�(�(�h
�V7�t�7�0Y	6��';�Y	6�x���O6:�"�K�O6:�dl
�T��#��e
�'����e
�P�$>�B$9�N
%� �����r�

ZeroDay Forums Mini