
    j6                        d 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 ddl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 erddlmZ  G d dedef         ee                   ZdS )z$
psycopg server-side cursor (sync).
    )annotations)TYPE_CHECKINGAnyoverload)Iterable   )errors)ParamsQuery)Row
RowFactory)Cursor)Self)ServerCursorMixin)
Connectionc                       e Zd ZdZdZedddd8d            Zedddd9d            Zddddd:dZd; fdZ	 d<ddd=d"Zd#d$d>d(Zd?d*Z	d@dAd/Z
dBd0ZdCd1ZdDd3ZdEdFd7Z xZS )GServerCursorpsycopg NF)
scrollablewithhold
connectionConnection[Row]namestrr   bool | Noner   boolc                   d S Nr   )selfr   r   r   r   s        `/workspace/show-city-briefing-agent/.venv/lib/python3.11/site-packages/psycopg/_server_cursor.py__init__zServerCursor.__init__   s	     s    Connection[Any]row_factoryRowFactory[Row]c                   d S r   r   r    r   r   r%   r   r   s         r!   r"   zServerCursor.__init__(   s	     sr#   )r%   r   r   RowFactory[Row] | Nonec               p    t          j        | ||p|j                   t          j        | |||           d S )N)r%   )r   r"   r%   r   r(   s         r!   r"   zServerCursor.__init__3   sK     	*+*O9O	
 	
 	
 	
 	"4z8DDDDDr#   returnNonec                ,   | j         j        5  | j        r	 ddd           dS | j         j        s,| j                             |                                            t                                                       ddd           dS # 1 swxY w Y   dS )zI
        Close the current cursor and free associated resources.
        N)_connlockclosedwait
_close_gensuperclose)r    	__class__s    r!   r4   zServerCursor.closeA   s     Z_ 	 	{ 	 	 	 	 	 	 	 	 :$ 3
 1 1222GGMMOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   	B	AB		BB)binaryqueryr   paramsParams | Noner6   kwargsr   r   c                  |r%t          dt          |          d                    | j        j        rt	          j        d          	 | j        j        5  | j                            | 	                    |||                     ddd           n# 1 swxY w Y   n,# t          j
        $ r}|                    d          d}~ww xY w| S )zC
        Open a cursor to execute a query to the database.
        zkeyword not supported: r   z2server-side cursors not supported in pipeline modeN)	TypeErrorlist_pgconnpipeline_statuseNotSupportedErrorr.   r/   r1   _declare_gen_NO_TRACEBACKwith_traceback)r    r7   r8   r6   r:   exs         r!   executezServerCursor.executeL   s+     	IGd6ll1oGGHHH<' 	%D  	* J J
 1 1% H HIIIJ J J J J J J J J J J J J J J 	* 	* 	*##D)))	* s<   	B 0BB BB BB C,CCT)	returning
params_seqIterable[Params]rG   c               *    t          j        d          )z/Method not implemented for server-side cursors.z0executemany not supported on server-side cursors)r@   rA   )r    r7   rH   rG   s       r!   executemanyzServerCursor.executemanyf   s     !"TUUUr#   
Row | Nonec                    | j         j        5  | j                             |                     d                    }d d d            n# 1 swxY w Y   |r| xj        dz  c_        |d         S d S )Nr   r   )r.   r/   r1   
_fetch_gen_posr    recss     r!   fetchonezServerCursor.fetchonel   s    Z_ 	7 	7:??4??1#5#566D	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	IINII7N4   .AAAr   sizeint	list[Row]c                    |s| j         }| j        j        5  | j                            |                     |                    }d d d            n# 1 swxY w Y   | xj        t          |          z  c_        |S r   )	arraysizer.   r/   r1   rN   rO   len)r    rT   rQ   s      r!   	fetchmanyzServerCursor.fetchmanyu   s     	">DZ_ 	: 	::??4??4#8#899D	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:		SYY		s   .AAAc                    | j         j        5  | j                             |                     d                     }d d d            n# 1 swxY w Y   | xj        t          |          z  c_        |S r   )r.   r/   r1   rN   rO   rY   rP   s     r!   fetchallzServerCursor.fetchall}   s    Z_ 	: 	::??4??4#8#899D	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:		SYY		rS   c                    | S r   r   )r    s    r!   __iter__zServerCursor.__iter__   s    r#   r   c                   | j         ,| j        t          | j                   cxk    r| j        k    ren nb| j        j        5  | j                            |                     | j                            | _         d| _        d d d            n# 1 swxY w Y   | j        t          | j                   k    rt          d          | j         | j                 }| xj        dz  c_        | xj	        dz  c_	        |S )Nr   zno more records to returnr   )

_iter_rows	_page_posrY   itersizer.   r/   r1   rN   StopIterationrO   )r    recs     r!   __next__zServerCursor.__next__   s    O#~T_!5!5FFFFFFFFF # #"&*//$//$-2P2P"Q"Q!"# # # # # # # # # # # # # # # >S1111 ;<<<odn-!		Q		
s    ?BBBrelativevaluemodec                    | j         j        5  | j                             |                     ||                     d d d            n# 1 swxY w Y   |dk    r| xj        |z  c_        d S || _        d S )Nrf   )r.   r/   r1   _scroll_genrO   )r    rg   rh   s      r!   scrollzServerCursor.scroll   s    Z_ 	; 	;JOOD,,UD99:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; :IIIIIIDIIIs   /AAA)r   r   r   r   r   r   r   r   )
r   r$   r   r   r%   r&   r   r   r   r   )
r   r$   r   r   r%   r)   r   r   r   r   )r+   r,   r   )
r7   r   r8   r9   r6   r   r:   r   r+   r   )r7   r   rH   rI   rG   r   r+   r,   )r+   rL   )r   )rT   rU   r+   rV   )r+   rV   )r+   r   )r+   r   )rf   )rg   rU   rh   r   r+   r,   )__name__
__module____qualname__	__slots__r   r"   r4   rF   rK   rR   rZ   r\   r^   re   rk   __classcell__)r5   s   @r!   r   r      s       JI #'     X  #'     X /3"&E E E E E E	 	 	 	 	 	 !%
 #     6 PTV V V V V V                &        r#   r   r$   N)__doc__
__future__r   typingr   r   r   collections.abcr    r	   r@   abcr
   r   rowsr   r   cursorr   _compatr   _server_cursor_baser   r   r   r   r   r#   r!   <module>r{      s5    # " " " " " / / / / / / / / / / $ $ $ $ $ $               ! ! ! ! ! ! ! !             2 2 2 2 2 2 '&&&&&&F F F F F$%6%;<fSk F F F F Fr#   