§
    eŠtj   ã                  ó6  — d Z ddlmZ ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ  ededef         ¬¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ d¦  «        ZdS )z7State tracking utilities used by :class:`_orm.Session`.é    )ÚannotationsN)ÚEnum)ÚAny)ÚCallable)Úcast)ÚIterator)ÚNoReturn)ÚOptional)ÚTuple)ÚTypeVar)ÚUnioné   )Úexc)Úutil)ÚLiteralÚ_F.)Úboundc                  ó   — e Zd ZdS )Ú_StateChangeStateN)Ú__name__Ú
__module__Ú__qualname__© ó    úZ/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sqlalchemy/orm/state_changes.pyr   r      s   € € € € € Ø€Dr   r   c                  ó   — e Zd ZdZdZdZdS )Ú_StateChangeStatesé   r   é   N)r   r   r   ÚANYÚ	NO_CHANGEÚCHANGE_IN_PROGRESSr   r   r   r   r   #   s    € € € € € Ø
€CØ€IØÐÐÐr   r   c                  ó”   — e Zd ZU dZej        Zded<   ej        Z	ded<   dZ
ded<   dd„Zedd„¦   «         Zej        dd„¦   «         ZdS )Ú_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Ú_stateNzOptional[Callable[..., Any]]Ú_current_fnÚoperation_nameÚstrÚstateÚreturnr	   c                ó:   — t          j        d|› d|›�d¬¦  «        ‚)NúCan't run operation 'z()' when Session is in state Úisce©Úcode)Úsa_excÚIllegalStateChangeError)Úselfr(   r*   s      r   Ú_raise_for_prerequisite_statez*_StateChange._raise_for_prerequisite_state7   s?   € õ Ô,ð% Nð %ð %Ø ð%ð %àð
ñ 
ô 
ð 	
r   Úprerequisite_statesúEUnion[Literal[_StateChangeStates.ANY], Tuple[_StateChangeState, ...]]Úmoves_toúCallable[[_F], _F]c                ó´   ‡‡‡‡— |s
J d¦   «         ‚|t           j        uŠt          d|¦  «        Š‰t           j        uŠt          j        dˆˆˆˆf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.

        zno prerequisite states sentzTuple[_StateChangeState, ...]Úfnr   r3   r   ÚargÚkwr+   c                ó&  •— |j         }‰
r|‰vr|                     | j        |¦  «         |j        }|j        }‰	r‰n|}|t
          j        uro‰	rm||uri|rC|t
          j        t
          j        fv r)t          j
        d| j        › d|j        › d‰›�d¬¦  «        ‚t          j
        d| j        › d‰›d|›�d¬¦  «        ‚| |_        t
          j        |_        	  | |g|¢R i |¤Ž}|j         |u r|||_        ||_        S |j         |u r"t          j
        d| j        › d	‰›d
�d¬¦  «        ‚|r.t          j
        d|j        › d| j        › d|j         ›�d¬¦  «        ‚t          j
        d| j        › d|j         ›�d¬¦  «        ‚#  ‚ xY w# ||_        ||_        w xY w)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/   r-   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&   r4   r   r%   r'   r   r    r!   r"   r1   r2   )r:   r3   r;   r<   Úcurrent_stateÚ
