
    iT                    \   d Z ddlmZ ddlmZmZmZmZmZ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mZmZmZ dd
l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! ddl"m#Z#m$Z$m%Z% ddl&m'Z' erddlm(Z( ddl)m*Z*m+Z+ ejX                  jZ                  Z-ejX                  j\                  Z.ej^                  j`                  Z0ej^                  jb                  Z1ej^                  jd                  Z2ej^                  jf                  Z3ej^                  jh                  Z4ej^                  jj                  Z5ej^                  jl                  Z6ej^                  jn                  Z7ej^                  jp                  Z8ej^                  jr                  Z9ejt                  jv                  Z; G d deeef         Z<y)z
Psycopg BaseCursor object
    )annotations)TYPE_CHECKINGAnyGenericIterableNoReturnSequence)partial   )adapt)errors)pq)ConnectionTypeParamsPQGenQuery)RowRowMaker)Column)connection_summary)PostgresClientQueryPostgresQuery)Prepare)executefetchsend)capabilities)Transformer)PGconnPGresultc                     e Zd ZU dj                         Zded<   ded<   ded<   eZded	<   d3d
Zd4d5dZ	d6dZ
ed7d       Zed8d       Zed9d       Zed:d       Zed;d       Zed<d       Zd=dZd>d?dZd@dZedAd       ZdBdZ	 d>ddd	 	 	 	 	 	 	 	 	 dCdZ	 	 	 	 	 	 	 	 dDdZ	 	 	 	 	 	 	 	 dDdZddd	 	 	 	 	 	 	 dEdZ	 d>	 	 	 	 	 dFdZ	 d>dd	 	 	 	 	 	 	 	 	 dGd ZdHd!Zd>dId"Z	 d>	 	 	 	 	 dJd#Zd$dd%	 	 	 	 	 	 	 dKd&Z 	 d>	 	 	 	 	 dLd'Z!dMd(Z"dNd)Z#d>dOd*Z$dMd+Z%dPd,Z&dd	 	 	 	 	 	 	 dQd-Z'dRd.Z(dSd/Z)dTd0Z*dUd1Z+ed6d2       Z,y)V
BaseCursorz
        _conn format _adapters arraysize _closed _results pgresult _pos
        _iresult _rowcount _query _tx _last_query _row_factory _make_row
        _pgconn _execmany_returning
        __weakref__
        r   _txRowMaker[Row]	_make_rowr   _pgconnztype[PostgresQuery]
_query_clsc                    || _         t        | _        |j                  | _        t        j                  |j                        | _        d| _	        d| _
        d | _        | j                          y )Nr   F)_connTEXTformatpgconnr&   r   AdaptersMapadapters	_adapters	arraysize_closed_last_query_reset)self
connections     t/var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/venv/lib/python3.12/site-packages/psycopg/_cursor_base.py__init__zBaseCursor.__init__:   sT    
!((**:+>+>?)-    c                p    g | _         d | _        d| _        d| _        d| _        |  d | _        |rd | _        y y )Nr   )_resultspgresult_pos_iresult	_rowcount_execmany_returning_query)r4   reset_querys     r6   r3   zBaseCursor._resetD   s?    (*)-	04 DK r8   c           
     ^   | j                   j                   d| j                   j                   }t        | j                        }| j
                  rd}nB| j                  r4t        j                  | j                  j                        j                  }nd}d| d| d| dt        |       dd		S )
