
    ,hI                       S r SSKJr  SSKrSSKrSSKJr  SSKJr  SSK	J
r
JrJrJrJrJr  SSKJr  SSKJr  S	S
KJr  S	SKJrJr  S	SKJrJrJrJrJrJrJ r   S	SK!J"r"  S	SK#J$r$J%r%J&r&J'r'  S	SK(J)r)  S	SK*J+r+  S	SK,J-r-  S	SK.J/r/  S	SK0J1r1J2r2J3r3  S	SK0J4r4  S	SK5J6r6  S	SK7J8r8  S	SK9J:r:  S	SK;J<r<  S	SK=J>r>  S	SK?J@r@  S	SKAJBrBJCrCJDrD  \
(       a  S	SKEJFrF  SrG\R                  R                  rI\R                  R                  rJ\R                  R                  rL\R                  R                  rM\R                  R                  rN\OrP\R                  " S5      rR " S S \B\$   5      rSg)!z*
Psycopg connection object (sync version)
    )annotationsN)	monotonic)TracebackType)TYPE_CHECKINGAny	GeneratorIteratorcastoverload)Lock)contextmanager   )errors)pqwaiting)RVAdaptContextConnDict	ConnParamParamsPQGenQuery)Xid)Row
RowFactoryargs_row	tuple_row)AdaptersMap)IsolationLevel)Cursor)Self)conninfo_attemptsconninfo_to_dictmake_conninfo)timeout_from_conninfo)Pipeline)notifies)Transaction)capabilities)ServerCursor)gssapi_requested)BaseConnection	CursorRowNotify)PGconng?psycopgc                  N  ^  \ rS rSr% SrSrS\S'   S\S'   S\S	'   S
\S'   \" \\   \	5      4   S;U 4S jjjr
\ S<SSSSSS.               S=S jjj5       rS>S jr        S?S jr\S@S j5       rSAS jr\SS.SBS jj5       r\SS.     SCS jj5       r\SSSS.         SDS jj5       r\SSSS.           SES jj5       r S<SSSSS.           SFS jjjr SGSSS.         SHS jjjrSAS  jrSAS! jrS"S#.SIS$ jjrS%S#.SIS& jjr\ SJ     SKS' jj5       rSSS(.     SLS) jjr\SMS* j5       r\SMS+ j5       r\4SNS, jjrSOS- jrSOS. jr SPS/ jr!SPS0 jr"SQS1 jr#SQS2 jr$SQS3 jr%SQS4 jr&SRS5 jr'SAS6 jr(SGSSS7 jjr)SGSSS8 jjr*STS9 jr+S:r,U =r-$ )U
Connection8   z+
Wrapper for a connection to the database.
r0   ztype[Cursor[Row]]cursor_factoryztype[ServerCursor[Row]]server_cursor_factoryRowFactory[Row]row_factoryzPipeline | None	_pipelinec                z   > [         TU ]  U5        X l        [        5       U l        [
        U l        [        U l        g N)	super__init__r7   r   lockr    r4   r*   r5   )selfpgconnr7   	__class__s      M/var/www/html/Ai_home/venv/lib/python3.13/site-packages/psycopg/connection.pyr<   Connection.__init__D   s1    
 	 &F	$%1"    F   N)
autocommitprepare_thresholdcontextr7   r4   c          	     "   U R                   " U40 UD6n[        U5      n	Sn
[        U5      n/ nU H  nUR                  S5      UR                  S5      UR                  S5      4nSU-  n[        R                  SU5         [        S0 UD6nU R                  XS9n[        R                  " U[        S9n
[        R                  S	U5          O   U
(       d  US   S   n[#        U5      S:X  a  UR!                  S5      e[        U5      /nUR                  S5        UR%                  S U 5       5        ['        U5      " SR)                  U5      5      R!                  S5      e[*        R,                  " 5       S:  aF  U
R.                  R0                  (       a+  [3        U5      (       d  [4        R6                  " S[8        5        [;        U5      U
l        U(       a  XZl        U(       a  Xjl         U(       a  [C        URD                  5      U
l#        X:l$        U
$ ! [        R                   a?  n[        R                  S
U[        U5      5        UR                  UU45         SnAGM1  SnAf[        R                   a  nUR!                  S5      eSnAff = f)zF
Connect to a database server and return a new `Connection` instance.
Nhostporthostaddrz host: %r, port: %r, hostaddr: %rzconnection attempt: %stimeoutintervalzconnection succeeded: %szconnection failed: %s: %sr   r   z7Multiple connection attempts failed. All failures were:c              3  4   #    U H  u  pS U SU 3v   M     g7f)z- z: N ).0errordescrs      rA   	<genexpr>%Connection.connect.<locals>.<genexpr>~   s     PKLEBugRw/Ks   
i q aa  the connection was obtained using the GSSAPI relying on the 'gssencmode=prefer' libpq default. In a future psycopg[binary] version this default will be changed to 'disable'. If you wish to interact with the GSSAPI reliably please set the 'gssencmode' parameter in the connection string or the 'PGGSSENCMODE' environment variable to 'prefer' or 'require' )%_get_connection_paramsr%   r"   getloggerdebugr$   _connect_genr   	wait_conn_WAIT_INTERVALeErrorstrappend_NO_TRACEBACKwith_tracebacklenextendtypejoinr   versionr?   used_gssapir+   warningswarnDeprecationWarningbool_autocommitr7   r4   r   adapters	_adaptersrF   )clsconninforE   rF   rG   r7   r4   kwargsparamsrM   rvattemptsconn_errorsattempttdescrrU   genexlast_exliness                       rA   connectConnection.connectO   s'     ++H??'/$V,13Gkk&)7;;v+>J@WXF6?ELL159(7w7&&x&A&&s^D 7?  " !"oa(G;1$,,T22 \NELLRSLLPKPQw-		% 01@@FF JJLF"		%%%f--MM t"
 j)(N .&w'7'78BL0	O 77 08%RI""B;//?? .''--.s$   3HJ'3I!!J8J		Jc                    U $ r:   rR   r>   s    rA   	__enter__Connection.__enter__   s    rC   c                   U R                   (       a  g U(       a   U R                  5         OU R                  5         [        U SS 5      (       d  U R                  5         g g ! [         a   n[        R	                  SX5         S nANIS nAff = f)Nz#error ignored in rollback on %s: %s_pool)closedrollback	Exceptionr]   warningcommitgetattrclose)r>   exc_typeexc_valexc_tbexc2s        rA   __exit__Connection.__exit__   sp     ;;R KKM tWd++JJL ,  RDdQQRs   A   
B
*BB
c                    [        U40 UD6$ )z3Manipulate connection parameters before connecting.)r#   )ru   rv   rw   s      rA   r[   !Connection._get_connection_params   s      3F33rC   c                j    U R                   (       a  gSU l        U R                  R                  5         g)zClose the database connection.NT)r   _closedr?   finishr   s    rA   r   Connection.close   s%    ;; 	rC   )binaryc                   g r:   rR   )r>   r   s     rA   cursorConnection.cursor   s    >ArC   c                   g r:   rR   )r>   r   r7   s      rA   r   r      s      rC   )r   
scrollablewithholdc                   g r:   rR   )r>   namer   r   r   s        rA   r   r      s      rC   c                   g r:   rR   )r>   r   r   r7   r   r   s         rA   r   r      s     #&rC   )r   r7   r   r   c                   U R                  5         U(       d  U R                  nU(       a  U R                  U UUUUS9nOU R                  XS9nU(       a  [        Ul        U$ )zG
Return a new `Cursor` to send commands and queries to the connection.
)r   r7   r   r   r7   )_check_connection_okr7   r5   r4   BINARYformat)r>   r   r   r7   r   r   curs          rA   r   r      sk     	!!#**K ,,'%! - C %%d%DCCJ
rC   )preparer   c                    U R                  5       nU(       a  [        Ul        UR                  XUS9$ ! [        R
                   a  nUR                  S5      eSnAff = f)z8Execute a query and return a cursor to read its results.)r   N)r   r   r   executerb   rf   rg   )r>   queryrx   r   r   r   r   s          rA   r   Connection.execute   sT    	*++-C#
;;ug;>> 	*##D))	*s   14 AAAc                    U R                      U R                  U R                  5       5        SSS5        g! , (       d  f       g= f)z/Commit any pending transaction to the database.N)r=   wait_commit_genr   s    rA   r   Connection.commit  s(    YYIId&&() YY	    6
Ac                    U R                      U R                  U R                  5       5        SSS5        g! , (       d  f       g= f)z2Roll back to the start of any pending transaction.N)r=   r   _rollback_genr   s    rA   r   Connection.rollback  s(    YYIId((*+ YYr   g      >@rL   c                   U R                  5       (       d  g[        R                  " 5       (       a'  [        R                  " U R                  US9[        S9  gU R                  5         g)ak  Cancel the current operation on the connection.

:param timeout: raise a `~errors.CancellationTimeout` if the
    cancellation request does not succeed within `timeout` seconds.

Note that a successful cancel attempt on the client is not a guarantee
that the server will successfully manage to cancel the operation.

This is a non-blocking version of `~Connection.cancel()` which
leverages a more secure and improved cancellation feature of the libpq,
which is only available from version 17.

If the underlying libpq is older than version 17, the method will fall
back to using the same implementation of `!cancel()`.
NrL   rN   )_should_cancelr)   has_cancel_safer   r`   _cancel_genra   cancel)r>   rM   s     rA   cancel_safeConnection.cancel_safe  sQ      ""$$''))   1N KKMrC         @c               ~     U R                  US9  g ! [         a   n[        R                  SU5         S nAg S nAff = f)NrL   zquery cancellation failed: %s)r   r   r]   r   )r>   rM   r   s      rA   _try_cancelConnection._try_cancel3  s=    	@W- 	@NN:B??	@s    
<7<c              #  p  #    [        XU5      nU R                  (       aB  U R                  5          U   U R                  5          Uv   SSS5        SSS5        SSS5        gU   Uv   SSS5        g! , (       d  f       N/= f! , (       d  f       N8= f! , (       d  f       g= f! , (       d  f       g= f7f)af  
Start a context block with a new transaction or nested transaction.

:param savepoint_name: Name of the savepoint used to manage a nested
    transaction. If `!None`, one will be chosen automatically.
:param force_rollback: Roll back the transaction at the end of the
    block even if there were no error (e.g. to try a no-op process).
:rtype: Transaction
N)r(   r8   pipeline)r>   savepoint_nameforce_rollbacktxs       rA   transactionConnection.transaction9  sg      ~>>>"dmmo '6"   '6o"" sc   .B6BBA2	BBB6$B%)	B62
B <B
B	B
B"B6%
B3/B6)rM   
stop_afterc             #    #    Ub  [        5       U-   n[        U[        5      nOSn[        nSnU R                  (       a  [        R
                  " S[        5        U R                     U R                  R                  nSU R                  sU l
        n  U(       a(  U(       a   UR                  5       v   US-  nU(       a  M   O} U R                  [        U R                  5      US9nU HS  n
[#        U
R$                  R'                  U5      U
R(                  R'                  U5      U
R*                  5      v   US-  nMU     Ub  XR:  a  O+U(       a"  [        [        U[        5       -
  5      nUS:  a  OM  Xpl
         SSS5        g! [        R                   a  n	U	R!                  S5      eSn	A	ff = f! Xpl
        f = f! , (       d  f       g= f7f)ac  
Yield `Notify` objects as soon as they are received from the database.

:param timeout: maximum amount of time to wait for notifications.
    `!None` means no timeout.
:param stop_after: stop after receiving this number of notifications.
    You might actually receive more than this number if more than one
    notifications arrives in the same packet.
Nr   zusing 'notifies()' together with notifies handlers on the same connection is not reliable. Please use only one of thees methodsr   rN   g        )r   minra   _notify_handlersrn   ro   RuntimeWarningr=   r?   	_encoding_notifies_backlogpopleftr   r'   rb   rf   rg   r.   relnamedecodeextrabe_pid)r>   rM   r   deadlinerO   	nreceivedencdpgnsr   pgns              rA   r'   Connection.notifiesN  s      {W,H7N3HH%H	  MM R
 YY++''C *.t/E/E%D"A!+ "#))+-%NI  a:#'99Xdkk-BX9#VD $(C"( # 2 23 7 #		 0 0 5 #

# 
 &NI $( "-)2I  #&~x)+7M#N#c>!= @ *+&Q Y$  ! :"$"3"3D"99:, *+&Q Ysa   A$G&+F;-F0F0#F&BF03F;:	GF-F((F--F00F88F;;
G	Gc              #  <  #    U R                      U R                  5         U R                  =nc  [        U 5      =ol        SSS5         W   Uv   SSS5        UR                  S:X  a-  U R                      XR                  L d   eSU l        SSS5        gg! , (       d  f       N\= f! , (       d  f       N]= f! , (       d  f       g= f! WR                  S:X  a>  U R                      XR                  L d   eSU l        SSS5        f ! , (       d  f       f = ff = f7f)z<Context manager to switch the connection into pipeline mode.Nr   )r=   r   r8   r&   levelr>   r   s     rA   r   Connection.pipeline  s      YY%%' NN*3,4TN:> 	*  ~~"YY#~~555%)DN Y # Y  Y ~~"YY#~~555%)DN YY #s|   D1B D	C	 B'C	 D4B8
D
B$ D'
B51C	 8
CD	D&D>	D
DDDc              #  B  #    U R                   (       a   e[        U SS9=ol          U   Uv   SSS5        UR                  S:X  d   eXR                   L d   eSU l         g! , (       d  f       N8= f! UR                  S:X  d   eXR                   L d   eSU l         f = f7f)zWlike pipeline() but don't acquire a lock.

Assume that the caller is holding the lock.
T)_no_lockNr   )r8   r&   r   r   s     rA   _pipeline_nolockConnection._pipeline_nolock  s      >>!!$,TD$AA>	"  >>Q&&&~~---!DN  >>Q&&&~~---!DNs1   $BA1 A A1 *B 
A.*A1 1+BBc                X    [         R                  " XR                  R                  US9$ ! [         at    U R                  R
                  [        :X  aT  U R                  SS9   [         R                  " XR                  R                  US9  e ! [        R                   a     e f = fe f = f)z
Consume a generator operating on the connection.

The function must be used on generators that don't change connection
fd (i.e. not on connect and reset).
rN   r   rL   )
r   r   r?   socket_INTERRUPTEDtransaction_statusACTIVEr   rb   QueryCanceled)r>   r~   rO   s      rA   r   Connection.wait  s    	<<[[%7%7(KK 		{{--7    -LLkk&8&88L   		s-   (+ 7B)#)BB)B$!B)#B$$B)c                &    U R                  U5        g r:   )set_autocommitr>   values     rA   _set_autocommitConnection._set_autocommit      E"rC   c                    U R                      U R                  U R                  U5      5        SSS5        g! , (       d  f       g= f)z6Method version of the `~Connection.autocommit` setter.N)r=   r   _set_autocommit_genr   s     rA   r   Connection.set_autocommit  *    YYIId..u56 YY	   !7
Ac                &    U R                  U5        g r:   )set_isolation_levelr   s     rA   _set_isolation_levelConnection._set_isolation_level  s      'rC   c                    U R                      U R                  U R                  U5      5        SSS5        g! , (       d  f       g= f)z;Method version of the `~Connection.isolation_level` setter.N)r=   r   _set_isolation_level_genr   s     rA   r   Connection.set_isolation_level  s*    YYIId33E:; YYr   c                &    U R                  U5        g r:   )set_read_onlyr   s     rA   _set_read_onlyConnection._set_read_only  s    5!rC   c                    U R                      U R                  U R                  U5      5        SSS5        g! , (       d  f       g= f)z5Method version of the `~Connection.read_only` setter.N)r=   r   _set_read_only_genr   s     rA   r  Connection.set_read_only  s*    YYIId--e45 YYr   c                &    U R                  U5        g r:   )set_deferrabler   s     rA   _set_deferrableConnection._set_deferrable  r   rC   c                    U R                      U R                  U R                  U5      5        SSS5        g! , (       d  f       g= f)z6Method version of the `~Connection.deferrable` setter.N)r=   r   _set_deferrable_genr   s     rA   r	  Connection.set_deferrable  r   r   c                    U R                      U R                  U R                  U5      5        SSS5        g! , (       d  f       g= f)z?
Begin a TPC transaction with the given transaction ID `!xid`.
N)r=   r   _tpc_begin_genr>   xids     rA   	tpc_beginConnection.tpc_begin  s,     YYIId))#./ YYr   c                    U R                      U R                  U R                  5       5        SSS5        g! , (       d  f       g= f! [        R                   a%  n[        R
                  " [        U5      5      SeSnAff = f)zF
Perform the first phase of a transaction started with `tpc_begin()`.
N)r=   r   _tpc_prepare_genrb   ObjectNotInPrerequisiteStateNotSupportedErrorrd   )r>   r   s     rA   tpc_prepareConnection.tpc_prepare  sY    	9		$//12 -- 	9%%c"g.D8	9s1   A  7A 
AA A B A<<Bc                    U R                      U R                  U R                  SU5      5        SSS5        g! , (       d  f       g= f)z*
Commit a prepared two-phase transaction.
COMMITNr=   r   _tpc_finish_genr  s     rA   
tpc_commitConnection.tpc_commit  s.     YYIId**8S9: YY	   "8
Ac                    U R                      U R                  U R                  SU5      5        SSS5        g! , (       d  f       g= f)z-
Roll back a prepared two-phase transaction.
ROLLBACKNr  r  s     rA   tpc_rollbackConnection.tpc_rollback	  s.     YYIId**:s;< YYr!  c                   U R                  5         U R                  R                  nU R                  [	        [
        R                  5      S9 nUR                  [
        R                  " 5       5        UR                  5       nS S S 5        U[        :X  a.  U R                  R                  [        :X  a  U R                  5         W$ ! , (       d  f       NH= f)Nr   )
_check_tpcinfor   r   r   r   _from_recordr   _get_recover_queryfetchallIDLEINTRANSr   )r>   statusr   ress       rA   tpc_recoverConnection.tpc_recover  s    --[[Xc.>.>%?[@CKK..01,,.C A T>dii::gEMMO
 A@s   5C
C)r   r   r8   r4   r=   r7   r5   )r?   r/   r7   r6   rY   )rv   rd   rE   rq   rF   
int | NonerG   zAdaptContext | Noner7   zRowFactory[Row] | Noner4   ztype[Cursor[Row]] | Nonerw   r   returnr!   )r3  r!   )r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | Noner3  None)rv   rd   rw   r   r3  r   )r3  r4  )r   rq   r3  Cursor[Row])r   rq   r7   RowFactory[CursorRow]r3  zCursor[CursorRow])
r   rd   r   rq   r   bool | Noner   rq   r3  zServerCursor[Row])r   rd   r   rq   r7   r6  r   r7  r   rq   r3  zServerCursor[CursorRow])r   rd   r   rq   r7   zRowFactory[Any] | Noner   r7  r   rq   r3  zCursor[Any] | ServerCursor[Any]r:   )
r   r   rx   zParams | Noner   r7  r   rq   r3  r5  )rM   floatr3  r4  )NF)r   z
str | Noner   rq   r3  zIterator[Transaction])rM   float | Noner   r2  r3  zGenerator[Notify, None, None])r3  zIterator[Pipeline])r~   z	PQGen[RV]rO   r9  r3  r   )r   rq   r3  r4  )r   zIsolationLevel | Noner3  r4  )r   r7  r3  r4  )r  z	Xid | strr3  r4  )r  zXid | str | Noner3  r4  )r3  z	list[Xid]).__name__
__module____qualname____firstlineno____doc____annotations__r
   r   r   r   r<   classmethodr   r   r   r[   r   r   r   r   r   r   r   r   r   r   r'   r   r   ra   r   r   r   r   r   r  r  r
  r	  r  r  r  r$  r0  __static_attributes____classcell__)r@   s   @rA   r2   r2   8   s    J%%22  
 (,JsOY'G	2	2 %	2 	2  C !()'+.237CC 	C
 &C %C ,C 1C C 
C CJ, & %	
 
. 4 4 ',A A %  4I 	    
 "&   	 
      
    
 "&&& 	&
 +&  & & 
!& &   .2"&   	 
 ,       
) J !%*
  $** *
 * * 
*$*
,
 /3 4 /2 @ HM(AE	 * *.E+&E+;EE+	&E+N * *$ " "( =K (#7
(<
"6
#7
09;=
 
rC   r2   )Tr>  
__future__r   loggingrn   timer   typesr   typingr   r   r   r	   r
   r   	threadingr   
contextlibr   rZ   r   rb   r   r   abcr   r   r   r   r   r   r   _tpcr   rowsr   r   r   r   adaptr   _enumsr   r   r    _compatr!   rv   r"   r#   r$   r%   r8   r&   
generatorsr'   r   r(   _capabilitiesr)   _server_cursorr*   _conninfo_utilsr+   _connection_baser,   r-   r.   pq.abcr/   ra   FormatTEXTr   TransactionStatusr,  r   r-  KeyboardInterruptr   	getLoggerr]   r2   rR   rC   rA   <module>r[     s    #     J J  %   L L L  6 6  "   H H +    $ ' ( - ? ?	yy~~				  				$	$



&
& 			9	%b$ brC   