
    2iL'                       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	m
Z
mZ ddlmZ dd	lmZ dd
lmZmZ ddlmZmZ ddlmZ ddlmZ e	rddlmZ ddlmZ ej<                  j>                  Zej@                  jB                  Z! ejD                  e#      Z$ G d de%      Z& G d dejN                        Z( G d dee         Z) G d de)d         Z* G d de)d         Z+y)zC
Transaction context managers returned by Connection.transaction()
    )annotationsN)Enum)TracebackType)TYPE_CHECKINGAnyGeneric)Iterator   )errors)pqsql)ConnectionTypePQGen)Self)connection_summary)
Connection)AsyncConnectionc                  &    e Zd ZdZdZdddZddZy)	Rollbacka  
    Exit the current `Transaction` context immediately and rollback any changes
    made within this context.

    If a transaction context is specified in the constructor, rollback
    enclosing transactions contexts up to and including the one specified.
    psycopgNc                    || _         y N)transaction)selfr   s     R/var/www/html/secretsanta/venv/lib/python3.12/site-packages/psycopg/transaction.py__init__zRollback.__init__+   s
    &    c                N    | j                   j                   d| j                  dS )N())	__class____qualname__r   r   s    r   __repr__zRollback.__repr__.   s'    ..--.a0@0@/C1EEr   r   )r   z%Transaction | AsyncTransaction | Nonereturnstr)__name__
__module__r"   __doc__r   r$    r   r   r   r       s     J'Fr   r   c                      e Zd ZdZy)OutOfOrderTransactionNestingz)Out-of-order transaction nesting detectedN)r(   r)   r"   r*   r+   r   r   r-   r-   2   s    3r   r-   c                      e Zd Z G d dee      Z	 	 d	 	 	 	 	 ddZedd       ZddZ	ddZ
	 	 	 	 	 	 	 	 ddZdd	Zdd
ZddZddZddZddZddZy)BaseTransactionc                  (    e Zd ZdZdZdZdZdZdZdZ	y)	BaseTransaction.Statusz
        The current status of a transaction.

        Exposed as the `~psycopg.Transaction.status` attribute of
        `~psycopg.Transaction` and `~psycopg.AsyncTransaction` objects.
        not_startedactive	committedfailedrolled_back_explicitlyrolled_back_with_errorN)
r(   r)   r"   r*   NOT_STARTEDACTIVE	COMMITTEDFAILEDROLLED_BACK_EXPLICITLYROLLED_BACK_WITH_ERRORr+   r   r   Statusr1   7   s)    	 $	!9!9r   r>   Nc                    || _         | j                   j                  | _        |xs d| _        || _        | j                  j
                  | _        d| _        d| _        y )N F)	_connpgconn_savepoint_nameforce_rollbackr>   r8   status_outer_transaction_stack_index)r   
connectionsavepoint_namerE   s       r   r   zBaseTransaction.__init__F   sR      
jj''-3,kk--"'r   c                    | j                   S )zV
        The name of the savepoint; `!None` if handling the main transaction.
        )rD   r#   s    r   rJ   zBaseTransaction.savepoint_nameT   s     ###r   c                $   | j                   j                   d| j                   j                   }t        | j                        }| j
                  r| j
                  dnd}d| d| d| j                  j                   d| dt        |       dd	S )
