
    i$                       d Z ddlmZ ddlmZ ddl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mZ dd
lmZ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  erddl!m"Z" ejF                  jH                  Z$ G d dedef         Z%y)z
Psycopg AsyncCursor object.
    )annotations)TracebackType)TYPE_CHECKINGAnyAsyncIteratorIterableoverload)asynccontextmanager   )errors)pq)ParamsQuery)	AsyncCopyAsyncWriter)AsyncRowFactoryRowRowMaker)Self)
BaseCursor)AsyncPipeline)AsyncConnectionc                      e Zd ZdZdZedd       Ze	 	 	 	 dd       Zdd	 	 	 d  fdZd!dZ	 	 	 	 	 	 	 	 d"d	Zd#d
Ze	d$d       Z
e
j                  d%d       Z
d&dZ	 d'ddd	 	 	 	 	 	 	 	 	 d(dZdd	 	 	 	 	 	 	 d)dZ	 d'ddd	 	 	 	 	 	 	 	 	 d*dZd+dZd,d-dZd.dZd/dZd0d1dZe	 d'dd	 	 	 	 	 	 	 d2d       Zd#dZ xZS )3AsyncCursorpsycopg c                     y Nr   )self
connections     t/var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/venv/lib/python3.12/site-packages/psycopg/cursor_async.py__init__zAsyncCursor.__init__    s    :=    c                    y r   r   )r   r    row_factorys      r!   r"   zAsyncCursor.__init__#   s     r#   N)r%   c               N    t         |   |       |xs |j                  | _        y r   )superr"   r%   _row_factory)r   r    r%   	__class__s      r!   r"   zAsyncCursor.__init__(   s%     	$'A:+A+Ar#   c                   K   | S wr   r   r   s    r!   
__aenter__zAsyncCursor.__aenter__1   s     s   c                @   K   | j                          d {    y 7 wr   )close)r   exc_typeexc_valexc_tbs       r!   	__aexit__zAsyncCursor.__aexit__4   s      jjls   c                ,   K   | j                          yw)zI
        Close the current cursor and free associated resources.
        N)_closer+   s    r!   r.   zAsyncCursor.close<   s      	s   c                    | j                   S )z9Writable attribute to control how result rows are formed.r(   r+   s    r!   r%   zAsyncCursor.row_factoryB   s        r#   c                F    || _         | j                  r ||       | _        y y r   )r(   pgresult	_make_row)r   r%   s     r!   r%   zAsyncCursor.row_factoryG   s"    '==(.DN r#   c                $    | j                  |       S r   r6   r+   s    r!   _make_row_makerzAsyncCursor._make_row_makerM   s      &&r#   preparebinaryc          	     j  K   	 | j                   j                  4 d{    | j                   j                  | j                  ||||             d{    ddd      d{    | S 7 L7 7 
# 1 d{  7  sw Y   | S xY w# t        j
                  $ r}|j                  d      d}~ww xY ww)z=
        Execute a query or command to the database.
        Nr<   )_connlockwait_execute_gene_NO_TRACEBACKwith_traceback)r   queryparamsr=   r>   exs         r!   executezAsyncCursor.executeP   s     	*zz  jjoo%%eVWV%T          	*##D))	*s   B3B A+B 2A1A-A1B $A/%B )B3+B -A1/B 1B7A:8B?B B3B B0B++B00B3F)	returningc          	     ,  K   	 | j                   j                  4 d{    t        j                         r| j                   j                  r5| j                   j                  | j                  |||             d{    n| j                   j                         4 d{    | j                   j                  | j                  |||             d{    ddd      d{    n4| j                   j                  | j                  |||             d{    ddd      d{    y7 7 7 7 a7 S# 1 d{  7  sw Y   .xY w7 57 '# 1 d{  7  sw Y   yxY w# t        j                  $ r}|j                  d      d}~ww xY ww)zI
        Execute the same command with a sequence of input data.
        N)r@   rA   r   is_supported	_pipelinerB   _executemany_gen_pipeline_pipeline_nolock_executemany_gen_no_pipelinerD   rE   rF   )r   rG   
