
    gif                        d 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 ddl
mZ dd	lmZmZ erdd
lmZ  G d d          Z G d d          ZdS )z9
psycopg connection pool base class and functionalities.
    )annotations)	monotonicrandom)TYPE_CHECKINGAny)errors   )
PoolClosed)CounterDeque)BaseConnectionc                     e Zd ZU dZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZded<   	 d>d?d%Zd@d'ZedAd(            ZedAd)            ZedBd+            ZdCd-ZdDd/ZdDd0ZdEd3ZdFd5ZdFd6ZdFd7Z e!dGd;            Z"dEd<Z#d=S )HBasePoolr   pool_minpool_max	pool_sizepool_availablerequests_waitingrequests_numrequests_queuedrequests_wait_msrequests_errorsusage_msreturns_badconnections_numconnections_msconnections_errorsconnections_lostz
Deque[Any]_pool conninfostrkwargsdict[str, Any] | Nonemin_sizeintmax_size
int | Nonename
str | Nonetimeoutfloatmax_waitingmax_lifetimemax_idlereconnect_timeoutnum_workersc       
           |                      ||          \  }}|s t          j        dz   x}t          _        d| }|dk     rt          d          || _        |pi | _        || _        || _        || _        || _	        || _
        |
| _        || _        |	| _        || _        || _        t!                      | _        t%          t&                               | _        || _        d| _        d| _        d| _        d| _        d S )Nr
   zpool-znum_workers must be at least 1FT)_check_sizer   	_num_pool
ValueErrorr"   r$   r*   	_min_size	_max_sizer,   r.   r1   r/   r0   r2   _nconnsr   r    r   r#   _stats_nconns_min_growing_opened_closed_open_implicit)selfr"   r$   r&   r(   r*   r,   r.   r/   r0   r1   r2   nums                a/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/psycopg_pool/base.py__init__zBasePool.__init__-   s    "--hAA( 	!'/'9A'==C($ 3==D??=>>> &,l	!!&!2( &WW
clnn $ #    returnc           
     n    d| j         j         d| j         j         d| j        dt	          |           dd	S )N<. z at 0xx>)	__class__
__module____name__r*   idr@   s    rB   __repr__zBasePool.__repr__f   sX    1) 1 1DN,C 1 1	1 1#%d8801 1 1	
rD   c                    | j         S N)r7   rP   s    rB   r&   zBasePool.min_sizel   
    ~rD   c                    | j         S rS   )r8   rP   s    rB   r(   zBasePool.max_sizep   rT   rD   boolc                    | j         S )z`!True` if the pool is closed.)r>   rP   s    rB   closedzBasePool.closedt   s     |rD   tuple[int, int]c                    ||}|dk     rt          d          ||k     rt          d          ||cxk    rdk    rn nt          d          ||fS )Nr   zmin_size cannot be negativez/max_size must be greater or equal than min_sizez3if min_size is 0 max_size must be greater or than 0)r6   )r@   r&   r(   s      rB   r4   zBasePool._check_sizey   s{    Ha<<:;;;hNOOOx$$$$1$$$$$RSSS!!rD   Nonec                N    | j         r| j        rt          j        d          d S d S )Nz8pool has already been opened/closed and cannot be reused)r>   r=   eOperationalErrorrP   s    rB   _check_openzBasePool._check_open   sA    < 	DL 	$J  	 	 	 	rD   c                    | j         r7| j        rt          d| j        d          t          d| j        d          d S )Nz	the pool z is already closedz is not open yet)r>   r=   r   r*   rP   s    rB   _check_open_getconnzBasePool._check_open_getconn   s\    < 	L| L !LTY!L!L!LMMM !JTY!J!J!JKKK		L 	LrD   connBaseConnection[Any]c                    t          |dd           x}| u rd S |rd|j        }nd}t          d| j        d| d|           )Nr    zit comes from pool zit doesn't come from any poolz can't return connection to pool z, z: )getattrr*   r6   )r@   rb   poolmsgs       rB   _check_pool_putconnzBasePool._check_pool_putconn   sp    D'4000DT99F 	25	55CC1CKtyKKcKKTKK
 
 	
