
    R
h                        d Z ddlmZ ddlZddlZddlmZmZ ddl	m
Z
mZ  ej        d          Z e
d           G d	 d
                      Zde_        dS )z"
psycopg two-phase commit support
    )annotationsN)	b64decode	b64encode)	dataclassreplacez^(\d+)_([^_]*)_([^_]*)$T)frozenc                      e Zd ZU dZded<   ded<   ded<   dZd	ed
<   dZded<   dZded<   edd            Z	ddZ
ddZd dZedd            Zed!d            ZddZedd            Zed"d            ZdS )#XidzA two-phase commit transaction identifier.

    The object can also be unpacked as a 3-item tuple (`format_id`, `gtrid`,
    `bqual`).

    
int | None	format_idstrgtrid
str | NonebqualNzdt.datetime | Nonepreparedownerdatabasesreturnc                p    	 |                      |          S # t          $ r t          d|d          cY S w xY w)zTry to parse an XA triple from the string.

        This may fail for several reasons. In such case return an unparsed Xid.
        N)_parse_string	Exceptionr
   )clsr   s     W/var/www/html/01_SiteInternet/03_Maps/venv/lib/python3.11/site-packages/psycopg/_tpc.pyfrom_stringzXid.from_string!   sN    	&$$Q''' 	& 	& 	&tQ%%%%%	&s    55c                *    |                                  S N)_as_tidselfs    r   __str__zXid.__str__,   s    ||~~    intc                    dS )N    r   s    r   __len__zXid.__len__/   s    qr"   indexint | str | Nonec                6    | j         | j        | j        f|         S r   )r   r   r   )r    r(   s     r   __getitem__zXid.__getitem__2   s    
DJ7>>r"   c                   t                               |          }|st          d          t          |                    d                    }t          |                    d                                                    }t          |                    d                                                    }|                     |||          S )Nzbad Xid format      r%   )_re_xidmatch
ValueErrorr#   groupr   decode
from_parts)r   r   mr   r   r   s         r   r   zXid._parse_string5   s    MM! 	/-...

OO	!''!**%%,,..!''!**%%,,..~~i666r"   c                2   |t|t          d          d|cxk    rdk     sn t          d          t          |          dk    rt          d          t          |          dk    rt          d          n|t          d          t          |||          S )	Nz,if format_id is specified, bqual must be toor   l        z/format_id must be a non-negative 32-bit integer@   z&bqual must be not longer than 64 charsz&gtrid must be not longer than 64 charsz,if format_id is None, bqual must be None too)	TypeErrorr1   lenr
   )r   r   r   r   s       r   r4   zXid.from_parts@   s     } NOOO	....J.... !RSSS5zzB !IJJJ5zzB !IJJJ  ]JKKK9eU+++r"   c                *   | j         | j        | j        S t          | j                                                                                  }t          | j                                                                                  }| j          d| d| S )a  
        Return the PostgreSQL transaction_id for this XA xid.

        PostgreSQL wants just a string, while the DBAPI supports the XA
        standard and thus a triple. We use the same conversion algorithm
        implemented by JDBC in order to allow some form of interoperation.

        see also: the pgjdbc implementation
          http://cvs.pgfoundry.org/cgi-bin/cvsweb.cgi/jdbc/pgjdbc/org/
            postgresql/xa/RecoveredXid.java?rev=1.2
        N_)r   r   r   r   encoder3   )r    egtridebquals      r   r   zXid._as_tidQ   s     >!TZ%7: 4:,,..//66884:,,..//6688.44644F444r"   c                    dS )Nz<SELECT gid, prepared, owner, database FROM pg_prepared_xactsr&   )r   s    r   _get_recover_queryzXid._get_recover_queryg   s    MMr"   giddt.datetimec                \    t                               |          }t          ||||          S )N)r   r   r   )r
   r   r   )r   rA   r   r   r   xids         r   _from_recordzXid._from_recordk   s,     ooc""sXUXNNNNr"   )r   r   r   r
   )r   r   )r   r#   )r(   r#   r   r)   )r   r   r   r   r   r   r   r
   )
rA   r   r   rB   r   r   r   r   r   r
   )__name__
__module____qualname____doc____annotations__r   r   r   classmethodr   r!   r'   r+   r   r4   r   r@   rE   r&   r"   r   r
   r
      sn          JJJ#'H''''EH& & & [&      ? ? ? ? 7 7 7 [7 , , , [, 5 5 5 5, N N N [N O O O [O O Or"   r
   psycopg)rI   
__future__r   redatetimedtbase64r   r   dataclassesr   r   compiler/   r
   rG   r&   r"   r   <module>rT      s     # " " " " " 				     ' ' ' ' ' ' ' ' * * * * * * * *
"*/
0
0 $^O ^O ^O ^O ^O ^O ^O ^OB r"   