HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/__pycache__/state_changes.cpython-310.pyc
o

���g��@s�dZddlmZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
dd	lmZdd
lmZddlm
Z
ddlmZdd
lmZddlmZddlmZddlmZededefd�ZGdd�de�ZGdd�de�ZGdd�d�ZdS)z9State tracking utilities used by :class:`_orm.Session`.

�)�annotationsN)�Enum)�Any)�Callable)�cast)�Iterator)�NoReturn)�Optional)�Tuple)�TypeVar)�Union�)�exc)�util)�Literal�_F.)�boundc@seZdZdS)�_StateChangeStateN)�__name__�
__module__�__qualname__�rr�G/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/state_changes.pyr!src@seZdZdZdZdZdS)�_StateChangeStates�r
�N)rrr�ANY�	NO_CHANGE�CHANGE_IN_PROGRESSrrrrr%src@sbeZdZUdZejZded<ejZ	ded<dZ
ded<dd
d�Zeddd��Z
ejddd��ZdS)�_StateChangea!Supplies state assertion decorators.

    The current use case is for the :class:`_orm.SessionTransaction` class. The
    :class:`_StateChange` class itself is agnostic of the
    :class:`_orm.SessionTransaction` class so could in theory be generalized
    for other systems as well.

    r�_next_state�_stateNzOptional[Callable[..., Any]]�_current_fn�operation_name�str�state�returnrcCstjd|�d|��dd��)NzCan't run operation 'z()' when Session is in state �isce��code)�sa_exc�IllegalStateChangeError)�selfr#r%rrr�_raise_for_prerequisite_state9s��z*_StateChange._raise_for_prerequisite_state�prerequisite_states�EUnion[Literal[_StateChangeStates.ANY], Tuple[_StateChangeState, ...]]�moves_to�Callable[[_F], _F]csH|sJd��|tju�td|���tju�tjd
����fd
d��}|S)a�Method decorator declaring valid states.

        :param prerequisite_states: sequence of acceptable prerequisite
         states.   Can be the single constant _State.ANY to indicate no
         prerequisite state

        :param moves_to: the expected state at the end of the method, assuming
         no exceptions raised.   Can be the constant _State.NO_CHANGE to
         indicate state should not change at the end of the method.

        zno prequisite states sentzTuple[_StateChangeState, ...]�fnrr,r�arg�kwr&c	sv|j}�r|�vr|�|j|�|j}|j}�r�n|}|tjurT�rT||urT|rC|tjtjfvrCt	j
d|j�d|j�d���dd��t	j
d|j�d��d|��dd��||_tj|_zXz
||g|�Ri|��}Wn�|j|ur||W||_||_S|j|ur�t	j
d|j�d	��d
�dd��|r�t	j
d|j�d|j�d
|j��dd��t	j
d|j�d
|j��dd��||_||_w)NzMethod 'z"()' can't be called here; method 'zN()' is already in progress and this would cause an unexpected state change to r'r(zCant run operation 'z()' here; will move to state z where we are expecting z()' failed to change state to z as expectedzWhile method 'z()' was running, method 'z)()' caused an unexpected state change to )r!r-rr r"rrrrr*r+)	r2r,r3r4�
current_state�
next_state�existing_fn�expect_state�	ret_value��expect_state_change�has_prerequisite_statesr0�prerequisite_state_collectionrr�_go_s��
��
���
���

�
��
���	
��z(_StateChange.declare_states.<locals>._goN)
r2rr,rr3rr4rr&r)rrrrr�	decorator)�clsr.r0r>rr:r�declare_statesBs��
Mz_StateChange.declare_states�expected�
Iterator[Any]ccsj�|jtjusJd��||_z!zdVWn�|j|ur)tjd|j��dd��Wtj|_dStj|_w)zxcalled within a method that changes states.

        method must also use the ``@declare_states()`` decorator.

        zAUnexpected call to _expect_state outside of state-changing methodNzUnexpected state change to r'r()r rrr!r*r+)r,rBrrr�
_expect_state�s��

��z_StateChange._expect_state)r#r$r%rr&r)r.r/r0rr&r1)rBrr&rC)rrr�__doc__rrr �__annotations__rr!r"r-�classmethodrA�
contextlib�contextmanagerrDrrrrr+s
	
	lr)rE�
__future__rrH�enumr�typingrrrrrr	r
rr�rr*r�util.typingrrrrrrrrr�<module>s(