
    *Jf9                        d Z ddlmZmZmZ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 ddlmZ dd	lmZmZ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  ddl!m"Z" erddl#m$Z$ ddl%m&Z& dZ'ej(        j)        Z)ej(        j*        Z*ej+        j,        Z,ej+        j-        Z-ej.        j/        Z/ej.        j0        Z0 G d deeef                   Z1 G d de1def         ee                   Z2 G d de1def         e"e                   Z3dS )z%
psycopg server-side cursor objects.
    )AnyAsyncIteratorListIterableIterator)OptionalTYPE_CHECKINGoverload)warn   )pq)sql)errors)ConnectionTypeQueryParamsPQGen)Row
RowFactoryAsyncRowFactory)
BaseCursorCursor)Self)execute)AsyncCursor)
Connection)AsyncConnectiond   c            
           e Zd ZdZd                                Zdedee         defdZ	def fdZ
edefd	            Zedee         fd
            Zedefd            Zedee         fd            Z	 	 ddedee         dee         ded         fdZded         fdZded         fdZdee         deee                  fdZdededed         fdZdedej        fdZ xZS )ServerCursorMixinzDMixin to add ServerCursor behaviour and implementation a BaseCursor.z7_name _scrollable _withhold _described itersize _formatname
scrollablewithholdc                 n    || _         || _        || _        d| _        t          | _        t          | _        d S )NF)_name_scrollable	_withhold
_describedDEFAULT_ITERSIZEitersizeTEXT_format)selfr!   r"   r#   s       X/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/psycopg/server_cursor.py__init__zServerCursorMixin.__init__*   s3     
%!-    returnc                     t                                                                          d d          }|                    d| j                   d                    |          S )Nr    )super__repr__splitinsertr%   join)r-   parts	__class__s     r.   r5   zServerCursorMixin.__repr__7   sQ      ""((q11Q4:)***xxr0   c                     | j         S )zThe name of the cursor.)r%   r-   s    r.   r!   zServerCursorMixin.name=   s     zr0   c                     | j         S )z
        Whether the cursor is scrollable or not.

        If `!None` leave the choice to the server. Use `!True` if you want to
        use `scroll()` on the cursor.
        )r&   r<   s    r.   r"   zServerCursorMixin.scrollableB   s     r0   c                     | j         S )zY
        If the cursor can be used after the creating transaction has committed.
        )r'   r<   s    r.   r#   zServerCursorMixin.withholdL   s    
 ~r0   c                 `    | j         }|o|j        t          k    p
|j        dk    }|r| j        ndS )zoIndex of the next row to fetch in the current result.

        `!None` if there is no result to fetch.
        r0   N)pgresultstatus	TUPLES_OKcommand_status_pos)r-   restupless      r.   	rownumberzServerCursorMixin.rownumberS   s<     m O#*	1NS5G35N",tyy,r0   Nqueryparamsbinaryc              #   0  K   |                      |          }| j        r!|                                 E d{V  d| _        |                     |          E d{V  |                     ||          }|                     |d           t          | j        j                  E d{V }|d         j	        t          k    r|                     |d                    || j        | _        n|rt          nt          | _        |                                 E d{V  dS )z0Generator implementing `ServerCursor.execute()`.NFT)force_extended)_make_declare_statementr(   
_close_gen_start_query_convert_query_execute_sendr   _connpgconnrA   
COMMAND_OK_raise_for_resultformatr,   BINARYr+   _describe_gen)r-   rH   rI   rJ   pgqresultss         r.   _declare_genzServerCursorMixin._declare_gen`   s@      ,,U33 ? 	$(((((((((#DO$$U+++++++++!!%003t444$TZ%6777777772;++""72;/// >;DLL%+566DL %%'''''''''''r0   c              #   *  K   | j                             | j                            | j                             t          | j                   E d {V }|                     |           || _        |                     d| j	                   d| _
        d S )Nr   )rW   T)_pgconnsend_describe_portalr%   encode	_encodingr   _check_results_results_select_current_resultr,   r(   )r-   r[   s     r.   rY   zServerCursorMixin._describe_gen   s      ))$**;*;DN*K*KLLL$T\22222222G$$$##Adl#;;;r0   c              #   ,  K   | j         j        j        }|t          k    r|t          k    rd S | j        s|t          k    rd S | j        sot          j        d          	                    t          j
        | j                            }| j                             |          E d {V }|J |j        dk    rd S t          j        d          	                    t          j        | j                            }| j                             |          E d {V  d S )Nz3SELECT 1 FROM pg_catalog.pg_cursors WHERE name = {}r   zCLOSE {})rS   rT   transaction_statusIDLEINTRANSr'   r(   r   SQLrW   Literalr%   _exec_commandntuples
Identifier)r-   tsrH   rE   s       r.   rO   zServerCursorMixin._close_gen   s     Z1 ::"--F ~ 	"**F  	GE fS[,,--  "Z55e<<<<<<<<C???{a
##**3>$*+E+EFF:++E22222222222r0   numc              #   h  K   | j         rt          j        d          | j        s4|                                 E d {V  |                                 E d {V  t          j        d                              |t          j        d          nt          j	        |          t          j
        | j                            }| j                            || j                  E d {V }|J || _        | j                            |d           | j                            d|j        | j                  S )Nzthe cursor is closedzFETCH FORWARD {} FROM {}ALL)result_formatF)set_loadersr   )closedeInterfaceErrorr(   rP   rY   r   ri   rW   rj   rm   r%   rS   rk   r,   r@   _txset_pgresult	load_rowsrl   	_make_row)r-   ro   rH   rE   s       r.   