N.closedz	no result<z [z] z at 0xx>)	__class__
__module____qualname__r   r&   r1   r<   r   
ExecStatusstatusnameid)r4   clsinforM   s       r6   __repr__zBaseCursor.__repr__P   s    **+1T^^-H-H,IJ!$,,/<<F]]]]4==#7#78==F F3%r&D64|1==r8   c                    | j                   S )z$The connection this cursor is using.)r)   r4   s    r6   r5   zBaseCursor.connection[   s     zzr8   c                    | j                   S N)r/   rT   s    r6   r.   zBaseCursor.adapters`   s    ~~r8   c                    | j                   S )z`True` if the cursor is closed.)r1   rT   s    r6   rE   zBaseCursor.closedd   s     ||r8   c                   | j                   }|rr|j                  s9|j                  t        k(  s&|j                  t        k(  s|j                  t
        k(  r-t        |j                        D cg c]  }t        | |       c}S yc c}w )z
        A list of `Column` objects describing the current resultset.

        `!None` if the current resultset didn't return tuples.
        N)r<   nfieldsrM   	TUPLES_OKSINGLE_TUPLETUPLES_CHUNKranger   )r4   resis      r6   descriptionzBaseCursor.descriptioni   sf     mm
 KKzzY&zz\)zz\)-23;;-?@F4O@@ As   +Bc                    | j                   S )z6Number of records affected by the precedent operation.)r?   rT   s    r6   rowcountzBaseCursor.rowcount   s     ~~r8   c                x    | j                   xr | j                   j                  t        k(  }|r| j                  S dS )zoIndex of the next row to fetch in the current result.

        `!None` if there is no result to fetch.
        N)r<   rM   rZ   r=   )r4   tupless     r6   	rownumberzBaseCursor.rownumber   s2     D4==#7#79#D"tyy,,r8   c                     y rV    )r4   sizess     r6   setinputsizeszBaseCursor.setinputsizes       r8   Nc                     y rV   rg   )r4   sizecolumns      r6   setoutputsizezBaseCursor.setoutputsize   rj   r8   c                    | j                   t        | j                        dz
  k  r| j                  | j                   dz          yy)a  
        Move to the result set of the next query executed through `executemany()`
        or to the next result set if `execute()` returned more than one.

        Return `!True` if a new result is available, which will be the one
        methods `!fetch*()` will operate on.
        r   TN)r>   lenr;   _select_current_resultrT   s    r6   nextsetzBaseCursor.nextset   s;     ==3t}}-11''(9:r8   c                r    | j                   r| j                   j                  nd}|r|j                         S dS )z
        The command status tag from the last SQL command executed.

        `!None` if the cursor doesn't have a result available.
        N)r<   command_statusdecode)r4   msgs     r6   statusmessagezBaseCursor.statusmessage   s.     /3mmdmm**"szz|,,r8   c                    t         rV   )NotImplementedErrorrT   s    r6   _make_row_makerzBaseCursor._make_row_maker   s    !!r8   preparebinaryc             #    K   | j                  |      E d{    | j                  ||      }| j                  |||      E d{    | j                  j                  r,| j                  j                  j                         E d{    || _        | j                  j                  j                  | j                        E d{    y7 7 7 G7 w)z*Generator implementing `Cursor.execute()`.Nr{   )	_start_query_convert_query_maybe_prepare_genr)   	_pipeline_communicate_genr2   	_preparedmaintain_gen)r4   queryparamsr|   r}   pgqs         r6   _execute_genzBaseCursor._execute_gen   s      $$U+++!!%0**3*OOO::zz++<<>>> ::''44TZZ@@@ 	,O> 	AsF   CC-CCACC=CCCCCCc              #  L  K   | j                   j                  }|sJ | j                  |      E d{    |sd| _        | j                  J || _        d}|D ]d  }|r| j                  ||      }|| _        d}nj                  |       | j                  |d      E d{    |j                         E d{    f || _
        |r|j                  d      E d{    | j                   j                  j                  | j                         E d{    y7 7 {7 e7 B7 w)zY
        Generator implementing `Cursor.executemany()` with pipelines available.
        Nr   TFr|   )flush)r)   r   r   r?   r@   r   rA   dumpr   r   r2   
_fetch_genr   r   )r4   r   
params_seq	returningpipelinefirstr   r   s           r6   _executemany_gen_pipelinez$BaseCursor._executemany_gen_pipeline   s"     ::''x$$U+++DN''///#,   		3F))%8! ..sD.AAA00222		3 !***666::''44TZZ@@@1 	,  B2
 7@sX   /D$DA.D$ D!D$8D9$D$D 6D$D"D$D$D$ D$"D$c              #    K   | j                  |      E d{    |sd| _        | j                  J || _        d}|D ]L  }|r| j                  ||      }|| _        d}nj                  |       | j                  |d      E d{    N || _        | j                  j                  j                  | j                        E d{    y7 7 G7 	w)z]
        Generator implementing `Cursor.executemany()` with pipelines not available.
        Nr   TFr   )r   r?   r@   r   rA   r   r   r2   r)   r   r   )r4   r   r   r   r   r   r   s          r6   _executemany_gen_no_pipelinez'BaseCursor._executemany_gen_no_pipeline   s      $$U+++DN''///#,   	BF))%8! ..sD.AAA	B !::''44TZZ@@@' 	,  B 	As4   CCA.CC?CCCCCc             #    K   | j                  ||      \  }}|t        j                  u r| j                  ||       n|t        j                  u r{| j                  ||       | j                  j                  sSt        | j                        E d {   \  }|j                  t        k(  r!t        j                  || j                        | j                  |||       | j                  j                   j#                  |||      }| j                  j                  r;d }||||f}| j                  j                  j$                  j'                  | |f       y t        | j                        E d {   }	|(| j                  j                   j)                  ||||	       | j+                  |	       | j-                  |	       y 7 17 Tw)Nr}   encoding)_get_preparedr   NO_execute_sendSHOULD_send_preparer)   r   r   r&   rM   FATAL_ERROReerror_from_result	_encoding_send_query_preparedr   maybe_add_to_cacheresult_queueappendvalidate_check_results_set_results)