rD   dict[str, int]c                |    t          | j                  }|                    |                                            |S )z<
        Return current stats about the pool usage.
        )dictr:   update_get_measures)r@   rvs     rB   	get_statszBasePool.get_stats   s6     $+
		$$$&&'''	rD   c                    | j         t                      c}| _         t          |          }|                    |                                            |S )zy
        Return current stats about the pool usage.

        After the call, all the counters are reset to zero.
        )r:   r   rk   rl   rm   )r@   statsrn   s      rB   	pop_statszBasePool.pop_stats   sF     "['))t{%[[
		$$$&&'''	rD   c           
         | j         | j        | j        | j        | j        | j        | j        t          | j                  iS )zG
        Return immediate measures of the pool (not counters).
        )		_POOL_MINr7   	_POOL_MAXr8   
_POOL_SIZEr9   _POOL_AVAILABLElenr    rP   s    rB   rm   zBasePool._get_measures   s9    
 NDNNDNOT\ #dj//	
 	
rD   valuemin_pcmax_pcc                <    |d||z
  t                      z  z   |z   z  S )zV
        Add a random value to *value* between *min_pc* and *max_pc* percent.
              ?r   )clsry   rz   r{   s       rB   _jitterzBasePool._jitter   s&    
 688;<vEFFrD   c                f    t                      |                     | j        dd          z   |_        dS )zeSet an expiry date on a connection.

        Add some randomness to avoid mass reconnection.
        g        N)r   r   r/   
_expire_at)r@   rb   s     rB   _set_connection_expiry_datez$BasePool._set_connection_expiry_date   s+    
 $++T5Fs(S(SSrD   N)r!   )r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r'   r/   r-   r0   r-   r1   r-   r2   r'   )rE   r#   )rE   r'   )rE   rV   )r&   r'   r(   r)   rE   rY   )rE   r[   )rb   rc   rE   r[   )rE   ri   )ry   r-   rz   r-   r{   r-   rE   r-   )$rN   rM   __qualname__r5   rt   ru   rv   rw   _REQUESTS_WAITING_REQUESTS_NUM_REQUESTS_QUEUED_REQUESTS_WAIT_MS_REQUESTS_ERRORS	_USAGE_MS_RETURNS_BAD_CONNECTIONS_NUM_CONNECTIONS_MS_CONNECTIONS_ERRORS_CONNECTIONS_LOST__annotations__rC   rQ   propertyr&   r(   rX   r4   r_   ra   rh   ro   rr   rm   classmethodr   r    rD   rB   r   r      s        I IIJ&O*"M(*(I L(&O.* 7$ 7$ 7$ 7$ 7$r
 
 
 
    X    X    X" " " "   L L L L

 

 

 

   	 	 	 		
 	
 	
 	
 G G G [GT T T T T TrD   r   c                  6    e Zd ZdZdZdZdZddZddZddZ	dS )AttemptWithBackoffzR
    Keep the state of a repeated operation attempt with exponential backoff.
    r}   g?g       @r,   r-   c               0    || _         d| _        d| _        d S )Nr   )r,   delay
give_up_at)r@   r,   s     rB   rC   zAttemptWithBackoff.__init__   s    
rD   nowrE   r[   c                ,   | j         dk    rA|| j        z   | _        t                              | j        | j         | j                  | _         n| xj         | j        z  c_         | j         |z   | j        k    rt          d| j        |z
            | _         dS dS )z7Calculate how long to wait for a new connection attemptr   N)	r   r,   r   r   r   INITIAL_DELAYDELAY_JITTERDELAY_BACKOFFmaxr@   r   s     rB   update_delayzAttemptWithBackoff.update_delay   s    :!DL0DO!))"T%6$68I DJJ JJ$,,JJ:do--S$/C"788DJJJ .-rD   rV   c                .    | j         dk    o
|| j         k    S )z8Return True if we are tired of trying this attempt. Meh.r   )r   r   s     rB   time_to_give_upz"AttemptWithBackoff.time_to_give_up   s    $?)??rD   N)r,   r-   )r   r-   rE   r[   )r   r-   rE   rV   )
rN   rM   r   __doc__r   r   r   rC   r   r   r   rD   rB   r   r      sq          MLM   
9 9 9 9@ @ @ @ @ @rD   r   N)r   
__future__r   timer   r   typingr   r   psycopgr	   r]   r   _compatr   r   psycopg._connection_baser   r   r   r   rD   rB   <module>r      s*    # " " " " "             % % % % % % % %             # # # # # # # # 8777777sT sT sT sT sT sT sT sTl@ @ @ @ @ @ @ @ @ @rD   