N. r@   <r   z) z at 0xx>)	r!   r)   r"   r   rC   rJ   rF   valueid)r   clsinfosps       r   r$   zBaseTransaction.__repr__]   s    **+1T^^-H-H,IJ!$++.,0,?,?##&a(R3%qAdkk//04&r$xl!LLr   c              #  2  K   | j                   | j                  j                  k7  rt        d      | j                  j                  | _         | j                          | j                         D ]%  }| j                  j                  |      E d {    ' y 7 w)Nz(transaction blocks can be used only once)	rF   r>   r8   	TypeErrorr9   _push_savepoint_get_enter_commandsrB   _exec_command)r   commands     r   
_enter_genzBaseTransaction._enter_genc   sx     ;;$++111FGGkk((//1 	9Gzz//888	98s   BBBBc              #     K   |s%| j                   s| j                         E d {    y	 | j                  |      E d {   S 7 7 # t        $ r  t        $ r!}t
        j                  d| |       Y d }~yd }~ww xY ww)NFz#error ignored in rollback of %s: %s)rE   _commit_gen_rollback_genr-   	Exceptionloggerwarning)r   exc_typeexc_valexc_tbexc2s        r   	_exit_genzBaseTransaction._exit_genl   s|      t22'')))#'#5#5g#>>? * ?/   DdDQsI   "A>AA>A A A A>A A;A61A>6A;;A>c              #     K   | j                  d      }| j                  j                  | _        |r|| j	                         D ]%  }| j
                  j                  |      E d {    ' y 7 w)Ncommit)_pop_savepointr>   r:   rF   _get_commit_commandsrB   r[   )r   exr\   s      r   r_   zBaseTransaction._commit_gen   sb       *kk++H002 	9Gzz//888	98s   A"A.$A,%A.c              #    K   t        |t              r$t        j                  | j                   dd       | j                  d      }t        |t              s| j                  r| j                  j                  | _	        n| j                  j                  | _	        |r|| j                         D ]%  }| j                  j                  |      E d {    ' | j                  j                  j                          | j                  j                  j                  | j                        E d {    t        |t              r|j                   r|j                   | u ryy7 7 2w)Nz: Explicit rollback from: T)exc_inforollbackF)
isinstancer   rb   debugrB   rk   rE   r>   r<   rF   r=   _get_rollback_commandsr[   	_preparedclearmaintain_genr   )r   re   rm   r\   s       r   r`   zBaseTransaction._rollback_gen   s    gx(LLDJJ<'ABTLR  ,gx(D,?,?++<<DK++<<DKH224 	9Gzz//888	9 	

""$::''44TZZ@@@gx(&&'*=*=*E 9 	As%   CE"EAE"-E .1E" E"c              #  .  K   | j                   r| j                  j                          | j                  r]t	        j
                  d      j                  t	        j                  | j                              j                  | j                         y y w)NzSAVEPOINT {})	rG   rB   _get_tx_start_commandrD   r   SQLformat
Identifieras_bytesr#   s    r   rZ   z#BaseTransaction._get_enter_commands   sh     ""**2244't';';<=$**%  s   BBc              #  F  K   | j                   rh| j                  s\t        j                  d      j	                  t        j
                  | j                               j                  | j                         | j                  r| j                  j                  rJ d y y w)Nz
RELEASE {}s   COMMIT	rD   rG   r   ry   rz   r{   r|   rB   _num_transactionsr#   s    r   rl   z$BaseTransaction._get_commit_commands   sw     (?(?%t';';<=$**% ""zz3333O #s   BB!c              #    K   | j                   r| j                  st        j                  d      j	                  t        j
                  | j                               j                  | j                         t        j                  d      j	                  t        j
                  | j                               j                  | j                         | j                  r| j                  j                  rJ d y y w)NzROLLBACK TO {n})nzRELEASE {n}s   ROLLBACKr~   r#   s    r   rs   z&BaseTransaction._get_rollback_commands   s     (?(?)*#..)=)=>?$**% &#..)=)=>?$**% ""zz3333 #s   C=C?c                ^   | j                   j                  t        k(  | _        | j                  r| j                  j
                  r/J | j                  s!d| j                  j
                  dz    | _        | j                  j
                  | _        | j                  xj
                  dz  c_        y)z
        Push the transaction on the connection transactions stack.

        Also set the internal state of the object and verify consistency.
        _pg3_r
   N)rC   transaction_statusIDLErG   rB   r   rD   rH   r#   s    r   rY   zBaseTransaction._push_savepoint   s     #'++"@"@D"H"" zz3333 '').tzz/K/Ka/O.P'Q$ JJ88

$$)$r   c                    | j                   xj                  dz  c_        | j                   j                  | j                  k(  ryt        d| d|        S )zy
        Pop the transaction from the connection transactions stack.

        Also verify the state consistency.
        r
   Nztransaction z at the wrong nesting level: )rB   r   rH   r-   )r   actions     r   rk   zBaseTransaction._pop_savepoint   sR     	

$$)$::''4+<+<<+6("?vF
 	
r   NF)rI   r   rJ   
str | NonerE   bool)r&   r   r%   )r&   zPQGen[None])rd   type[BaseException] | Nonere   BaseException | Nonerf   TracebackType | Noner&   PQGen[bool])re   r   r&   r   )r&   zIterator[bytes])r&   None)r   r'   r&   zException | None)r(   r)   r"   r'   r   r>   r   propertyrJ   r$   r]   rh   r_   r`   rZ   rl   rs   rY   rk   r+   r   r   r/   r/   6   s    :d :$ &*$	" # 	 $ $M9, & %	
 
