
    R
hi$                       U d Z ddlmZ ddl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 dd
lmZmZmZ ddlmZ ddlmZmZmZ ddlmZ er&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& ddl'm(Z( dZ)de*d<   ej+        j,        Z,ej+        j-        Z-ej.        j/        Z/ej0        j1        Z1 ej2        d          Z3 G d d          Z4 G d de4          Z5 G d de4          Z6dS )z
commands pipeline management
    )annotationsN)TracebackType)TYPE_CHECKINGAny   )errors)pq)PipelineCommandPQGen)DequeSelf	TypeAlias)connection_summary)
fetch_manypipeline_communicatesend)capabilities)PGresult)KeyPrepare)
Connection)
BaseCursor)BaseConnection)AsyncConnectionzEtuple[BaseCursor[Any, Any], tuple[Key, Prepare, bytes] | None] | Noner   PendingResultpsycopgc                      e Zd ZU ded<   ded<   d!d	Zd"dZed#d            Zed$d            Z	d%dZ
d&dZd%dZd%dZd%dZd'dZd(dZd)dZd S )*BasePipelinezDeque[PipelineCommand]command_queuezDeque[PendingResult]result_queueconnBaseConnection[Any]returnNonec                    || _         |j        | _        t          t                               | _        t          t
                               | _        d| _        d S )Nr   )_connpgconnr   r
   r   r   r    level)selfr!   s     \/var/www/html/01_SiteInternet/03_Maps/venv/lib/python3.11/site-packages/psycopg/_pipeline.py__init__zBasePipeline.__init__/   sC    
k"?355!-022


    strc                    | 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__6   s[    *JJT^-HJJ!$*"344232222RXX22222r,   pq.PipelineStatusc                >    t          j        | j        j                  S N)r	   PipelineStatusr'   pipeline_statusr)   s    r*   statuszBasePipeline.status;   s     !<===r,   boolc                (    t          j                    S )zCReturn `!True` if the psycopg libpq wrapper supports pipeline mode.)r   has_pipeline)r8   s    r*   is_supportedzBasePipeline.is_supported?   s     (***r,   PQGen[None]c              #  
  K   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 )NT)checkr   r   )	r   rD   r(   r'   enter_pipeline_moder   transaction_statusACTIVE	_sync_genr@   s    r*   
_enter_genzBasePipeline._enter_genD   s      !----:??K++---- 	(4;#AV#K#K ~~'''''''''

a



r,   excBaseException | Nonec                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'   rA   BADexit_pipeline_modeeOperationalErrorloggerwarningwith_traceback)r)   rN   exc2s      r*   _exitzBasePipeline._exitR   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_genr@   s    r*   rL   zBasePipeline._sync_gen`   sh      ((*********???///////////r,   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[   r]   r@   s    r*   	_exit_genzBasePipeline._exit_gene   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_resultsrS   Error)r)   fetched	exceptionresultsqueuedrN   s         r*   r_   zBasePipeline._communicate_geno   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   rd   re   rS   rf   )r)   r\   rh   ri   rj   rN   s         r*   r`   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rj   r   ri   list[PGresult]c                p   |Z|\  }|j         t          k    r t          j        || j        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)rA   FATAL_ERRORrS   error_from_resultr'   	_encodingPIPELINE_ABORTEDPipelineAbortedr&   	_preparedvalidate_check_results_set_results)	r)   rj   ri   resultcursorprepinfokeyprepnames	            r*   re   zBasePipeline._process_results   s     >IV}++)&4;;PQQQQ"222'(:;;; 32  &FH J"*T4&//T4III!!'***(((((r,   c                    | j                             | j        j                   | j                            d           dS )z#Enqueue a PQpipelineSync() command.N)r   appendr'   pipeline_syncr    r@   s    r*   r^   zBasePipeline._enqueue_sync   s;    !!$+";<<<  &&&&&r,   N)r!   r"   r#   r$   )r#   r-   )r#   r;   )r#   rB   )r#   rF   )rN   rO   r#   r$   )r\   rB   r#   rF   )rj   r   ri   rm   r#   r$   r#   r$   )__name__r5   r6   __annotations__r+   r:   propertyrA   classmethodrE   rM   rY   rL   rb   r_   r`   re   r^    r,   r*   r   r   +   s7        ))))&&&&   3 3 3 3
 > > > X> + + + [+   4 4 4 40 0 0 0
3 3 3 3       @) ) ) ).' ' ' ' ' 'r,   r   c                  L     e Zd ZU dZdZded<   d fdZdd	ZddZddZ xZ	S )Pipelinez(Handler for connection in pipeline mode.r   Connection[Any]r&   r!   r#   r$   c                J    t                                          |           d S r=   superr+   r)   r!   r4   s     r*   r+   zPipeline.__init__   !    r,   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waitrL   rS   _NO_TRACEBACKrW   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>r   c                    | j         j        5  | j                             |                                            d d d            n# 1 swxY w Y   | S r=   r&   r   r   rM   r@   s    r*   	__enter__zPipeline.__enter__   s    Z_ 	/ 	/JOODOO--...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   -AA
A
exc_typetype[BaseException] | Noneexc_valrO   exc_tbTracebackType | Nonec                   	 | 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   rb   	ExceptionrU   rV   rW   rY   r)   r   r   r   rX   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#   r$   r   r#   r   r   r   r   rO   r   r   r#   r$   )
r   r5   r6   __doc__r   r+   r   r   r   __classcell__r4   s   @r*   r   r      s         22J     * * * *   
               r,   r   c                  L     e Zd ZU dZdZded<   d fdZdd	ZddZddZ xZ	S )AsyncPipelinez.Handler for async connection in pipeline mode.r   AsyncConnection[Any]r&   r!   r#   r$   c                J    t                                          |           d S r=   r   r   s     r*   r+   zAsyncPipeline.__init__   r   r,   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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   | S r=   r   r@   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   rO   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#   r$   r   r   r   )
r   r5   r6   r   r   r+   r   r   r   r   r   s   @r*   r   r      s         88J     * * * *   
               r,   r   )7r   
__future__r   loggingtypesr   typingr   r    r   rS   r	   abcr
   r   _compatr   r   r   pq.miscr   
generatorsr   r   r   _capabilitiesr   pq.abcr   
_preparingr   r   
connectionr   _cursor_baser   _connection_baser   connection_asyncr   r   r   
ExecStatusrp   rs   
ConnStatusrQ   TransactionStatusrK   	getLoggerrU   r   r   r   r   r,   r*   <module>r      s^     # " " " " "        % % % % % % % %             ' ' ' ' ' ' ' ' + + + + + + + + + + ' ' ' ' ' ' > > > > > > > > > > ' ' ' ' ' ' 2      ((((((((&&&&&&((((((000000111111 L      m'=1 m			$		9	%	%N' N' N' N' N' N' N' N'b(  (  (  (  ( | (  (  ( V%  %  %  %  % L %  %  %  %  % r,   