params_seqrK   rI   s        r!   executemanyzAsyncCursor.executemanyd   sh    	*zz   --/ zz++"jjoo ::5*iX  
 $(::#>#>#@  "&**// $ > >$):y!"#     **//99%YW  #  

   #   (  	*##D))	*s   FE( D/E( AE<D2=#E D4!E$0D:D6D:E$D8%4EEEE( )E*E( .F/E( 2E4E6D:8E:E	 EE	EE( E%EE%!E( $F%E( (F;FFFr   r>   sizec          	    :  K   | j                   j                  rt        j                  d      | j                  j
                  4 d{    	 | j                  j                  | j                  ||||             d{    d}| j                  j                  | j                  |             d{   x}rzt        |j                        D ]+  }| j                  j                  || j                         - d}| j                  j                  | j                  |             d{   x}rz| j                   j                   t"        k(  r| j                  j%                          d{    	 | j                  j                  | j                  d             d{   r5	 | j                  j                  | j                  d             d{   r5	 | j                  j                  | j                  d             d{    ddd      d{    y7 7 7 t7 # t        j                  $ r}|j                  d      d}~ww xY w7 7 7 # t&        $ r Y w xY w7 a# t&        $ r Y jw xY w# | j                   j                   t"        k(  r| j                  j%                          d{  7   	 | j                  j                  | j                  d             d{  7  r6	 | j                  j                  | j                  d             d{  7  r6n# t&        $ r Y nw xY w	 | j                  j                  | j                  d             d{  7   w # t&        $ r Y w w xY ww xY w7 h# 1 d{  7  sw Y   yxY ww)a  
        Iterate row-by-row on a result from the database.

        :param size: if greater than 1, results will be retrieved by chunks of
            this size from the server (but still yielded row-by-row); this is only
            available from version 17 of the libpq.
        z(stream() cannot be used in pipeline modeNrT   TF)first)_pgconnpipeline_statusrD   ProgrammingErrorr@   rA   rB   _stream_send_gen_stream_fetchone_genrangentuples_txload_rowr9   rE   rF   transaction_statusACTIVE_try_cancel	Exception)	r   rG   rH   r>   rU   rW   resposrI   s	            r!   streamzAsyncCursor.stream   s4     <<''$$%OPP::?? 	 	jjoo))%T)R   #'::??43L3LU3S#TTTcT$S[[1 E"hh//T^^DDE!E $(::??43L3LU3S#TTTcT <<22f< **00222$(JJOO 55E5B%   ! %)JJOO 55E5B%  "jjood.G.Ge.G.TUUU9	 	 	 UT ?? .''--. 3  %  V$ ! <<22f< **00222$(JJOO 55E5B%   ! %)JJOO 55E5B%   % 