296	
"*&
r   r/   c                  F    e Zd ZdZdZedd       ZddZ	 	 	 	 	 	 	 	 d	dZy)
TransactionzO
    Returned by `Connection.transaction()` to handle a transaction block.
    r   c                    | j                   S )zLThe connection the object is managing.

        :type: `Connection`
        rB   r#   s    r   rI   zTransaction.connection        zzr   c                    | j                   j                  5  | j                   j                  | j                                d d d        | S # 1 sw Y   | S xY wr   rB   lockwaitr]   r#   s    r   	__enter__zTransaction.__enter__  s>    ZZ__ 	/JJOODOO-.	/	/s   *AAc                $   | j                   j                  t        k(  rL| j                  j                  5  | j                  j                  | j                  |||            cd d d        S | j                  j                  | _        y# 1 sw Y   y xY wr   	rC   rF   OKrB   r   r   rh   r>   r;   r   rd   re   rf   s       r   __exit__zTransaction.__exit__  ss     ;;# Rzzt~~h'PQR R ++,,DK	R Rs   ,BBN)r&   Connection[Any]r&   r   rd   r   re   r   rf   r   r&   r   )r(   r)   r"   r*   r   rI   r   r   r+   r   r   r   r      P     J 
, & %	
 
r   r   r   c                  F    e Zd ZdZdZedd       ZddZ	 	 	 	 	 	 	 	 d	dZy)
AsyncTransactionzT
    Returned by `AsyncConnection.transaction()` to handle a transaction block.
    r   c                    | j                   S )zQThe connection the object is managing.

        :type: `AsyncConnection`
        r   r#   s    r   rI   zAsyncTransaction.connection  r   r   c                  K   | j                   j                  4 d {    | j                   j                  | j                                d {    d d d       d {    | S 7 G7 7 
# 1 d {  7  sw Y   | S xY wwr   r   r#   s    r   
__aenter__zAsyncTransaction.__aenter__$  sk     ::?? 	5 	5**//$//"3444	5 	5	54	5 	5 	5 	5sV   BA%B-A+A'A+BA)B'A+)B+A>1A42A>9Bc                z  K   | j                   j                  t        k(  rd| j                  j                  4 d {    | j                  j                  | j                  |||             d {   cd d d       d {    S | j                  j                  | _        y7 e7 37 %# 1 d {  7  sw Y   y xY wwr   r   r   s       r   	__aexit__zAsyncTransaction.__aexit__)  s      ;;#zz X X!ZZ__T^^Hgv-VWWX X X ++,,DK	XWX X X XsV   8B;B B;0B&.B"/B&2B;>B$?"B;"B&$B;&B8,B/-B84B;N)r&   AsyncConnection[Any]r   r   )r(   r)   r"   r*   r   rI   r   r   r+   r   r   r   r     r   r   r   r   ),r*   
__future__r   loggingenumr   typesr   typingr   r   r   collections.abcr	   r@   r   er   r   abcr   r   _compatr   pq.miscr   rI   r   connection_asyncr   TransactionStatusr   
ConnStatusr   	getLoggerr(   rb   ra   r   ProgrammingErrorr-   r/   r   r   r+   r   r   <module>r      s    #    . . $   &  '&1	  ]]			8	$Fy F$41#5#5 4z
gn- z
z/"34 D'=> r   