next_stateÚexisting_fnÚexpect_stateÚ	ret_valueÚexpect_state_changeÚhas_prerequisite_statesr7   Úprerequisite_state_collections            €€€€r   Ú_goz(_StateChange.declare_states.<locals>._go]   s¿  ø€ à œKˆMð (ðOà!Ð)FÐFÐFà×2Ò2°2´;ÀÑNÔNÐNàÔ)ˆJØÔ*ˆKØ':ÐM˜8˜8ÀˆLð Õ"4Ô"8Ð8Ð8à'ð 9ð  lÐ2Ð2àð  :Ý&Ô0Ý&Ô9ð2ð $ð $õ !Ô8ð8 2¤;ð 8ð 8Ø#.Ô#7ð8ð 8ð ,4ð8ð 8ð $ðñ ô ð õ !Ô8ð4°´ð 4ð 4Ø.6ð4ð 4à%/ð4ð 4ð $ð	ñ ô ð ð  "ˆDÔÝ1ÔDˆDÔð!/Ø˜B˜tÐ0 cÐ0Ð0Ð0¨RÐ0Ð0�	ð ”; ,Ð.Ð.Ø$ð4 $.�Ô Ø#.�Ô Ð ð3 ”; -Ð/Ð/Ý Ô8ð7 2¤;ð 7ð 7à&ð7ð 7ð 7ð $ð	ñ ô ð ð !ð Ý Ô8ð;¨Ô)=ð ;ð ;à#%¤;ð;ð ;ð ,0¬;ð	;ð ;ð
 $ðñ ô ð õ !Ô8ð; 2¤;ð ;ð ;Ø+/¬;ð;ð ;à#ðñ ô ð øð/Øøøøøð: $.�Ô Ø#.�Ô Ð.Ð.Ð.Ð.s%   ÃE: Ã 
F  Ã9BF  Å:E=Å=F  Æ F)
r:   r   r3   r   r;   r   r<   r   r+   r   )r   r    r   r!   r   Ú	decorator)Úclsr5   r7   rF   rC   rD   rE   s     ` @@@r   Údeclare_statesz_StateChange.declare_states@   s¡   øøøø€ ð& #ÐAÐAÐ$AÑAÔAÐ"àÕ'9Ô'=Ð=ð 	 õ )-Ø+Ð-@ñ)
ô )
Ð%ð 'Õ.@Ô.JÐJÐå	ŒðK	/ð K	/ð K	/ð K	/ð K	/ð K	/ð K	/ð K	/ñ 
ŒðK	/ðZ ˆ
r   ÚexpectedúIterator[Any]c              #  ó  K  — | j         t          j        u s
J d¦   «         ‚|| _         	 dV — | j        |urt	          j        d| j        ›�d¬¦  «        ‚n#  ‚ xY w	 t          j        | _         dS # t          j        | _         w xY 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 methodNzUnexpected state change to r.   r/   )r%   r   r"   r&   r1   r2   )r3   rJ   s     r   Ú_expect_statez_StateChange._expect_state­   s¾   è è € ð ÔÕ#5Ô#HÐHÐHÐHð$ñ IÔHÐHð
 $ˆÔð
	EØˆEˆEˆEð Œ{ (Ð*Ð*ÝÔ4ØA°$´+ÐAÐAÈðñ ô ð ð +øð	Øøøøà*õ
  2ÔDˆDÔÐÐøÕ1ÔDˆDÔÐDÐDÐDÐDs   ¨A ¬(A. ÁAÁA. Á.B)r(   r)   r*   r   r+   r	   )r5   r6   r7   r   r+   r8   )rJ   r   r+   rK   )r   r   r   Ú__doc__r   r    r%   Ú__annotations__r!   r&   r'   r4   ÚclassmethodrI   Ú
contextlibÚcontextmanagerrM   r   r   r   r$   r$   )   s¾   € € € € € € ðð ð &8Ô%;€KÐ;Ð;Ð;Ñ;Ø 2Ô <€FÐ<Ð<Ð<Ñ<Ø04€KÐ4Ð4Ð4Ñ4ð
ð 
ð 
ð 
ð ðjð jð jñ „[ðjðX ÔðEð Eð Eñ ÔðEð Eð Er   r$   )rN   Ú
__future__r   rQ   Úenumr   Útypingr   r   r   r   r	   r
   r   r   r   Ú r   r1   r   Úutil.typingr   r   r   r   r$   r   r   r   ú<module>rX      sÍ  ðð >Ð =à "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !à€WˆT˜ # s (Ô+Ð,Ñ,Ô,€ð	ð 	ð 	ð 	ð 	˜ñ 	ô 	ð 	ðð ð ð ð Ð*ñ ô ð ð[Eð [Eð [Eð [Eð [Eñ [Eô [Eð [Eð [Eð [Er   