
    *Jf\(              	          U d Z ddlZddlmZ ddlmZmZ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 ddlmZ ddlmZmZ ddlm Z m!Z!m"Z" erddl#m$Z$ ddl%m&Z& ddl'm(Z(m)Z) ddl*m+Z+ ede	dee	eee,f                  f         f         Z-ee.d<   ej/        j0        Z0ej/        j1        Z1ej2        j3        Z3ej4        j5        Z5 ej6        d          Z7 G d d          Z8 G d de8          Z9 G d de8          Z:dS )z
commands pipeline management
    N)TracebackType)AnyListOptionalUnionTupleTypeTYPE_CHECKING)	TypeAlias   )pq)errors)PipelineCommandPQGen)DequeSelf)connection_summary)pgconn_encoding)KeyPrepare)pipeline_communicate
fetch_manysend)PGresult)
BaseCursor)BaseConnection
Connection)AsyncConnectionzBaseCursor[Any, Any]PendingResultpsycopgc                      e Zd ZU ee         ed<   ee         ed<   dZee	         ed<   ddZ
defd	Zedej        fd
            Zede	fd            Zedefd            Zded         fdZdee         ddfdZded         fdZded         fdZded         fdZde	ded         fdZdeded         ddfdZddZdS )BasePipelinecommand_queueresult_queueN_is_supportedconnBaseConnection[Any]returnc                     || _         |j        | _        t          t                               | _        t          t
                               | _        d| _        d S )Nr   )_connpgconnr   r   r#   r   r$   level)selfr&   s     T/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/psycopg/_pipeline.py__init__zBasePipeline.__init__.   sC    
k"?355!-022


    c                     | j         j         d| j         j         }t          | j        j                  }d| d| dt          |           ddS )N.< z at 0xx>)	__class__
__module____qualname__r   r*   r+   id)r-   clsinfos      r.   __repr__zBasePipeline.__repr__5   s[    *JJT^-HJJ!$*"344232222RXX22222r0   c                 >    t          j        | j        j                  S N)r   PipelineStatusr+   pipeline_statusr-   s    r.   statuszBasePipeline.status:   s     !<===r0   c                 p    t           j        |                                  t           _        t           j        S )zCReturn `!True` if the psycopg libpq wrapper supports pipeline mode.)r"   r%   _not_supported_reasonr;   s    r.   is_supportedzBasePipeline.is_supported>   s-     %--0-F-F-H-H)HL&))r0   c                     t          j                    dk     rdt          j                     dS t           j        dk     rdt           j         dS dS )zReturn the reason why the pipeline mode is not supported.

        Return an empty string if pipeline mode is supported.
        i" zlibpq too old z+; v14 or greater required for pipeline modez libpq too old: module built for  )r   version__build_version__rF   s    r.   rE   z"BasePipeline._not_supported_reasonE   sk     :<<&  = = = =
 &((=23G = = =
 rr0   c              #   Z  K   |                                  s)t          j        d|                                            | j        dk    r| j                                         n6| j        s| j        j        t          k    r| 
                                E d {V  | xj        dz  c_        d S )Nzpipeline mode not supported: r   r   )rG   eNotSupportedErrorrE   r,   r+   enter_pipeline_moder#   transaction_statusACTIVE	_sync_genrB   s    r.   
_enter_genzBasePipeline._enter_gen[   s        "" 	%N0J0J0L0LNN   :??K++---- 	(4;#AV#K#K ~~'''''''''

a



r0   excc                 D   | xj         dz  c_         | j         dk    r| j        j        t          k    ro	 | j                                         d S # t
          j        $ r?}|rt                              d| |           n|	                    d           Y d }~d S d }~ww xY wd S d S )Nr   r   zerror ignored exiting %r: %s)
r,   r+   rC   BADexit_pipeline_moderM   OperationalErrorloggerwarningwith_traceback)r-   rT   exc2s      r.   _exitzBasePipeline._exitl   s    

a

