
    g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j#        j$        Z$ G d dedef                   Z%dS )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                  D    e Zd ZdZdZedGd            ZedHd	            Zd
ddI fdZdJdZdKdZdLdZe	dMd            Z
e
j        dNd            Z
dOdZ	 dPd
d
ddQd&Zd'd(dRd-Z	 dPd
d.d/dSd3ZdTd5ZdUdVd8ZdWd9ZdXd:ZdYdZd?Ze	 dPd
d@d[dE            ZdLdFZ xZS )\AsyncCursorpsycopg 
connectionAsyncConnection[Row]c                    d S Nr   )selfr   s     d/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/psycopg/cursor_async.py__init__zAsyncCursor.__init__    s    :=#    AsyncConnection[Any]row_factoryAsyncRowFactory[Row]c                   d S r    r   )r!   r   r&   s      r"   r#   zAsyncCursor.__init__#   s	     sr$   N)r&   AsyncRowFactory[Row] | Nonec               f    t                                          |           |p|j        | _        d S r    )superr#   r&   _row_factory)r!   r   r&   	__class__s      r"   r#   zAsyncCursor.__init__(   s3     	$$$'A:+Ar$   returnr   c                
   K   | S r    r   r!   s    r"   
__aenter__zAsyncCursor.__aenter__1   s      r$   exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | NoneNonec                >   K   |                                   d {V  d S r    )close)r!   r2   r4   r6   s       r"   	__aexit__zAsyncCursor.__aexit__4   s.       jjllr$   c                2   K   |                                   dS )zI
        Close the current cursor and free associated resources.
        N)_closer0   s    r"   r:   zAsyncCursor.close<   s       	r$   c                    | j         S )z9Writable attribute to control how result rows are formed.r,   r0   s    r"   r&   zAsyncCursor.row_factoryB   s       r$   c                F    || _         | j        r ||           | _        d S d S r    )r,   pgresult	_make_row)r!   r&   s     r"   r&   zAsyncCursor.row_factoryG   s3    '= 	/([..DNNN	/ 	/r$   RowMaker[Row]c                ,    |                      |           S r    r?   r0   s    r"   _make_row_makerzAsyncCursor._make_row_makerM   s      &&&r$   preparebinaryqueryr   paramsParams | NonerG   bool | NonerH   c          	     @  K   	 | j         j        4 d{V  | j                             |                     ||||                     d{V  ddd          d{V  n# 1 d{V swxY w Y   n,# t          j        $ r}|                    d          d}~ww xY w| S )z=
        Execute a query or command to the database.
        NrF   )_connlockwait_execute_gene_NO_TRACEBACKwith_traceback)r!   rI   rJ   rG   rH   exs         r"   executezAsyncCursor.executeP   sQ     	*z        joo%%eVWV%TT                                    	* 	* 	*##D)))	*s:   A2 8A A2  
A**A2 -A*.A2 2BBBF)	returning
params_seqIterable[Params]rW   boolc          	       K   	 | j         j        4 d{V  t          j                    r| j         j        r6| j                             |                     |||                     d{V  n| j                                         4 d{V  | j                             |                     |||                     d{V  ddd          d{V  n# 1 d{V swxY w Y   n5| j                             |                     |||                     d{V  ddd          d{V  dS # 1 d{V swxY w Y   dS # t          j
        $ r}|                    d          d}~ww xY w)zI
        Execute the same command with a sequence of input data.
        N)rN   rO   r   is_supported	_pipelinerP   _executemany_gen_pipeline_pipeline_nolock_executemany_gen_no_pipelinerR   rS   rT   )r!   rI   rX   rW   rU   s        r"   executemanyzAsyncCursor.executemanyd   s     	*z         -//  z+ "joo ::5*iXX         
 $(:#>#>#@#@        "&*// $ > >$):y!" !"# #                                  *//99%YWW        #                             (  	* 	* 	*##D)))	*s_   E  A5D-6CD-
C	D- C	!9D-E  -
D77E  :D7;E   E)E$$E)r   rH   sizerc   intAsyncIterator[Row]c          	      K   | j         j        rt          j        d          | j        j        4 d{V  	 | j                            |                     ||||                     d{V  d}| j                            |                     |                     d{V x}rqt          |j
                  D ]%}| j                            || j                  W V  &d}| j                            |                     |                     d{V x}qn,# t          j        $ r}|                    d          d}~ww xY w| j         j        t"          k    r| j                                         d{V  	 | j                            |                     d                     d{V r5	 | j                            |                     d                     d{V 5n# t&          $ r Y nw xY w	 | j                            |                     d                     d{V  n# t&          $ r Y nw xY wn# | j         j        t"          k    r| j                                         d{V  	 | j                            |                     d                     d{V r5	 | j                            |                     d                     d{V 5n# t&          $ r Y nw xY w	 | j                            |                     d                     d{V  w # t&          $ r Y w w xY ww xY wddd          d{V  dS # 1 d{V swxY w Y   dS )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 modeNrb   TF)first)_pgconnpipeline_statusrR   ProgrammingErrorrN   rO   rP   _stream_send_gen_stream_fetchone_genrangentuples_txload_rowrB   rS   rT   transaction_statusACTIVE_try_cancel	Exception)	r!   rI   rJ   rH   rc   rg   resposrU   s	            r"   streamzAsyncCursor.stream   s      <' 	Q$%OPPP:? 	 	 	 	 	 	 	 	joo))%T)RR         #':??43L3LU3S3S#T#TTTTTTTTc "$S[11 E E"h//T^DDDDDDD!E $(:??43L3LU3S3S#T#TTTTTTTTc " ? . . .''---. <2f<< *00222222222$(JOO 55E5BB% %       ! ! %)JOO 55E5BB% %       ! %   
