
    2il+                    $   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jL                  jN                  Z' G d de#def         Z(y)z
Psycopg Cursor object.
    )annotations)TracebackType)TYPE_CHECKINGAnyoverload)contextmanager)IterableIterator   )errors)pq)ParamsQueryQueryNoTemplate)CopyWriter)Row
RowFactoryRowMaker)SelfTemplate)Pipeline)
BaseCursor)
Connectionc                      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e	 d,ddd	 	 	 	 	 	 	 	 	 d-d       Zeddd	 	 	 	 	 	 	 d.d       Z	 d,ddd	 	 	 	 	 	 	 	 	 d/dZdd	 	 	 	 	 	 	 d0dZ	 d,ddd	 	 	 	 	 	 	 	 	 d1dZd2dZd3dZd4dZd5d6dZd7dZd&dZd8dZd9d:dZe	 d,dd 	 	 	 	 	 	 	 d;d!       Zd(d"Z xZS )<Cursorpsycopg c                     y Nr   )self
connections     M/var/www/html/secretsanta/venv/lib/python3.12/site-packages/psycopg/cursor.py__init__zCursor.__init__$   s    58    c                    y r    r   )r!   r"   row_factorys      r#   r$   zCursor.__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Cursor.__init__,   s%     	$'A:+A+Ar%   c                    | S r    r   r!   s    r#   	__enter__zCursor.__enter__2       r%   c                $    | j                          y r    )close)r!   exc_typeexc_valexc_tbs       r#   __exit__zCursor.__exit__5   s     	

r%   c                $    | j                          y)zI
        Close the current cursor and free associated resources.
        N)_closer-   s    r#   r1   zCursor.close=   s     	r%   c                    | j                   S )z9Writable attribute to control how result rows are formed.r*   r-   s    r#   r'   zCursor.row_factoryC   s        r%   c                F    || _         | j                  r ||       | _        y y r    )r*   pgresult	_make_row)r!   r'   s     r#   r'   zCursor.row_factoryH   s"    '==(.DN r%   c                $    | j                  |       S r    r9   r-   s    r#   _make_row_makerzCursor._make_row_makerN   s      &&r%   preparebinaryc                    y r    r   )r!   queryparamsr@   rA   s        r#   executezCursor.executeQ   s     r%   c                    y r    r   )r!   rC   r@   rA   s       r#   rE   zCursor.execute[   s     r%   c          	        	 | j                   j                  5  | j                   j                  | j                  ||||             ddd       | S # 1 sw Y   | S xY w# t        j
                  $ r}|j                  d      d}~ww xY w)z=
        Execute a query or command to the database.
        r?   N)_connlockwait_execute_gene_NO_TRACEBACKwith_traceback)r!   rC   rD   r@   rA   exs         r#   rE   zCursor.executed   s}    	* 

%%eVWV%T    	*##D))	*s4   A /AA AA A B1BBF)	returningc          	     r   	 | j                   j                  5  t        j                         r| j                   j                  r-| j                   j                  | j                  |||             n|| j                   j                         5  | j                   j                  | j                  |||             ddd       n,| j                   j                  | j                  |||             ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w# t        j                  $ r}|j                  d      d}~ww xY w)zI
        Execute the same command with a sequence of input data.
        N)rH   rI   r   is_supported	_pipelinerJ   _executemany_gen_pipeline_pipeline_nolock_executemany_gen_no_pipelinerL   rM   rN   )r!   rC   
params_seqrP   rO   s        r#   executemanyzCursor.executemanyx   s   	* ((* zz++

 ::5*iX
 "ZZ88:  JJOO $ > >$):y!"  JJOO99%YW#   (  	*##D))	*sM   D A2D