_fetch_genzServerCursorMixin._fetch_gen   s9     ; 	;"#9::: 	,((*********))+++++++++233::!kCGENNNs{3/?/?N4:&&
 
 11%t|1TTTTTTTTcu555x!!!S[$.AAAr0   valuemodec              #   P  K   |dvrt          d| d          t          j        d                              t          j        |dk    rdnd          t          j        |          t          j        | j                            }| j                            |          E d {V  d S )N)relativeabsolutez
bad mode: z'. It should be 'relative' or 'absolute'zMOVE{} {} FROM {}r   z	 ABSOLUTE )	
ValueErrorr   ri   rW   rj   rm   r%   rS   rk   )r-   r|   r}   rH   s       r.   _scroll_genzServerCursorMixin._scroll_gen   s      ///W$WWWXXX+,,33G4:#5#5KK2>>KN4:&&
 

 :++E22222222222r0   c                    t          |t                    r|                    | j                  }t          |t          j                  st	          j        |          }t	          j        d          t	          j        | j                  g}| j	        0|
                    t	          j        | j	        rdnd                     |
                    t	          j        d                     | j        r'|
                    t	          j        d                     |
                    t	          j        d                     |
                    |           t	          j        d                              |          S )NDECLARESCROLLz	NO SCROLLCURSORz	WITH HOLDFORr3   )