"jood.G.Ge.G.T.TUUUUUUUUUU$   ! =4<2f<< *00222222222$(JOO 55E5BB% %       ! ! %)JOO 55E5BB% %       ! %   
"jood.G.Ge.G.T.TUUUUUUUUUU$   ! =	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   MCDH:E &D;;E  H:4M8A)G"!M"
G/,M.G//M34H)'M)
H63M5H66M:5L10A)KL1
K'	$L1&K'	'L1+4L L1 
L-	*L1,L-	-L11M
MM
Row | Nonec                   K   |                                   d{V  |                                 }| j        |j        k     r7| j                            | j        | j                  }| xj        dz  c_        |S dS )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_posrn   ro   rp   rB   )r!   ru   records      r"   fetchonezAsyncCursor.fetchone   s       ""$$$$$$$$$**,,9s{""X&&ty$.AAFIINIIMtr$   r   	list[Row]c                4  K   |                                   d{V  |                                 }|s| j        }| j                            | j        t          | j        |z   |j                  | j                  }| xj        t          |          z  c_        |S )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)
r{   r|   	arraysizero   	load_rowsr}   minrn   rB   len)r!   rc   ru   recordss       r"   	fetchmanyzAsyncCursor.fetchmany   s       ""$$$$$$$$$**,, 	">D($$Is49t+S[994>
 
 			S\\!		r$   c                   K   |                                   d{V  |                                 }| j                            | j        |j        | j                  }|j        | _        |S )z
        Return all the remaining records from the current recordset.

        :rtype: Sequence[Row], with Row defined by `row_factory`
        N)r{   r|   ro   r   r}   rn   rB   )r!   ru   r   s      r"   fetchallzAsyncCursor.fetchall   sj       ""$$$$$$$$$**,,($$TYT^LLK	r$   c                 K   |                                   d {V  |                                 }| j        |j        k     rL| j                            | j        | j                  }| xj        dz  c_        |W V  | j        |j        k     Jd S d S )Nr   rz   )r!   ru   rows      r"   	__aiter__zAsyncCursor.__aiter__   s      ""$$$$$$$$$**,,i#+%%(##DIt~>>CIINIIIIII i#+%%%%%%r$   relativevaluemodestrc                j   K   |                                   d{V  |                     ||           dS )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)r{   _scroll)r!   r   r   s      r"   scrollzAsyncCursor.scroll   sF       ""$$$$$$$$$UD!!!!!r$   writer	statementr   AsyncWriter | NoneAsyncIterator[AsyncCopy]c                K   	 | j         j        4 d{V  | j                             |                     ||                     d{V  ddd          d{V  n# 1 d{V swxY w Y   t	          | |          4 d{V }|W V  ddd          d{V  n# 1 d{V swxY w Y   n,# t
          j        $ r}|                    d          d}~ww xY w|                     d           dS )zU
        Initiate a :sql:`COPY` operation and return an object to manage it.
        Nr   r   )	rN   rO   rP   _start_copy_genr   rR   rS   rT   _select_current_result)r!   r   rJ   r   copyrU   s         r"   r   zAsyncCursor.copy   s;     	*z O O O O O O O Ojood&:&:9f&M&MNNNNNNNNNO O O O O O O O O O O O O O O O O O O O O O O O O O O !f555       



                           	* 	* 	*##D)))	*
 	##A&&&&&s^   B/ 5AB/ 
