L idZddlmZddlZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZededefZGddeZGddeZGddZy)z7State tracking utilities used by :class:`_orm.Session`.) annotationsN)Enum)Any)Callable)cast)Iterator)NoReturn)Optional)Tuple)TypeVar)Union)exc)util)Literal_F.)boundc eZdZy)_StateChangeStateN)__name__ __module__ __qualname__b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/orm/state_changes.pyrrsrrceZdZdZdZdZy)_StateChangeStatesrN)rrrANY NO_CHANGECHANGE_IN_PROGRESSrrrrr#s CIrrceZdZUdZej Zded<ejZ ded<dZ ded< d dZ e d d Z ejd d Zy) _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_fnc<tjd|d|d)NzCan't run operation 'z()' when Session is in state iscecode)sa_excIllegalStateChangeError)selfoperation_namestates r_raise_for_prerequisite_statez*_StateChange._raise_for_prerequisite_state7s1,,#N#34 ) %  rc|sJd|tjutd|tjutj dfd }|S)aMethod 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, ...]c|j} r | vr|j|j||j}|j} r n|}|t j ur r||ur|rV|t jt jfvr4tjd|jd|jd dtjd|jd d|d||_t j|_ ||g|i|}|j|ur|||_||_S|j|ur(tjd|jd d d|r>tjd |jd |jd |jdtjd|jd |jd#xYw#||_||_wxYw)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&r1rr%r'rr r!r"r,r-) fnr.argkw current_state next_state existing_fn expect_state ret_valueexpect_state_changehas_prerequisite_statesmoves_toprerequisite_state_collections r_goz(_StateChange.declare_states.._go]sB KKM(!)FF222;; N))J**K':8 L"4"8"88'l2:&00&992$!88"2;;-0##.#7#7"89++3,8$ !88.r{{m<..6\:%%/N4$  "D 1DDD ! /t0c0R0 ;;,.$4$. #. 3;;-/ 88"2;;-0&\7$  ! 88()=)=(>?##%;;-0++/;;/ ; $ !88"2;;-0++/;;/;#/ :$. #. s% GG/B'GGGG,) r4rr.rr5rr6rreturnr)rr rr!r decorator)clsprerequisite_statesr>r@r<r=r?s ` @@@rdeclare_statesz_StateChange.declare_states@so&#?$??" '9'='= = )- +-@) %'.@.J.JJ K / K /Z rc#:K|jtjusJd||_ d|j|ur$t j d|jd tj|_y#xYw#tj|_wxYww)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%rr"r&r,r-)r.expecteds r _expect_statez_StateChange._expect_states#5#H#HH  $ H $ E {{(*441$++A+ 2DDD    2DDD s-+BA;2B%B;A>>BBB)r/strr0rrAr )rDzEUnion[Literal[_StateChangeStates.ANY], Tuple[_StateChangeState, ...]]r>rrAzCallable[[_F], _F])rGrrAz Iterator[Any])rrr__doc__rr r%__annotations__r!r&r'r1 classmethodrE contextlibcontextmanagerrHrrrr$r$)s&8%;%;K"; 2 < rTss>"! T#s(+,  * [E[Er