
    gi                        d Z ddlmZ ddl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 ddlmZ ddlmZmZ ddlmZ  ej        d          Z G d deee                   ZdS )z6
Psycopg null connection pool module (async version).
    )annotationsN)Anycast)AsyncConnection)TransactionStatus   )ACTAsyncConnectFailedCBAsyncConnectionCB)PoolTimeoutTooManyRequests)ConnectionTimeout)AEvent)AddConnectionAsyncConnectionPool)_BaseNullConnectionPoolzpsycopg.poolc                       e Zd Z	 d3 ede          ddddddddddddddd	d
d4 fd%Zd5d6d(Zd7d+Zd8d/Zd9d:d0Z	d;d1Z
d<d2Z xZS )=AsyncNullConnectionPool 	type[ACT]Nr         >@g      @g     @g     r@   )connection_classkwargsmin_sizemax_sizeopen	configurecheckresetnametimeoutmax_waitingmax_lifetimemax_idlereconnect_timeoutreconnect_failednum_workersconninfostrr   r   dict[str, Any] | Noner   intr   
int | Noner   bool | Noner   AsyncConnectionCB[ACT] | Noner   r    r!   
str | Noner"   floatr#   r$   r%   r&   r'   AsyncConnectFailedCB | Noner(   c               j    t                                          ||||||	||||
||||||           d S )N)r   r   r   r   r    r   r   r   r!   r"   r#   r$   r%   r&   r(   )super__init__)selfr)   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   	__class__s                     l/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/psycopg_pool/null_pool_async.pyr5   z AsyncNullConnectionPool.__init__   s`    * 	-#%/#! 	 	
 	
 	
 	
 	
    returnNonec                  K   |                                   | j        4 d{V  | j        rJ t                      | _        ddd          d{V  n# 1 d{V swxY w Y   t                              d| j                   |                     t          |                      | j        	                    |           d{V s-| 
                                 d{V  t          d| d          | j        4 d{V  | j        sJ d| _        ddd          d{V  n# 1 d{V swxY w Y   t                              d| j                   dS )a9  
        Create a connection for test.

        Calling this function will verify that the connectivity with the
        database works as expected. However the connection will not be stored
        in the pool.

        Close the pool, and raise `PoolTimeout`, if not ready within *timeout*
        sec.
        Nz"waiting for pool %r initializationz%pool initialization incomplete after z seczpool %r is ready to use)_check_open_getconn_lock_pool_full_eventr   loggerinfor!   run_taskr   wait_timeoutcloser   )r6   r"   s     r8   waitzAsyncNullConnectionPool.waitB   sr      	  """: 	- 	- 	- 	- 	- 	- 	- 	-,,,,$*HHD!	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	8$)DDDmD))****77@@@@@@@@ 	U**,,SgSSSTTT: 	) 	) 	) 	) 	) 	) 	) 	)(((($(D!	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	-ty99999s#   A
A A D##
D-0D-float | None
ACT | Nonec                
  K   ||dk    rt                      d }| j        dk    s| j        | j        k     r^	 |                     |           d {V }n/# t          $ r"}t          t          |                    d d }~ww xY w| xj        dz  c_        no| j        rht          | j                  | j        k    rK| j	        | j
        xx         dz  cc<   t          d| j        ddt          | j                   dz             |S )	Ng        r   )r"   r   z	the pool z has already z requests waiting)r   r   _nconns_connectr   r*   r#   len_waiting_stats_REQUESTS_ERRORSr   r!   )r6   r"   connexs       r8   _get_ready_connectionz-AsyncNullConnectionPool._get_ready_connection_   s:     7c>>--=A!=!=5!]]7];;;;;;;;$ 5 5 5!#b''**45LLALLL 	#dm"4"48H"H"HK-...!3...!5DI555;c$-((;;;<   s   A 
B A;;B rP   r	   boolc                ~  K   | j         4 d {V  | j        s| j        r	 d d d           d {V  dS d |_        |j        j        t          j        k    r| j        | j	        xx         dz  cc<   |
                                 d {V  | xj        dz  c_        	 d d d           d {V  dS # 1 d {V swxY w Y   d S )NFr   T)r>   _closedrM   _poolpgconntransaction_statusr   UNKNOWNrN   _RETURNS_BADrD   rJ   r6   rP   s     r8   _maybe_close_connectionz/AsyncNullConnectionPool._maybe_close_connectiont   s      : 		 		 		 		 		 		 		 		< DM 		 		 		 		 		 		 		 		 		 		 		 		 		 		 DJ{-1B1JJJD-...!3...**,,LLALL		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		s   B,A&B,,
B69B6c                   K   |                      ||          \  }}t                              d| j        ||           | j        4 d{V  || _        || _        ddd          d{V  dS # 1 d{V swxY w Y   dS )zwChange the size of the pool during runtime.

        Only *max_size* can be changed; *min_size* must remain 0.
        z&resizing %r to min_size=%s max_size=%sN)_check_sizer@   rA   r!   r>   	_min_size	_max_size)r6   r   r   s      r8   resizezAsyncNullConnectionPool.resize   s     
 "--hAA(4di8	
 	
 	
 : 	& 	& 	& 	& 	& 	& 	& 	&%DN%DN	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s   A--
A7:A7c                
   K   dS )z9No-op, as the pool doesn't have connections in its state.N )r6   s    r8   r   zAsyncNullConnectionPool.check   s      r9   c                  K   d |_         | j        4 d {V  | j        r:| j                                                            |           d {V rnR| j        :|                                 d {V  | j        r| j                                         n| xj        dz  c_        	 d d d           d {V  d S # 1 d {V swxY w Y   d S )Nr   )rV   r>   rM   popleftsetrD   r?   rJ   r[   s     r8   _add_to_poolz$AsyncNullConnectionPool._add_to_pool   s      
 : 	& 	& 	& 	& 	& 	& 	& 	&- & ..0044T:::::::: 	 - & jjll""""""" ( &)--//// LLA%LLL!	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s   BB88
CC)r   )"r)   r*   r   r   r   r+   r   r,   r   r-   r   r.   r   r/   r   r/   r    r/   r!   r0   r"   r1   r#   r,   r$   r1   r%   r1   r&   r1   r'   r2   r(   r,   )r   )r"   r1   r:   r;   )r"   rF   r:   rG   )rP   r	   r:   rS   )N)r   r,   r   r-   r:   r;   )r:   r;   )rP   r	   r:   r;   )__name__
__module____qualname__r   r   r5   rE   rR   r\   ra   r   rg   __classcell__)r7   s   @r8   r   r      s        &
 '+d;&H&H(,# 37/3/3'##+8<'&
 &
 &
 &
 &
 &
 &
 &
P: : : : ::   *   & & & & &   & & & & & & & &r9   r   )__doc__
__future__r   loggingtypingr   r   psycopgr   
psycopg.pqr   abcr	   r
   r   errorsr   r   _compatr   _acompatr   
pool_asyncr   r   base_null_poolr   	getLoggerr@   r   rc   r9   r8   <module>ry      sE    # " " " " "          # # # # # # ( ( ( ( ( ( = = = = = = = = = = 0 0 0 0 0 0 0 0 & & & & & &       : : : : : : : : 3 3 3 3 3 3		>	*	*T& T& T& T& T&57J37O T& T& T& T& T&r9   