A''B/ *A'+B/ BB/ 
B''B/ *B'+B/ /C>CCc                8  K   | j         dur| j        s| j        j        r{| j        j        4 d {V  | j                            | j        j                            d                     d {V  d d d           d {V  d S # 1 d {V swxY w Y   d S d S d S d S )NFT)flush)_execmany_returningrA   rN   r]   rO   rP   
_fetch_genr0   s    r"   r{   zAsyncCursor._fetch_pipeline  sk     $E11M 2
$ 2 z S S S S S S S Sjoodj&:&E&ED&E&Q&QRRRRRRRRRS S S S S S S S S S S S S S S S S S S S S S S S S S S S S S	 211111s   ?B
BB)r   r   )r   r%   r&   r'   )r   r%   r&   r)   )r.   r   )r2   r3   r4   r5   r6   r7   r.   r8   )r.   r8   )r.   r'   )r&   r'   r.   r8   )r.   rC   r    )
rI   r   rJ   rK   rG   rL   rH   rL   r.   r   )rI   r   rX   rY   rW   rZ   r.   r8   )
rI   r   rJ   rK   rH   rL   rc   rd   r.   re   )r.   rx   )r   )rc   rd   r.   r   )r.   r   )r.   re   )r   )r   rd   r   r   r.   r8   )r   r   rJ   rK   r   r   r.   r   )__name__
__module____qualname__	__slots__r	   r#   r1   r;   r:   propertyr&   setterrE   rV   ra   rw   r   r   r   r   r   r
   r   r{   __classcell__)r-   s   @r"   r   r      sq       JI=== X=   X 48	B B B B B B B B          ! ! ! X! / / / /
' ' ' ' !%
  $"     * PU* * * * * *B !%0
 #0 0 0 0 0 0d        &
 
 
 
   " " " " "  !%'
 &*' ' ' ' ' '.S S S S S S S Sr$   r   r%   N)&__doc__
__future__r   typesr   typingr   r   r   r   r	   
contextlibr
    r   rR   r   abcr   r   r   r   r   rowsr   r   r   _compatr   _cursor_baser   _pipeline_asyncr   connection_asyncr   TransactionStatusrr   r   r   r$   r"   <module>r      s    # " " " " "       H H H H H H H H H H H H H H * * * * * *                     ( ( ( ( ( ( ( ( 0 0 0 0 0 0 0 0 0 0       $ $ $ $ $ $ * * * * * * 2111111			$}S }S }S }S }S*3S89 }S }S }S }S }Sr$   