:??t{1S88	4..00000% 4 4 4  4NN#A4NNNN--d333 ONNNNN4 ?88s   A B4BBc              #      K   |                                   |                                 E d {V  |                     d          E d {V  d S )NFflush_enqueue_sync_communicate_gen
_fetch_genrB   s    r.   rR   zBasePipeline._sync_genz   sh      ((*********???///////////r0   c              #      K   	 |                                   |                                 E d{V  |                     d          E d{V  dS # |                     d          E d{V  w xY w)z_
        Exit current pipeline by sending a Sync and fetch back all remaining results.
        NTr_   ra   rB   s    r.   	_exit_genzBasePipeline._exit_gen   s      	3   ,,.........T22222222222tT2222222222s   .A A.c              #      K   t          | j        | j                  E d{V }d}|D ]R}| j                                        }	 |                     ||           3# t          j        $ r}||}Y d}~Kd}~ww xY w||dS )zqCommunicate with pipeline to send commands and possibly fetch
        results, which are then processed.
        N)r   r+   r#   r$   popleft_process_resultsrM   Error)r-   fetched	exceptionresultsqueuedrT   s         r.   rc   zBasePipeline._communicate_gen   s       2$+t?QRRRRRRRR	 	$ 	$G&..00F$%%fg66667 $ $ $$ #I$  O ! s   AA7)A22A7r`   c             #     K   | j         sdS |r3| j                                         t          | j                  E d{V  d}| j         rut	          | j                  E d{V }|snX| j                                         }	 |                     ||           n # t          j        $ r}||}Y d}~nd}~ww xY w| j         u||dS )a^  Fetch available results from the connection and process them with
        pipeline queued items.

        If 'flush' is True, a PQsendFlushRequest() is issued in order to make
        sure results can be fetched. Otherwise, the caller may emit a
        PQpipelineSync() call to ensure the output buffer gets flushed before
        fetching.
        N)	r$   r+   send_flush_requestr   r   rh   ri   rM   rj   )r-   r`   rl   rm   rn   rT   s         r.   rd   zBasePipeline._fetch_gen   s        	F 	)K**,,,DK(((((((((	 	$!+DK!8!8888888G  &..00F$%%fg66667 $ $ $$ #I$  	$  O ! s   B B5'B00B5rn   rm   r   c                 V   |b|\  }|j         t          k    r(t          j        |t	          | j                            |j         t          k    rt          j        d          dS |\  }}|r(|\  }}}|j        j	        
                    ||||           |                    |           dS )ar  Process a results set fetched from the current pipeline.

        This matches 'results' with its respective element in the pipeline
        queue. For commands (None value in the pipeline queue), results are
        checked directly. For prepare statement creation requests, update the
        cache. Otherwise, results are attached to their respective cursor.
        N)encodingzpipeline aborted)rC   FATAL_ERRORrM   error_from_resultr   r+   PIPELINE_ABORTEDPipelineAbortedr*   	_preparedvalidate_set_results_from_pipeline)	r-   rn   rm   resultcursorprepinfokeyprepnames	            r.   ri   zBasePipeline._process_results   s     >IV}++)&?4;;W;WXXXX"222'(:;;; 32  &FH J"*T4&//T4III--g66666r0   c                     | j                             | j        j                   | j                            d           dS )z#Enqueue a PQpipelineSync() command.N)r#   appendr+   pipeline_syncr$   rB   s    r.   rb   zBasePipeline._enqueue_sync   s;    !!$+";<<<  &&&&&r0   )r&   r'   r(   Nr(   N)__name__r8   r9   r   r   __annotations__r   r%   r   boolr/   strr=   propertyr   r@   rC   classmethodrG   rE   r   rS   BaseExceptionr]   rR   rf   rc   rd   r   ri   rb    r0   r.   r"   r"   )   s        ))))&&&&$(M8D>(((   3# 3 3 3 3
 >) > > > X> *T * * * [* c    [*E$K    "4-0 4T 4 4 4 405; 0 0 0 0
35; 3 3 3 3%+     4 E$K    @7#7.2:.>7	7 7 7 70' ' ' ' ' 'r0   r"   c                        e Zd ZU dZdZded<   d fdZdd	Zdefd
Zde	e
e                  de	e         de	e         ddfdZ xZS )Pipelinez(Handler for connection in pipeline mode.r    Connection[Any]r*   r&   r(   Nc                 J    t                                          |           d S r?   superr/   r-   r&   r7   s     r.   r/   zPipeline.__init__   !    r0   c                    	 | j         j        5  | j                             |                                            ddd           dS # 1 swxY w Y   dS # t          j        $ r}|                    d          d}~ww xY w)zkSync the pipeline, send any pending command and receive and process
        all available results.
        Nr*   lockwaitrR   rM   _NO_TRACEBACKr[   r-   exs     r.   synczPipeline.sync   s    	* 2 2
 0 01112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 	* 	* 	*##D)))	*s9   A -AA AA AA A>$A99A>c                     | j         j        5  | j                             |                                            d d d            n# 1 swxY w Y   | S r?   r*   r   r   rS   rB   s    r.   	__enter__zPipeline.__enter__   s    Z_ 	/ 	/JOODOO--...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   -AA
A
exc_typeexc_valexc_tbc                    	 | j         j        5  | j                             |                                            d d d            n# 1 swxY w Y   nK# t          $ r>}|rt
                              d| |           n|                    d           Y d }~nd }~ww xY w|                     |           d S # |                     |           w xY wNz error ignored terminating %r: %s	r*   r   r   rf   	ExceptionrY   rZ   r[   r]   r-   r   r   r   r\   s        r.   __exit__zPipeline.__exit__   s   
	  2 2
 0 01112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 	0 	0 	0 0A4NNNN))$/// ONNNN	0 JJwDJJwsQ   A -AA AA AA B5 
B4BB5 BB5 5C)r&   r   r(   Nr   )r   r8   r9   __doc__r   r/   r   r   r   r   r	   r   r   r   __classcell__r7   s   @r.   r   r      s         22J     * * * *4    
 4./  -(  '	 
 
               r0   r   c                        e Zd ZU dZdZded<   d fdZdd	Zdefd
Zde	e
e                  de	e         de	e         ddfdZ xZS )AsyncPipelinez.Handler for async connection in pipeline mode.r    AsyncConnection[Any]r*   r&   r(   Nc                 J    t                                          |           d S r?   r   r   s     r.   r/   zAsyncPipeline.__init__  r   r0   c                 6  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 # t          j        $ r}|                    d           d }~ww xY wr?   r   r   s     r.   r   zAsyncPipeline.sync  s8     	*z 8 8 8 8 8 8 8 8joodnn&6&67777777778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 	* 	* 	*##D)))	*s:   A/ 3A	A/ 
A&&A/ )A&*A/ /B>BB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   | S r?   r   rB   s    r.   
__aenter__zAsyncPipeline.__aenter__  s      :? 	5 	5 	5 	5 	5 	5 	5 	5*//$//"3"3444444444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s   3A
A$'A$r   r   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   nK# t          $ r>}|rt
                              d| |           n|                    d           Y d }~nd }~ww xY w|                     |           d S # |                     |           w xY wr   r   r   s        r.   	__aexit__zAsyncPipeline.__aexit__  s     
	 z 8 8 8 8 8 8 8 8joodnn&6&67777777778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 	0 	0 	0 0A4NNNN))$/// ONNNN	0 JJwDJJwsR   A- 3A	A- 
A%%A- (A%)A- ,C -
B574B0+C 0B55C C&)r&   r   r(   Nr   )r   r8   r9   r   r   r/   r   r   r   r   r	   r   r   r   r   r   s   @r.   r   r     s         88J!!!!     * * * *$    
 4./  -(  '	 
 
               r0   r   );r   loggingtypesr   typingr   r   r   r   r   r	   r
   typing_extensionsr   rI   r   r   rM   abcr   r   _compatr   r   pq.miscr   
_encodingsr   
_preparingr   r   
generatorsr   r   r   pq.abcr   r{   r   
connectionr   r   connection_asyncr   bytesr   r   
ExecStatusrs   ru   
ConnStatusrV   TransactionStatusrQ   	getLoggerrY   r"   r   r   r   r0   r.   <module>r      s            I I I I I I I I I I I I I I I I I I ' ' ' ' ' '             ' ' ' ' ' ' ' '                 ' ' ' ' ' ' ' ' ' ' ' ' $ $ $ $ $ $ $ $ > > > > > > > > > > 2      """"""66666666111111 !%&sGU7J1K(LL
MMy    m'=1 m			$		9	%	%k' k' k' k' k' k' k' k'\(  (  (  (  ( | (  (  ( V%  %  %  %  % L %  %  %  %  % r0   