isinstancebytesdecodera   r   
Composableri   rm   r%   r&   appendr'   r8   )r-   rH   r9   s      r.   rN   z)ServerCursorMixin._make_declare_statement   s*   eU## 	1LL00E%00 	#GENNE GIN4:&&
 'LLT-=!N;OOPPPSWX&&'''> 	/LL--...SWU^^$$$Uws||  '''r0   )NN)__name__
__module____qualname____doc__r6   	__slots__strr   boolr/   r5   propertyr!   r"   r#   intrG   r   r   r   r\   rY   rO   r   r   r{   r   r   ComposedrN   __classcell__r:   s   @r.   r    r    %   sK       NNIOOQQI TN 	   #       c    X  HTN       X  $    X 
-8C= 
- 
- 
- X
- $(!%	( ((  ( 	(
 
t( ( ( (>uT{    3E$K 3 3 3 34Bhsm Bd3i0@ B B B B(3 3C 3E$K 3 3 3 3(U (s| ( ( ( ( ( ( ( (r0   r    c                       e Zd ZdZdZedddddded	ee         d
efd            Zeddddddede	e
         d	ee         d
ef
d            Zdddddddedee	e
                  d	ee         d
ef
dZd)dZd) fdZ	 d*dddedee         dee         dedef
dZdddedee         deddfdZdee
         fdZd+d!edee
         fd"Zdee
         fd#Zdee
         fd$Zd,d&ed'eddfd(Z xZS )-ServerCursorpsycopg NFr"   r#   
connectionzConnection[Row]r!   r"   r#   c                    d S Nr   r-   r   r!   r"   r#   s        r.   r/   zServerCursor.__init__   	     sr0   Connection[Any]row_factoryc                    d S r   r   r-   r   r!   r   r"   r#   s         r.   r/   zServerCursor.__init__   	     sr0   r   r"   r#   c                |    t          j        | ||p|j                   t                              | |||           d S N)r   )r   r/   r   r    r   s         r.   r/   zServerCursor.__init__   sN     	*+*O9O	
 	
 	
 	
 	""4z8DDDDDr0   r1   c                 J    | j         st          d|  dt                     d S d S Nzthe server-side cursor z[ was deleted while still open. Please use 'with' or '.close()' to close the cursor properlyrt   r   ResourceWarningr<   s    r.   __del__zServerCursor.__del__   O    { 	P$ P P P    	 	r0   c                 ,   | 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rS   lockrt   waitrO   r4   closer-   r:   s    r.   r   zServerCursor.close  s     Z_ 	 	{ 	 	 	 	 	 	 	 	 :$ 3
 1 1222GGMMOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   	B	AB		BBrJ   rH   rI   rJ   kwargsc                   |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.
        keyword not supported: r   2server-side cursors not supported in pipeline modeN	TypeErrorlistr^   pipeline_statusru   NotSupportedErrorrS   r   r   r\   _NO_TRACEBACKwith_tracebackr-   rH   rI   rJ   r   exs         r.   r   zServerCursor.execute  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_seqr   c                *    t          j        d          )z/Method not implemented for server-side cursors.0executemany not supported on server-side cursorsru   r   r-   rH   r   r   s       r.   executemanyzServerCursor.executemany(  s     !"TUUUr0   c                     | 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   rS   r   r   r{   rD   r-   recss     r.   fetchonezServerCursor.fetchone2  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   sizec                     |s| j         }| j        j        5  | j                            |                     |                    }d d d            n# 1 swxY w Y   | xj        t          |          z  c_        |S r   	arraysizerS   r   r   r{   rD   lenr-   r   r   s      r.   	fetchmanyzServerCursor.fetchmany;  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   rS   r   r   r{   rD   r   r   s     r.   fetchallzServerCursor.fetchallC  s    Z_ 	: 	::??4??4#8#899D	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:		SYY		r   c              #     K   	 | j         j        5  | j                             |                     | j                            }d d d            n# 1 swxY w Y   |D ]}| xj        dz  c_        |V  t          |          | j        k     rd S NTr   rS   r   r   r{   r*   rD   r   r-   r   recs      r.   __iter__zServerCursor.__iter__I  s      	 G Gztt}'E'EFFG G G G G G G G G G G G G G G  		Q						4yy4=((	s   3AAAr   r|   r}   c                     | 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 )Nr   )rS   r   r   r   rD   r-   r|   r}   s      r.   scrollzServerCursor.scrollS  s    Z_ 	; 	;JOOD,,UD99:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; :IIIIIIDIIIs   /AAAr1   Nr   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   r   s   @r.   r   r      s       JI &*  % 
 TN    X  &*  % 
  _ TN    X 26%)E E E%E E
 jo.E TNE E E E E   	 	 	 	 	 	 $(
 "&    
   
   > V V VV V$V
 V 
V V V V(3-     c $s)    $s)    (3-     C s D        r0   r   r   c                       e Zd ZdZdZedddddded	ee         d
efd            Zeddddddede	e
         d	ee         d
ef
d            Zdddddddedee	e
                  d	ee         d
ef
dZd)dZd) fdZ	 d*dddedee         dee         dedef
dZdddedee         deddfdZdee
         fdZd+d!edee
         fd"Zdee
         fd#Zdee
         fd$Zd,d&ed'eddfd(Z xZS )-AsyncServerCursorr   r   NFr   r   zAsyncConnection[Row]r!   r"   r#   c                    d S r   r   r   s        r.   r/   zAsyncServerCursor.__init__c  r   r0   AsyncConnection[Any]r   c                    d S r   r   r   s         r.   r/   zAsyncServerCursor.__init__m  r   r0   r   c                |    t          j        | ||p|j                   t                              | |||           d S r   )r   r/   r   r    r   s         r.   r/   zAsyncServerCursor.__init__x  sO     	*+*O9O	
 	
 	
 	
 	""4z8DDDDDr0   r1   c                 J    | j         st          d|  dt                     d S d S r   r   r<   s    r.   r   zAsyncServerCursor.__del__  r   r0   c                 x  K   | j         j        4 d {V  | j        r	 d d d           d {V  d S | j         j        s2| j                             |                                            d {V  t                                                       d {V  d d d           d {V  d S # 1 d {V swxY w Y   d S r   r   r   s    r.   r   zAsyncServerCursor.close  s     :? 	" 	" 	" 	" 	" 	" 	" 	"{ 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" :$ 9joodoo&7&7888888888''--//!!!!!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   	B)A$B))
B36B3r   rH   rI   rJ   r   c                  K   |r%t          dt          |          d                    | j        j        rt	          j        d          	 | 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 )Nr   r   r   r   r   s         r.   r   zAsyncServerCursor.execute  s       	IGd6ll1oGGHHH<' 	%D  	*z P P P P P P P Pjood&7&7vv&N&NOOOOOOOOOP P P P P P P P P P P P P P P P P P P P P P P P P P P 	* 	* 	*##D)))	* s<   B7 6B%B7 %
B//B7 2B/3B7 7C CC Tr   r   r   c                .   K   t          j        d          )Nr   r   r   s       r.   r   zAsyncServerCursor.executemany  s       !"TUUUr0   c                   K   | j         j        4 d {V  | j                             |                     d                     d {V }d d d           d {V  n# 1 d {V swxY w Y   |r| xj        dz  c_        |d         S d S r   r   r   s     r.   r   zAsyncServerCursor.fetchone  s     :? 	= 	= 	= 	= 	= 	= 	= 	=););<<<<<<<<D	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	IINII7N4   4A
A%(A%r   r   c                 (  K   |s| j         }| j        j        4 d {V  | j                            |                     |                     d {V }d d d           d {V  n# 1 d {V swxY w Y   | xj        t          |          z  c_        |S r   r   r   s      r.   r   zAsyncServerCursor.fetchmany  s=      	">D:? 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@)>)>????????D	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@		SYY		s   4A$$
A.1A.c                   K   | j         j        4 d {V  | j                             |                     d                      d {V }d d d           d {V  n# 1 d {V swxY w Y   | xj        t          |          z  c_        |S r   r   r   s     r.   r   zAsyncServerCursor.fetchall  s.     :? 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@)>)>????????D	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@		SYY		r   c                N  K   	 | j         j        4 d {V  | j                             |                     | j                             d {V }d d d           d {V  n# 1 d {V swxY w Y   |D ]}| xj        dz  c_        |W V  t          |          | j        k     rd S r   r   r   s      r.   	__aiter__zAsyncServerCursor.__aiter__  sb     	z M M M M M M M M!Z__T__T]-K-KLLLLLLLLM M M M M M M M M M M M M M M M M M M M M M M M M M M  		Q							4yy4=((	s   9A!!
A+.A+r   r|   r}   c                    K   | j         j        4 d {V  | j                             |                     ||                     d {V  d d d           d {V  d S # 1 d {V swxY w Y   d S r   )rS   r   r   r   r   s      r.   r   zAsyncServerCursor.scroll  s*     :? 	A 	A 	A 	A 	A 	A 	A 	A*//$"2"25$"?"?@@@@@@@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	As   5A
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   r   r   r   s   @r.   r   r   ]  s        JI &*  * 
 TN    X  &*  * 
 %S) TN    X 7;%)E E E*E E
 oc23E TNE E E E E   " " " " " " $(
 "&    
   
   8 V V VV V$V
 V 
V V V V     C S	    S	    s!3    A A# AS A$ A A A A A A A Ar0   r   r   N)4r   typingr   r   r   r   r   r   r	   r
   warningsr   r   r   r   r   ru   abcr   r   r   r   rowsr   r   r   cursorr   r   _compatr   
generatorsr   cursor_asyncr   r   r   connection_asyncr   r)   Formatr+   rX   
ExecStatusrU   rB   TransactionStatusrg   rh   r    r   r   r   r0   r.   <module>r     s~    @ ? ? ? ? ? ? ? ? ? ? ? ? ? 4 4 4 4 4 4 4 4 4 4                         5 5 5 5 5 5 5 5 5 5 5 5 2 2 2 2 2 2 2 2 2 2 & & & & & & & &             % % % % % % 2&&&&&&111111 	y~		]%
M#		 


&l( l( l( l( l(
>3#67 l( l( l(^F F F F F$%6%;<fSk F F FR|A |A |A |A |A,c12K4D|A |A |A |A |Ar0   