
    Bh                       S r SSKJr  SSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  \" S\S\4   S9r " S S\5      r " S S\5      r " S S5      rg)z7State tracking utilities used by :class:`_orm.Session`.    )annotationsN)Enum)Any)Callable)cast)Iterator)NoReturn)Optional)Tuple)TypeVar)Union   )exc)util)Literal_F.)boundc                      \ rS rSrSrg)_StateChangeState    N)__name__
__module____qualname____firstlineno____static_attributes__r       _/home/kali/devsecops-assessor/venv/lib/python3.13/site-packages/sqlalchemy/orm/state_changes.pyr   r      s    r   r   c                       \ rS rSrSrSrSrSrg)_StateChangeStates#      r      r   N)r   r   r   r   ANY	NO_CHANGECHANGE_IN_PROGRESSr   r   r   r   r    r    #   s    
CIr   r    c                      \ rS rSr% Sr\R                  rS\S'   \R                  r
S\S'   SrS\S'         SS	 jr\      SS
 j5       r\R                   SS j5       rSrg)_StateChange)   a  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_stateNzOptional[Callable[..., Any]]_current_fnc                :    [         R                  " SU SU< 3SS9e)NzCan't run operation 'z()' when Session is in state iscecode)sa_excIllegalStateChangeError)selfoperation_namestates      r   _raise_for_prerequisite_state*_StateChange._raise_for_prerequisite_state7   s1     ,,#N#3 4 )%
 	
r   c                   ^^^^ U(       d   S5       eU[         R                  Lm[        SU5      mT[         R                  Lm[        R
                  SUUUU4S jj5       nU$ )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.

zno prequisite states sentzTuple[_StateChangeState, ...]c                  > UR                   nT
(       a"  UT;  a  UR                  U R                  U5        UR                  nUR                  nT	(       a  TOUnU[
        R                  La  T	(       a  XWLa  U(       aW  U[
        R                  [
        R                  4;   a3  [        R                  " SU R                   SUR                   ST< 3SS9e[        R                  " SU R                   ST< SU< 3SS9eXl        [
        R                  Ul         U " U/UQ70 UD6nUR                   UL a  UXQl        Xal        $ UR                   UL a'  [        R                  " SU R                   S	T< S
3SS9eU(       a=  [        R                  " SUR                   SU R                   SUR                   < 3SS9e[        R                  " SU R                   SUR                   < 3SS9e!   e = f! XQl        Xal        f = f)NzMethod 'z"()' can't be called here; method 'zN()' is already in progress and this would cause an unexpected state change to r.   r/   zCant run operation 'z()' here; will move to state z where we are expecting z()' failed to change state to z as expectedzWhile method 'z()' was running, method 'z)()' caused an unexpected state change to )r+   r6   r   r*   r,   r    r$   r%   r&   r1   r2   )fnr3   argkwcurrent_state
next_stateexisting_fnexpect_state	ret_valueexpect_state_changehas_prerequisite_statesmoves_toprerequisite_state_collections            r   _go(_StateChange.declare_states.<locals>._go]   s6    KKM (!)FF222;;N))J**K':8L "4"8"88'2:&00&992 $ !88"2;;- 0##.#7#7"8 9++3,8 $  !88.r{{m <..6\ :%%/N4 $	   "1DDD!/t0c0R0	 ;;,.$4 $. #. 3 ;;-/ 88"2;;- 0&\7 $	  ! 88()=)=(> ?##%;;- 0++/;;/	;
 $  !88"2;;- 0++/;;/;# /: $. #. s%   G/ (G5 B*G5 /G22G5 5H)
r:   r   r3   r   r;   r   r<   r   returnr   )r    r$   r   r%   r   	decorator)clsprerequisite_statesrD   rF   rB   rC   rE   s     ` @@@r   declare_states_StateChange.declare_states@   su    & #?$??"'9'='== 	  )-+-@)
% '.@.J.JJ	K	/ K	/ 
K	/Z 
r   c              #  :  #    U R                   [        R                  L d   S5       eXl          Sv   U R                  ULa#  [        R
                  " SU R                  < 3SS9e [        R                  U l         g!   e = f! [        R                  U l         f = f7f)zhcalled within a method that changes states.

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

zAUnexpected call to _expect_state outside of state-changing methodNzUnexpected state change to r.   r/   )r*   r    r&   r+   r1   r2   )r3   expecteds     r   _expect_state_StateChange._expect_state   s      #5#H#HH 	
$	
H
 $
	E {{(*441$++A  +
  2DDD	  2DDDs-   +BA; 2B %B;A>>B BB)r,   r*   )r4   strr5   r   rH   r	   )rK   zEUnion[Literal[_StateChangeStates.ANY], Tuple[_StateChangeState, ...]]rD   r   rH   zCallable[[_F], _F])rO   r   rH   zIterator[Any])r   r   r   r   __doc__r    r$   r*   __annotations__r%   r+   r,   r6   classmethodrL   
contextlibcontextmanagerrP   r   r   r   r   r(   r(   )   s     &8%;%;K"; 2 < <F<04K-4
!
*;
	
 j
j
 $j 
j jX E Er   r(   )rS   
__future__r   rV   enumr   typingr   r   r   r   r	   r
   r   r   r    r   r1   r   util.typingr   r   r   r    r(   r   r   r   <module>r]      ss    > "              !T#s(+,	 	* [E [Er   