"jjood.G.Ge.G.TUUU$ ! =	 	 	 	s  ANH!	NN1H,?H$ 3H,3H'4A8H,,H*-H,4:N.I/N4.I"I#3III.I/I-I/NNN$H,'H,*H,,I?III>NII	I*'N)I**N-I//	I;8N:I;;N>;N 9J<
:N  .L+.K1
/4L+#L&
$L+*N +	L7	4N 6L7	7N ;.M0)M,
*M0/N 0	M<	9N ;M<	<N  NNNNNNc                   K   | j                          d{    | j                         }| j                  |j                  k  rG| j                  j                  | j                  | j                        }| xj                  dz  c_        |S y7 uw)z
        Return the next record from the current recordset.

        Return `!None` the recordset is finished.

        :rtype: Row | None, with Row defined by `row_factory`
        Nr   _fetch_pipeline_check_result_for_fetch_posr^   r_   r`   r9   )r   re   records      r!   fetchonezAsyncCursor.fetchone   sp      ""$$$**,99s{{"XX&&tyy$..AFIINIM 	%s   BBA6Bc                ^  K   | j                          d{    | j                         }|s| j                  }| j                  j	                  | j
                  t        | j
                  |z   |j                        | j                        }| xj
                  t        |      z  c_        |S 7 w)z
        Return the next `!size` records from the current recordset.

        `!size` default to `!self.arraysize` if not specified.

        :rtype: Sequence[Row], with Row defined by `row_factory`
        N)
rj   rk   	arraysizer_   	load_rowsrl   minr^   r9   len)r   rU   re   recordss       r!   	fetchmanyzAsyncCursor.fetchmany   s      ""$$$**,>>D(($$IIs499t+S[[94>>
 			S\!	 	%s   B-B+BB-c                   K   | j                          d{    | j                         }| j                  j                  | j                  |j
                  | j                        }|j
                  | _        |S 7 bw)z
        Return all the remaining records from the current recordset.

        :rtype: Sequence[Row], with Row defined by `row_factory`
        N)rj   rk   r_   rq   rl   r^   r9   )r   re   rt   s      r!   fetchallzAsyncCursor.fetchall   sa      ""$$$**,(($$TYYT^^LKK		 	%s   A;A9A#A;c               \  K   | j                          d {    | j                         }| j                  |j                  k  re| j                  j                  | j                  | j                        }| xj                  dz  c_        | | j                  |j                  k  rdy y 7 w)Nr   ri   )r   re   rows      r!   	__aiter__zAsyncCursor.__aiter__   s}     ""$$$**,ii#++%((##DIIt~~>CIINII ii#++% 	%s   B,B*BB,(B,c                d   K   | j                          d{    | j                  ||       y7 w)a  
        Move the cursor in the result set to a new position according to mode.

        If `!mode` is ``'relative'`` (default), `!value` is taken as offset to
        the current position in the result set; if set to ``'absolute'``,
        `!value` states an absolute target position.

        Raise `!IndexError` in case a scroll operation would leave the result
        set. In this case the position will not change.
        N)rj   _scroll)r   valuemodes      r!   scrollzAsyncCursor.scroll   s-      ""$$$UD! 	%s   0.0writerc              
  K   	 | j                   j                  4 d{    | j                   j                  | j                  ||             d{    ddd      d{    t	        | |      4 d{   }| ddd      d{    | j                  d       y7 7 S7 E# 1 d{  7  sw Y   UxY w7 F7 3# 1 d{  7  sw Y   CxY w# t
        j                  $ r}|j                  d      d}~ww xY ww)zU
        Initiate a :sql:`COPY` operation and return an object to manage it.
        Nr   r   )	r@   rA   rB   _start_copy_genr   rD   rE   rF   _select_current_result)r   	statementrH   r   copyrI   s         r!   r   zAsyncCursor.copy   s     	*zz O Ojjood&:&:9f&MNNNO O !f5  
  	##A&ONO O O O     	*##D))	*s   DC B#C /B)B%B)C !B'"C 7B>8C ;CC C C D#C %B)'C )B;/B20B;7C  C CC	CC D *C;;D  Dc                  K   | j                   dur| j                  s| j                  j                  rw| j                  j                  4 d {    | j                  j                  | j                  j                  j                  d             d {    d d d       d {    y y y y 7 _7 7 # 1 d {  7  sw Y   y xY ww)NFT)flush)_execmany_returningr8   r@   rN   rA   rB   
_fetch_genr+   s    r!   rj   zAsyncCursor._fetch_pipeline  s     $$E1MM

$$zz S Sjjoodjj&:&:&E&ED&E&QRRRS S S % " 2SRS S S Ss[   ACB-CAB3B/B3C$B1%	C/B31C3C9B<:CC)r    zAsyncConnection[Row])r    AsyncConnection[Any]r%   AsyncRowFactory[Row])r    r   r%   zAsyncRowFactory[Row] | None)returnr   )r/   ztype[BaseException] | Noner0   zBaseException | Noner1   zTracebackType | Noner   None)r   r   )r   r   )r%   r   r   r   )r   zRowMaker[Row]r   )
rG   r   rH   Params | Noner=   bool | Noner>   r   r   r   )rG   r   rR   zIterable[Params]rK   boolr   r   )
rG   r   rH   r   r>   r   rU   intr   AsyncIterator[Row])r   z
Row | None)r   )rU   r   r   	list[Row])r   r   )r   r   )relative)r}   r   r~   strr   r   )r   r   rH   r   r   zAsyncWriter | Noner   zAsyncIterator[AsyncCopy])__name__
__module____qualname__	__slots__r	   r"   r,   r2   r.   propertyr%   setterr;   rJ   rS   rg   rn   ru   rw   rz   r   r
   r   rj   __classcell__)r)   s   @r!   r   r      s   JI= =.@T  48	B(B 1	B, & %	
 
 ! ! / /
' !%
  $" 
   
* PU**(8*HL*	*B !%0
 #00 0
 0 0 
0d &
"  !%'
 &*'' '
 #' 
"' '.Sr#   r   r   N)&__doc__
__future__r   typesr   typingr   r   r   r   r	   
contextlibr
    r   rD   r   abcr   r   r   r   r   rowsr   r   r   _compatr   _cursor_baser   _pipeline_asyncr   connection_asyncr   TransactionStatusrb   r   r   r#   r!   <module>r      sh    #  H H *    ( 0 0  $ *1				$	$}S*3S89 }Sr#   