
    j,                       d Z ddlmZ ddlmZ ddlmZmZmZ ddl	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mZ ddlmZmZ ddlmZmZmZ ddlmZ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overload)asynccontextmanager)AsyncIteratorIterable   )errors)pq)ParamsQueryQueryNoTemplate)	AsyncCopyAsyncWriter)AsyncRowFactoryRowRowMaker)SelfTemplate)
BaseCursor)AsyncPipeline)AsyncConnectionc                      e Zd ZdZdZedQd            ZedRd	            Zd
ddS fdZdTdZdUdZdVdZe	dWd            Z
e
j        dXd            Z
dYdZe	 dZd
d
dd[d&            Zed
d
dd\d(            Z	 dZd
d
dd]d*Zd+d,d^d1Z	 dZd
d2d3d_d7Zd`d9Zdad;Zdbd=Zdcddd@ZdedAZdTdBZdfdDZdgdhdIZe	 dZd
dJdidO            ZdVdPZ xZS )jAsyncCursorpsycopg 
connectionAsyncConnection[Row]c                    d S Nr   )selfr   s     ^/workspace/show-city-briefing-agent/.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__2   s      r&   exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | NoneNonec                >   K   |                                   d {V  d S r"   )close)r#   r4   r6   r8   s       r$   	__aexit__zAsyncCursor.__aexit__5   s.       jjllr&   c                2   K   |                                   dS )zI
        Close the current cursor and free associated resources.
        N)_closer2   s    r$   r<   zAsyncCursor.close=   s       	r&   c                    | j         S )z9Writable attribute to control how result rows are formed.r.   r2   s    r$   r(   zAsyncCursor.row_factoryC   s       r&   c                F    || _         | j        r ||           | _        d S d S r"   )r.   pgresult	_make_row)r#   r(   s     r$   r(   zAsyncCursor.row_factoryH   s3    '= 	/([..DNNN	/ 	/r&   RowMaker[Row]c                ,    |                      |           S r"   rA   r2   s    r$   _make_row_makerzAsyncCursor._make_row_makerN   s      &&&r&   preparebinaryqueryr   paramsParams | NonerI   bool | NonerJ   c               
   K   d S r"   r   )r#   rK   rL   rI   rJ   s        r$   executezAsyncCursor.executeQ   s       sr&   r   c               
   K   d S r"   r   )r#   rK   rI   rJ   s       r$   rP   zAsyncCursor.execute[   s       sr&   r   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.
        NrH   )_connlockwait_execute_gene_NO_TRACEBACKwith_traceback)r#   rK   rL   rI   rJ   exs         r$   rP   zAsyncCursor.executed   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]r[   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)rS   rT   r   is_supported	_pipelinerU   _executemany_gen_pipeline_pipeline_nolock_executemany_gen_no_pipelinerW   rX   rY   )r#   rK   r\   r[   rZ   s        r$   executemanyzAsyncCursor.executemanyx   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   rJ   sizerg   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 modeNrf   TF)first)_pgconnpipeline_statusrW   ProgrammingErrorrS   rT   rU   _stream_send_gen_stream_fetchone_genrangentuples_txload_rowrD   rX   rY   transaction_statusACTIVE_try_cancel	Exception)	r#   rK   rL   rJ   rg   rk   resposrZ   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AsyncIterator[Self]c               R   K   | j         r	 | W V  |                                 sdS dS )z
        Iterate across multiple record sets received by the cursor.

        Multiple record sets are received after using `executemany()` with
        `!returning=True` or using `execute()` with more than one query in the
        command.
        TN)rC   nextsetr2   s    r$   resultszAsyncCursor.results   sF       = 	



||~~ E		 	r&   indexc                &  K   t          | j                   |cxk    rt          | j                  k     s*n t          d| dt          | j                   d          |dk     rt          | j                  |z   }|                     |           | S )a  
        Move to a specific result set.

        :arg index: index of the result to go to
        :type index: `!int`

        More than one result will be available after executing calling
        `executemany()` or `execute()` with more than one query.

        `!index` is 0-based and supports negative values, counting from the end,
        the same way you can index items in a list.

        The function returns self, so that the result may be followed by a
        fetch operation. See `results()` for details.
        zindex z out of range: z result(s) availabler   )len_results
IndexError_select_current_result)r#   r   s     r$   
set_resultzAsyncCursor.set_result   s        DM"""e@@@@c$-.@.@@@@@WWWs4=/A/AWWW   199&&.E##E***r&   
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 result set.

        Return `!None` the result set is finished.

        :rtype: Row | None, with Row defined by `row_factory`
        Nr   )_fetch_pipeline_check_result_for_fetch_posrr   rs   rt   rD   r#   ry   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 result set.

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

        :rtype: Sequence[Row], with Row defined by `row_factory`
        N)
r   r   	arraysizers   	load_rowsr   minrr   rD   r   )r#   rg   ry   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 result set.

        :rtype: Sequence[Row], with Row defined by `row_factory`
        N)r   r   rs   r   r   rr   rD   )r#   ry   r   s      r$   fetchallzAsyncCursor.fetchall  sj       ""$$$$$$$$$**,,($$TYT^LLK	r&   c                    | S r"   r   r2   s    r$   	__aiter__zAsyncCursor.__aiter__   s    r&   r   c                  K   |                                   d {V  |                                 }| j        |j        k     r7| j                            | j        | j                  }| xj        dz  c_        |S t          d          )Nr   zno more records to return)r   r   r   rr   rs   rt   rD   StopAsyncIterationr   s      r$   	__anext__zAsyncCursor.__anext__#  s      ""$$$$$$$$$**,,9s{""X&&ty$.AAFIINIIM !<===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  t	          | |          4 d{V }|W V  ddd          d{V  n# 1 d{V swxY w Y   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   )	rS   rT   rU   _start_copy_genr   rW   rX   rY   r   )r#   r   rL   r   copyrZ   s         r$   r   zAsyncCursor.copy:  s     	*z        jood&:&:9f&M&MNNNNNNNNN$T&999       TJJJJ                                                    
  	* 	* 	*##D)))	*
 	##A&&&&&s_   B/ AB"A:(B:
B	B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_returningrC   rS   ra   rT   rU   
_fetch_genr2   s    r$   r   zAsyncCursor._fetch_pipelineR  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+   )r0   r   )r4   r5   r6   r7   r8   r9   r0   r:   )r0   r:   )r0   r)   )r(   r)   r0   r:   )r0   rE   r"   )
rK   r   rL   rM   rI   rN   rJ   rN   r0   r   )rK   r   rI   rN   rJ   rN   r0   r   )
rK   r   rL   rM   rI   rN   rJ   rN   r0   r   )rK   r   r\   r]   r[   r^   r0   r:   )
rK   r   rL   rM   rJ   rN   rg   rh   r0   ri   )r0   r|   )r   rh   r0   r   )r0   r   )r   )rg   rh   r0   r   )r0   r   )r0   r   )r   )r   rh   r   r   r0   r:   )r   r   rL   rM   r   r   r0   r   )__name__
__module____qualname__	__slots__r   r%   r3   r=   r<   propertyr(   setterrG   rP   re   r{   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r/   s   @r$   r   r      s       JI=== X=   X 48	B B B B B B B B          ! ! ! X! / / / /
' ' ' '  !%
  $"     X 
  $"     X !%
  $"     * PU* * * * * *B !%0
 #0 0 0 0 0 0d      4        &
 
 
 
   > > > >" " " " "  !%'
 &*' ' ' ' ' '.S S S S S S S Sr&   r   r'   N))__doc__
__future__r   typesr   typingr   r   r   
contextlibr   collections.abcr	   r
    r   rW   r   abcr   r   r   r   r   r   rowsr   r   r   _compatr   r   _cursor_baser   _pipeline_asyncr   connection_asyncr   TransactionStatusrv   r   r   r&   r$   <module>r      s    # " " " " "       / / / / / / / / / / * * * * * * 3 3 3 3 3 3 3 3             / / / / / / / / / / ( ( ( ( ( ( ( ( 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&   