
    dh0                     f    d dl mZ  G d d      Z G d de      Z G d de      Z G d d	e      Zy
)   )excc                   `    e Zd ZdZd Zed        Zed        Zd Zd Z	d Z
d Zd	 Zd
 Zd Zy)Transactiona  Represent a database transaction in progress.

    The Transaction object is procured by
    calling the SAConnection.begin() method of
    SAConnection:

        with (yield from engine) as conn:
            trans = yield from conn.begin()
            try:
                yield from conn.execute("insert into x (a, b) values (1, 2)")
            except Exception:
                yield from trans.rollback()
            else:
                yield from trans.commit()

    The object provides .rollback() and .commit()
    methods in order to control transaction boundaries.

    See also:  SAConnection.begin(), SAConnection.begin_twophase(),
    SAConnection.begin_nested().
    c                 6    || _         |xs | | _        d| _        y )NT)_connection_parent
_is_active)self
connectionparents      Q/var/www/netwell/bot/venv/lib/python3.12/site-packages/aiomysql/sa/transaction.py__init__zTransaction.__init__   s    %~    c                     | j                   S )z+Return ``True`` if a transaction is active.)r	   r
   s    r   	is_activezTransaction.is_active"   s     r   c                     | j                   S )z8Return transaction's connection (SAConnection instance).)r   r   s    r   r   zTransaction.connection'   s     r   c                    K   | j                   j                  sy| j                   | u r| j                          d{    yd| _        y7 w)a0  Close this transaction.

        If this transaction is the base transaction in a begin/commit
        nesting, the transaction will rollback().  Otherwise, the
        method returns.

        This is used to cancel a Transaction without affecting the scope of
        an enclosing transaction.
        NF)r   r	   rollbackr   s    r   closezTransaction.close,   s?      ||&&<<4--/!!#DO "s   9AA	Ac                 |   K   | j                   j                  sy| j                          d{    d| _        y7 w)zRoll back this transaction.NF)r   r	   _do_rollbackr   s    r   r   zTransaction.rollback=   s4     ||&&!!! 	"s   +<:<c                 T   K   | j                   j                          d {    y 7 wN)r   r   r   s    r   r   zTransaction._do_rollbackD   s     ll##%%%   (&(c                    K   | j                   j                  st        j                  d      | j	                          d{    d| _        y7 w)zCommit this transaction.This transaction is inactiveNF)r   r	   r   InvalidRequestError
_do_commitr   s    r   commitzTransaction.commitG   sC      ||&&))*HIIoo 	 s   ?AAAc                    K   y wr    r   s    r   r   zTransaction._do_commitO   s	     s   c                    K   | S wr   r"   r   s    r   
__aenter__zTransaction.__aenter__R   s     s   c                    K   |r| j                          d {    y | j                  r| j                          d {    y y 7 +7 wr   )r   r	   r    )r
   exc_typeexc_valexc_tbs       r   	__aexit__zTransaction.__aexit__U   s>     --/!!kkm##  " $s   AA$AAAAN)__name__
__module____qualname____doc__r   propertyr   r   r   r   r   r    r   r$   r)   r"   r   r   r   r      sW    ,
      $" & $r   r   c                   *     e Zd Z fdZd Zd Z xZS )RootTransactionc                 &    t         |   |d        y r   superr   )r
   r   	__class__s     r   r   zRootTransaction.__init___   s    T*r   c                 T   K   | j                   j                          d {    y 7 wr   )r   _rollback_implr   s    r   r   zRootTransaction._do_rollbackb   s     --///r   c                 T   K   | j                   j                          d {    y 7 wr   )r   _commit_implr   s    r   r   zRootTransaction._do_commite   s     ++---r   )r*   r+   r,   r   r   r   __classcell__r4   s   @r   r0   r0   ]   s    +0.r   r0   c                   2     e Zd ZdZdZ fdZd Zd Z xZS )NestedTransactionzRepresent a 'nested', or SAVEPOINT transaction.

    A new NestedTransaction object may be procured
    using the SAConnection.begin_nested() method.

    The interface is the same as that of Transaction class.
    Nc                 &    t         |   ||       y r   r2   )r
   r   r   r4   s      r   r   zNestedTransaction.__init__t   s    V,r   c                    K   | j                   J d       | j                  r9| j                  j                  | j                   | j                         d {    y y 7 wNzBroken transaction logic)
_savepointr	   r   _rollback_to_savepoint_implr   r   s    r   r   zNestedTransaction._do_rollbackw   sX     *F,FF*??"">>/ / / /   AAAAc                    K   | j                   J d       | j                  r9| j                  j                  | j                   | j                         d {    y y 7 wr?   )r@   r	   r   _release_savepoint_implr   r   s    r   r   zNestedTransaction._do_commit}   sX     *F,FF*??""::/ / / /rB   )	r*   r+   r,   r-   r@   r   r   r   r9   r:   s   @r   r<   r<   i   s     J-//r   r<   c                   D     e Zd ZdZ fdZed        Zd Zd Zd Z	 xZ
S )TwoPhaseTransactionzRepresent a two-phase transaction.

    A new TwoPhaseTransaction object may be procured
    using the SAConnection.begin_twophase() method.

    The interface is the same as that of Transaction class
    with the addition of the .prepare() method.
    c                 B    t         |   |d        d| _        || _        y )NF)r3   r   _is_prepared_xid)r
   r   xidr4   s      r   r   zTwoPhaseTransaction.__init__   s!    T*!	r   c                     | j                   S )z Returns twophase transaction id.)rI   r   s    r   rJ   zTwoPhaseTransaction.xid   s     yyr   c                    K   | j                   j                  st        j                  d      | j                  j                  | j                         d{    d| _        y7 w)zfPrepare this TwoPhaseTransaction.

        After a PREPARE, the transaction can be committed.
        r   NT)r   r   r   r   r   _prepare_twophase_implrI   rH   r   s    r   preparezTwoPhaseTransaction.prepare   sS      ||%%))*HII55dii@@@  	As   AA%A#A%c                    K   | j                   j                  | j                  | j                         d {    y 7 wN)is_prepared)r   rollback_preparedrI   rH   r   s    r   r   z TwoPhaseTransaction._do_rollback   s8     00II4#4#4 1 6 	6 	6   5?=?c                    K   | j                   j                  | j                  | j                         d {    y 7 wrP   )r   commit_preparedrI   rH   r   s    r   r   zTwoPhaseTransaction._do_commit   s8     ..II4#4#4 / 6 	6 	6rS   )r*   r+   r,   r-   r   r.   rJ   rN   r   r   r9   r:   s   @r   rF   rF      s0    
  	!66r   rF   N) r   r   r0   r<   rF   r"   r   r   <module>rW      s;    T$ T$n	.k 	./ /6%6+ %6r   