zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
U
¸ý°d|ã@súdZddlmZddlZddlmZddlmZddlmZddlm    Z    ddlm
Z
dd    lm Z dd
lm Z dd lm 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úSd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/orm/state_changes.pyr!src@seZdZdZdZdZdS)Ú_StateChangeStatesér éN)rrrÚANYÚ    NO_CHANGEÚCHANGE_IN_PROGRESSrrrrr%src@sxeZdZUdZejZded<ejZ    ded<dZ
ded<ddd    d
œd d „Z e d dddœdd„ƒZ ejdddœdd„ƒ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Ústrr)Úoperation_nameÚstateÚreturncCst d|›d|›¡‚dS)NzCan't run operation 'z()' when Session is in state )Úsa_excÚIllegalStateChangeError)Úselfr$r%rrrÚ_raise_for_prerequisite_state9sÿz*_StateChange._raise_for_prerequisite_statezEUnion[Literal[_StateChangeStates.ANY], Tuple[_StateChangeState, ...]]zCallable[[_F], _F])Úprerequisite_statesÚmoves_tor&csT|s tdƒ‚|tjk    ‰td|ƒ‰ˆtjk    ‰tjddddddœ‡‡‡‡fdd„ ƒ}|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, ...]rr)Úfnr)ÚargÚkwr&c    sj|j}ˆr |ˆkr | |j|¡|j}|j}ˆr4ˆn|}|tjk    r¢ˆr¢||k    r¢|r„|tjtjfkr„t     
d|j›d|j›dˆ›¡‚nt     
d|j›dˆ›d|›¡‚||_tj|_z¦z||f|ž|Ž}Wn‚Yn€X|j|krè|W¢rS|j|krt     
d|j›dˆ›d¡‚nD|r:t     
d    |j›d
|j›d |j›¡‚nt     
d|j›d |j›¡‚W5||_||_XdS) NzMethod 'z"()' can't be called here; method 'zN()' is already in progress and this would cause an unexpected state change to 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()    r-r)r.r/Z current_stateÚ
next_stateZ existing_fnZ expect_stateZ    ret_value©Zexpect_state_changeZhas_prerequisite_statesr,Zprerequisite_state_collectionrrÚ_go^s\ÿþ þüúþÿÿ
 ÿÿÿz(_StateChange.declare_states.<locals>._go)ÚAssertionErrorrrrrrÚ    decorator)Úclsr+r,r2rr1rÚdeclare_statesAs ÿÿ
"Iz_StateChange.declare_statesz Iterator[Any])Úexpectedr&ccsd|jtjkstdƒ‚||_z:z
dVWn‚YnX|j|k    rRt d|j›¡‚W5tj|_XdS)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 rrr3r!r'r()r)r7rrrÚ _expect_stateªsÿ
 
 
ÿz_StateChange._expect_state)rrrÚ__doc__rrr Ú__annotations__rr!r"r*Ú classmethodr6Ú
contextlibÚcontextmanagerr8rrrrr+s
     hr)r9Ú
__future__rr<ÚenumrÚtypingrrrrrr    r
r r Úrr'rZ util.typingrrrrrrrrrÚ<module>s&