-C575D,D 5C>	:DD
D 
D D6 D11D6r   rA   sizec          	   #  "  K   | j                   j                  rt        j                  d      | j                  j
                  5  	 | j                  j                  | j                  ||||             d}| j                  j                  | j                  |            x}rqt        |j                        D ]*  }| j                  j                  || j                         , d}| j                  j                  | j                  |            x}rq| j                   j                   t"        k(  r| j                  j%                          	 | j                  j                  | j                  d            r-	 | j                  j                  | j                  d            r-	 | j                  j                  | j                  d             ddd       y# t        j                  $ r}|j                  d      d}~ww xY w# t&        $ r Y lw xY w# t&        $ r Y Ow xY w# | j                   j                   t"        k(  r| j                  j%                          	 | j                  j                  | j                  d            r-	 | j                  j                  | j                  d            r-n# t&        $ r Y nw xY w	 | j                  j                  | j                  d             w # t&        $ r Y w w xY ww xY w# 1 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 moderY   TFN)first)_pgconnpipeline_statusrL   ProgrammingErrorrH   rI   rJ   _stream_send_gen_stream_fetchone_genrangentuples_txload_rowr<   rM   rN   transaction_statusACTIVE_try_cancel	Exception)	r!   rC   rD   rA   rZ   r\   resposrO   s	            r#   streamzCursor.stream   s     <<''$$%OPPZZ__ 	

))%T)R !ZZ__T-F-Fu-MNNcN$S[[1 E"hh//T^^DDE!E "ZZ__T-F-Fu-MNNcN <<22f< JJ**,"jjood.G.Ge.G.TU  #jjood.G.Ge.G.TU

(A(A(A(NO5	 	 ?? .''--. %  %  <<22f< JJ**,"jjood.G.Ge.G.TU  #jjood.G.Ge.G.TU$ 


(A(A(A(NO$  =	 	s   ALLCG7LAH$+H	LH+G<<HH"	HLHL	HLHL"8L AJ43L 4	K 	=L ?K 	 L +K0/L 0	K<	9L ;K<	<L  LLLc              #  R   K   | j                   r	 |  | j                         syyw)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.
        N)r;   nextsetr-   s    r#   resultszCursor.results   s-      ==
||~	  s   %'c                   t        | j                         |cxk  rt        | j                        k  s'n t        d| dt        | j                         d      |dk  rt        | j                        |z   }| j                  |       | 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!   indexs     r#   
set_resultzCursor.set_result   s      DMM""e@c$--.@@s4==/A.BBVW  19&.E##E*r%   c                   | j                          | j                         }| j                  |j                  k  rG| j                  j                  | j                  | j                        }| xj                  dz  c_        |S y)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`
        r   N)_fetch_pipeline_check_result_for_fetch_posrc   rd   re   r<   r!   rj   records      r#   fetchonezCursor.fetchone   sa     	**,99s{{"XX&&tyy$..AFIINIMr%   c                B   | j                          | j                         }|s| j                  }| 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`
        )
rx   ry   	arraysizerd   	load_rowsrz   minrc   r<   rq   )r!   rZ   rj   recordss       r#   	fetchmanyzCursor.fetchmany   sz     	**,>>D(($$IIs499t+S[[94>>
 			S\!	r%   c                    | j                          | j                         }| j                  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`
        )rx   ry   rd   r   rz   rc   r<   )r!   rj   r   s      r#   fetchallzCursor.fetchall  sR     	**,(($$TYYT^^LKK	r%   c                    | S r    r   r-   s    r#   __iter__zCursor.__iter__  r/   r%   c                   | j                          | j                         }| j                  |j                  k  rG| j                  j                  | j                  | j                        }| xj                  dz  c_        |S t        d      )Nr   zno more records to return)rx   ry   rz   rc   rd   re   r<   StopIterationr{   s      r#   __next__zCursor.__next__!  sh    **,99s{{"XX&&tyy$..AFIINIM788r%   c                H    | j                          | j                  ||       y)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)rx   _scroll)r!   valuemodes      r#   scrollzCursor.scroll*  s     	UD!r%   writerc             #    K   	 | j                   j                  5  | j                   j                  | j                  ||             t	        | |      5 }| ddd       ddd       | j                  d       y# 1 sw Y   #xY w# 1 sw Y   'x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.
        r   Nr   )	rH   rI   rJ   _start_copy_genr   rL   rM   rN   rt   )r!   	statementrD   r   copyrO   s         r#   r   zCursor.copy8  s     	* 

 4 4Y GH$v. $J 	##A&  
  	*##D))	*sW   B>B 9BA:B B (B>:B	?BBB B;%B66B;;B>c                >   | j                   dur| j                  sv| j                  j                  r_| j                  j                  5  | j                  j                  | j                  j                  j                  d             d d d        y y y y # 1 sw Y   y xY w)NFT)flush)_execmany_returningr;   rH   rS   rI   rJ   
_fetch_genr-   s    r#   rx   zCursor._fetch_pipelineP  s    $$E1]]

$$ M



 4 4 ? ?d ? KLM M % # 2M Ms   A BB)r"   zConnection[Row])r"   Connection[Any]r'   RowFactory[Row])r"   r   r'   zRowFactory[Row] | None)returnr   )r2   ztype[BaseException] | Noner3   zBaseException | Noner4   zTracebackType | Noner   None)r   r   )r   r   )r'   r   r   r   )r   zRowMaker[Row]r    )
rC   r   rD   Params | Noner@   bool | NonerA   r   r   r   )rC   r   r@   r   rA   r   r   r   )
rC   r   rD   r   r@   r   rA   r   r   r   )rC   r   rW   zIterable[Params]rP   boolr   r   )
rC   r   rD   r   rA   r   rZ   intr   zIterator[Row])r   zIterator[Self])ru   r   r   r   )r   z
Row | None)r   )rZ   r   r   	list[Row])r   r   )r   r   )relative)r   r   r   strr   r   )r   r   rD   r   r   zWriter | Noner   zIterator[Copy])__name__
__module____qualname__	__slots__r   r$   r.   r5   r1   propertyr'   setterr>   rE   rX   rl   ro   rv   r}   r   r   r   r   r   r   r   rx   __classcell__)r+   s   @r#   r   r       s   JI8 8);J 
 UYB)B;QB, & %	
 
 ! ! / /
'  !%
  $" 
   
  
  $" 	
  
  !%
  $" 
   
* PU**(8*HL*	*B !%.
 #.. .
 . . 
.`4 &
9"  !%'
 !%'' '
 ' 
' '.Mr%   r   r   N))__doc__
__future__r   typesr   typingr   r   r   
contextlibr   collections.abcr	   r
    r   rL   r   abcr   r   r   r   r   r   rowsr   r   r   _compatr   r   rS   r   _cursor_baser   r"   r   TransactionStatusrg   r   r   r%   r#   <module>r      sn    #  / / % .   / /  + + #  $&				$	$wMZ)3./ wMr%   