r4   r   r|   r}   preprN   resultkeyqueuedresultss
             r6   r   zBaseCursor._maybe_prepare_gen  sy     ''W5
d7::s62 w~~%""4-zz+++24<<+@ @IV}}311&4>>RR%%dC%?
 jj""55c4F::FtT*JJ  --44dF^D %T\\22?JJ  ))#tT7CG$'"3 !A& 3s&   BGGCG/G0AGGc                N    | j                   j                  j                  ||      S rV   )r)   r   get)r4   r   r|   s      r6   r   zBaseCursor._get_prepared4  s!     zz##''W55r8   r   c             #    K   | j                  |      E d{    | j                  ||      }| j                  ||d       |dk  rt        d      |dk(  r| j                  j                          n1t        j                  d       | j                  j                  |       || _	        t        | j                        E d{    y7 7 w)z2Generator to send the query for `Cursor.stream()`.NT)r}   force_extendedr   zsize must be >= 1)check)r   r   r   
ValueErrorr&   set_single_row_moder   has_stream_chunkedset_chunked_rows_moder2   r   )r4   r   r   r}   rl   r   s         r6   _stream_send_genzBaseCursor._stream_send_gen9  s      $$U+++!!%03vdC!8011QYLL,,.++$7LL..t4 %%% 	, 	&s"   CCB*CC
C
Cc              #    K   t        | j                        E d {   }|y |j                  }|t        k(  s	|t        k(  r=|| _        | j                  j                  ||       |r| j                         | _	        |S |t        k(  s	|t        k(  rA|r t        | j                        E d {   }|r |t        k7  rt        j                  d      y | j                  |      S 7 7 9w)N)set_loadersz1the operation in stream() didn't produce a result)r   r&   rM   r[   r\   r<   r#   set_pgresultrz   r%   rZ   
COMMAND_OKr   ProgrammingError_raise_for_result)r4   r   r^   rM   s       r6   _stream_fetchone_genzBaseCursor._stream_fetchone_genO  s     */*==;\!V|%;DMHH!!#5!9!%!5!5!7Jy Fj$8!&t||!44 "((G   ))#..1  > 5s(   C&C"BC&*C$+C&21C&$C&c              #  ,  K   | j                   rt        j                  d      | j                          | j                  r| j                  |ur!d| _        t        j                  |       | _        | j                  j                         E d{    y7 w)zGenerator to start the processing of a query.

        It is implemented as generator because it may send additional queries,
        such as `begin`.
        the cursor is closedN)
rE   r   InterfaceErrorr3   r2   r   r   r#   r)   r   )r4   r   s     r6   r   zBaseCursor._start_queryj  sp      ;;""#9::D$4$4E$A#D((.DH::**,,,s   B
BBBc              #    K   | j                   j                  rt        j                  d      | j	                         E d{    |r3t        | j                        }|j                  ||       |j                  }| j                  |      }| j                  |d       t        t        | j                        E d{   x}      dk7  rt        j                  d      | j                  |d          | j!                  |       y7 7 Jw)z<Generator implementing sending a command for `Cursor.copy().z$COPY cannot be used in pipeline modeNFr   r   z*COPY cannot be mixed with other operationsr   )r)   r   r   NotSupportedErrorr   r   r#   convertr   r   r   rp   r   r&   r   _check_copy_resultr   )r4   	statementr   r   r   r   s         r6   _start_copy_genzBaseCursor._start_copy_geny  s      ::%%&LMM$$&&& %dhh/CKK	6*		I##I.5/gdll&;;<w=B$$%QRR
+'" 	' <s%   ?D	DA:D	<D=A	D	D	F)r   r}   c          
     x   || j                   }n|rt        nt        }|| _        | j                  j
                  r{| j                  j
                  j                  j                  t        | j                  j                  |j                  |j                  |j                  |j                  |             y|s|j                  s	|t        k(  rI| j                  j                  |j                  |j                  |j                  |j                  |       y| j                  j                  |j                         y)z
        Implement part of execute() before waiting common to sync and async.

        This is not a generator, but a normal non-blocking function.
        N)param_formatsparam_typesresult_format)r+   BINARYr*   rA   r)   r   command_queuer   r
   r&   send_query_paramsr   r   formatstypes
send_query)r4   r   r   r}   fmts        r6   r   zBaseCursor._execute_send  s     >++C"&C:: JJ  ..55LL22KKLL"'-- %"%	 u||sf}LL**#mm!KK! +  LL##EKK0r8   c                `    | j                  | j                        }|j                  ||       |S rV   )r'   r#   r   )r4   r   r   r   s       r6   r   zBaseCursor._convert_query  s)     oodhh'E6"
r8   c                    |st        j                  d      |D ]=  }|j                  }|t        k7  s|t        k7  s#|t
        k7  s-| j                  |       ? y)z
        Verify that the results of a query are valid.

        Verify that the query returned at least one result and that they all
        represent a valid result from the database.
        zgot no result from the queryN)r   InternalErrorrM   rZ   r   EMPTY_QUERYr   )r4   r   r^   rM   s       r6   r   zBaseCursor._check_results  sS     //"@AA 	,CZZF"v';+@U&&s+	,r8   c                t   |j                   x}t        k(  r!t        j                  || j                        |t
        k(  rt        j                  d      |t        k(  s|t        k(  s	|t        k(  rt        j                  d      t        j                  dt        j                  |      j                         )zV
        Raise an appropriate error message for an unexpected database result
        r   pipeline abortedz8COPY cannot be used with this method; use copy() insteadz%unexpected result status from query: )rM   r   r   r   r   PIPELINE_ABORTEDPipelineAbortedCOPY_INCOPY_OUT	COPY_BOTHr   r   r   rL   rN   r4   r   rM   s      r6   r   zBaseCursor._raise_for_result  s     mm#F3%%ft~~FF''##$677w&H"4)8K$$J  //:2==;P;U;U:VW r8   c                v   || _         | j                  |   x}| _        | j                  j	                  ||       d| _        |j                  t        k(  r| j                  j                  | _	        n4|j                  t        k7  r!| j                  j                  }||nd| _	        | j                         | _        y)zL
        Select one of the results in the cursor as the active one.
        )r+   r   Nr:   )r>   r;   r<   r#   r   r=   rM   rZ   ntuplesr?   r   command_tuplesrz   r%   )r4   r_   r+   r^   nrowss        r6   rq   z!BaseCursor._select_current_result  s     "mmA..dm
 	c&1	::"!]]22DN
 ZZ8#MM00E&+&7URDN--/r8   c                D   | j                   !|| j                  d d  | j                  d       y | j                   r=| j                   }| j                  j                  |       |r| j                  d       y y |D ]%  }| xj                  |j
                  xs dz  c_        ' y )Nr   )r@   r;   rq   extendr?   r   )r4   r   first_batchr^   s       r6   r   zBaseCursor._set_results  s    ##+&DMM!''*%%"mm+KMM  )++A. 
  :#"4"4"99:r8   c                   | j                   j                  r| j                   j                  j                  j                  t	        | j
                  j                  ||j                  |j                               | j                   j                  j                  j                  d        y | j
                  j                  ||j                  |j                         y )N)r   )
r)   r   r   r   r
   r&   send_preparer   r   r   )r4   rN   r   s      r6   r   zBaseCursor._send_prepare  s    ::JJ  ..55LL--KK %	 JJ  --44T:LL%%dEKKU[[%Qr8   c          	        || j                   }n|rt        nt        }| j                  j                  rf| j                  j                  j
                  j                  t        | j                  j                  ||j                  |j                  |             y | j                  j                  ||j                  |j                  |       y )N)r   r   )r+   r   r*   r)   r   r   r   r
   r&   send_query_preparedr   r   )r4   rN   r   r}   r   s        r6   r   zBaseCursor._send_query_prepared!  s     >++C"&C::JJ  ..55LL44JJ"%++"% LL,,cjj3 - r8   c                B   | j                   rt        j                  d      | j                  x}st        j                  d      |j
                  x}t        k(  r|S |t        k(  r!t        j                  || j                        |t        k(  rt        j                  d      |j                  rd|j                  j                          d}n&	 t        j                  |      j                   }d| d}t        j                  d	|       # t"        $ r | d}Y .w xY w)
Nr   zno result availabler   r   z (command status: )z
 - unknownz (result status: z)the last operation didn't produce records)rE   r   r   r<   r   rM   rZ   r   r   r   r   r   rt   ru   r   rL   rN   r   )r4   r^   rM   detailstatus_names        r6   _check_result_for_fetchz"BaseCursor._check_result_for_fetch8  s   ;;""#9::}}$$$$%:;;jj FY.J{"%%cDNNCC''##$677!!-c.@.@.G.G.I-J!L8"$--"7"<"<K -[M;$$;F8D  " 8%+HJ"7K8s   D DDc                    |j                   }|t        k(  s	|t        k(  ry|t        k(  r!t	        j
                  || j                        t	        j                  dt        j                  |      j                         )zV
        Check that the value returned in a copy() operation is a legit COPY.
        Nr   zZcopy() should be used only with COPY ... TO STDOUT or COPY ... FROM STDIN statements, got )rM   r   r   r   r   r   r   r   r   rL   rN   r   s      r6   r   zBaseCursor._check_copy_resultR  sq     W( 2{"%%ft~~FF$$//1}}V/D/I/I.JL r8   c                    | j                         }|dk(  r| j                  |z   }n|dk(  r|}nt        d| d      d|cxk  r|j                  k  st	        d       t	        d      || _        y )Nrelativeabsolutez
bad mode: z'. It should be 'relative' or 'absolute'r   zposition out of bound)r   r=   r   r   
IndexError)r4   valuemoder^   newposs        r6   _scrollzBaseCursor._scrolla  s}    **,:YY&FZFz$/VWXXF(S[[(455 )455	r8   c                6    | j                  d       d| _        y)z3Non-blocking part of closing. Common to sync/async.F)rB   TN)r3   r1   rT   s    r6   _closezBaseCursor._closem  s     	&r8   c                .    | j                   j                  S rV   )r&   r   rT   s    r6   r   zBaseCursor._encodingt  s    ||%%%r8   )r5   r   )T)rB   boolreturnNone)r   str)r   r   )r   zadapt.AdaptersMap)r   r   )r   zlist[Column] | None)r   int)r   
int | None)rh   zSequence[Any]r   r   rV   )rl   r   rm   r  r   r   )r   bool | None)r   z
str | None)r   r$   )
r   r   r   Params | Noner|   r  r}   r  r   PQGen[None])r   r   r   zIterable[Params]r   r   r   r  )r   r   r|   r  r}   r  r   r  )r   r   r|   r  r   ztuple[Prepare, bytes])
r   r   r   r  r}   r  rl   r   r   r  )r   r   r   zPQGen[PGresult | None])r   zQuery | Noner   r  )r   r   r   r  r   r  )r   r   r   r   r}   r  r   r   )r   r   r   r  r   r   )r   zlist[PGresult]r   r   )r   r    r   r   )r_   r   r+   zpq.Format | Noner   r   )rN   bytesr   r   r   r   )rN   r  r   r   r}   r  r   r   )r   r    )r   r    r   r   )r   r   r   r   r   r   )r   r   )-__name__rJ   rK   split	__slots____annotations__r   r'   r7   r3   rR   propertyr5   r.   rE   r`   rb   re   ri   rn   rr   rw   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   rq   r   r   r   r   r   r   r   r   rg   r8   r6   r"   r"   -   s   
 EG  
O&3J#3
	>        *   - - - -" !%A
  $"AA A
 A A 
A$!A!A(8!AEI!A	!AFAA(8AEIA	A>  $"*#*# 	*#
 *# 
*#Z :>6 6+66	6 !%&
 #&& &
 & & 
&,/6-  9=##(5#	#>  %"+1+1 	+1
 +1 
+1\ 59$1	,"04:"R IM -:E	.4
 & &r8   r"   N)=__doc__
__future__r   typingr   r   r   r   r   r	   	functoolsr
    r   r   r   r   abcr   r   r   r   rowsr   r   _columnr   pq.miscr   _queriesr   r   
_preparingr   
generatorsr   r   r   _capabilitiesr   r   pq.abcr   r    Formatr*   r   rL   r   r   rZ   r   r   r   r   r[   r\   r   TransactionStatusACTIVEr"   rg   r8   r6   <module>r     s$   # L L     5 5   ' 8  , , ' (	yy~~			mm'']]%%
MM##	==!!
--

MM##	mm''}}))}}))==11 				$	$I	&,- I	&r8   