
    Zh                      |    d dl Z d dlZd dlZddlmZ ddlmZmZmZ 	 	 ddZ		 	 dd	Z
 G d
 de j                  ZdS )    N   )connect)_PoolContextManager_PoolConnectionContextManager_PoolAcquireContextManager
   Fc           	      D    t          d| ||||d|}t          |          S )Nminsizemaxsizeechopool_recycleloop )_create_poolr   )r   r   r   r   r   kwargscoros          Z/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/aiomysql/pool.pycreate_poolr      sA     Ht%1H H@FH HDt$$$    c           	         K   |t          j                    }t          d| ||||d|}| dk    rL|j        4 d {V  |                    d           d {V  d d d           d {V  n# 1 d {V swxY w Y   |S )Nr   r   Fr   )asyncioget_event_loopPool_cond_fill_free_pool)r   r   r   r   r   r   pools          r   r   r      s5     |%'' @t)@ @8>@ @D{{: 	. 	. 	. 	. 	. 	. 	. 	.&&u---------	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.Ks   A++
A58A5c                       e Zd ZdZd Zed             Zed             Zed             Zed             Z	ed             Z
d Ze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S )r   zConnection poolc                    |dk     rt          d          ||k     r|dk    rt          d          || _        || _        || _        d| _        t          j        |pd           | _        t          j	                    | _
        t                      | _        t                      | _        d| _        d| _        || _        || _        d S )Nr   z!minsize should be zero or greaterz'maxsize should be not less than minsize)maxlenF)
ValueError_minsize_loop_conn_kwargs
_acquiringcollectionsdeque_freer   	Conditionr   set_used_terminated_closing_closed_echo_recycle)selfr   r   r   r   r   r   s          r   __init__zPool.__init__$   s    Q;;@AAAWAFGGG
" &go>>>
&((
UU
55
$r   c                     | j         S N)r0   r2   s    r   r   z	Pool.echo6   s
    zr   c                     | j         S r5   )r#   r6   s    r   r   zPool.minsize:   s
    }r   c                     | j         j        S r5   )r)   r!   r6   s    r   r   zPool.maxsize>   s    z  r   c                 J    | j         t          | j                  z   | j        z   S r5   )freesizelenr,   r&   r6   s    r   sizez	Pool.sizeB   s    }s4:.@@r   c                 *    t          | j                  S r5   )r;   r)   r6   s    r   r:   zPool.freesizeF   s    4:r   c                 "  K   | j         4 d{V  | j        r:| j                                        }|                                 d{V  | j        :| j                                          ddd          d{V  dS # 1 d{V swxY w Y   dS )z#Close all free connections in pool.N)r   r)   popleftensure_closednotifyr2   conns     r   clearz
Pool.clearJ   s/     : 	  	  	  	  	  	  	  	 * +z))++((********* * + J		  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   AA>>
BBc                     | j         S )zW
        The readonly property that returns ``True`` if connections is closed.
        )r/   r6   s    r   closedzPool.closedR   s    
 |r   c                 &    | j         rdS d| _        dS )zClose pool.

        Mark all pool connections to be closed on getting back to pool.
        Closed pool doesn't allow to acquire new connections.
        NT)r/   r.   r6   s    r   closez
Pool.closeY   s     < 	Fr   c                     |                                   t          | j                  D ]0}|                                  | j                            |           1| j                                         dS )zbTerminate pool.

        Close pool with instantly closing all acquired connections also.
        N)rH   listr,   r-   addrD   rB   s     r   	terminatezPool.terminatec   sk     	

$$ 	' 	'DJJLLL  &&&&
r   c                   K   | j         rdS | j        st          d          | j        r4| j                                        }|                                 | j        4| j        4 d{V  | j        | j        k    r/| j        	                                 d{V  | j        | j        k    /	 ddd          d{V  n# 1 d{V swxY w Y   d| _         dS )z(Wait for closing all pool's connections.Nz..wait_closed() should be called after .close()T)
r/   r.   RuntimeErrorr)   r?   rH   r   r<   r:   waitrB   s     r   wait_closedzPool.wait_closedq   s}      < 	F} 	1  0 1 1 1 j 	:%%''DJJLLL j 	 : 	( 	( 	( 	( 	( 	( 	( 	()dm++joo''''''''' )dm+++	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( s   *A B==
C
Cc                 J    |                                  }t          ||           S )z&Acquire free connection from the pool.)_acquirer   )r2   r   s     r   acquirezPool.acquire   s    }})$555r   c                   K   | j         rt          d          | j        4 d {V  	 |                     d           d {V  | j        rr| j                                        }|j        r
J |            || j        vsJ || j        f            | j                            |           |cd d d           d {V  S | j        	                                 d {V  # 1 d {V swxY w Y   d S )Nz,Cannot acquire connection after closing poolT)
r.   rN   r   r   r)   r?   rF   r,   rK   rO   rB   s     r   rR   zPool._acquire   s     = 	OMNNN: 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	,	,**4000000000: ,:--//D#{00D00?tz111D$*3E111JNN4(((
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, *//+++++++++	,
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	,s   BC< C
C&)C&c                 d  K   t          | j                  }d}||k     r/| j        d         }|j                                        s|j                                        r.| j                                         |                                 n|j        j        r.| j                                         |                                 n|| j        dk    rX| j	        
                                |j        z
  | j        k    r.| j                                         |                                 n| j                                         |dz  }||k     /| j        | j        k     r| xj        dz  c_        	 t!          d| j        | j	        d| j         d {V }| j                            |           | j                                         | xj        dz  c_        n# | xj        dz  c_        w xY w| j        | j        k     | j        rd S |r| j        r| j        | j        k     r| xj        dz  c_        	 t!          d| j        | j	        d| j         d {V }| j                            |           | j                                         | xj        dz  c_        d S # | xj        dz  c_        w xY wd S d S )Nr   r	   r   )r   r   r   )r;   r)   _readerat_eof	exceptionpoprH   eof_receivedr1   r$   time
last_usagerotater<   r   r&   r   r0   r%   appendr   rA   r   )r2   override_min	free_sizenrC   s        r   r   zPool._fill_free_pool   s     
OO	)mm:b>D|""$$ $(>(>(@(@ $
   

 * 
$
   

-"$$*//##do5EE
   

 
!!###FA+ )mm. i$,&&OOq OO%$ :$*4: : :'+'8: : : : : : : : 
!!$'''
!!###1$1$ i$,&& : 	F 		% 		%T\1I1IOOq OO%$ :$*4: : :'+'8: : : : : : : : 
!!$'''
!!###1$1$		% 		%1I1Is   0AG G*0AJ J+c                    K   | j         4 d {V  | j                                          d d d           d {V  d S # 1 d {V swxY w Y   d S r5   )r   rA   r6   s    r   _wakeupzPool._wakeup   s      : 	  	  	  	  	  	  	  	 J	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   =
A
Ac                 `   | j                                         }|                    d           || j        v r-|j        s
J |            | j                            |           |S || j        v sJ || j        f            | j                            |           |j        s|                                }|r|                                 |S | j	        r|                                 n| j
                            |           | j                             |                                           }|S )zcRelease free connection back to the connection pool.

        This is **NOT** a coroutine.
        N)r$   create_future
set_resultr-   rF   remover,   get_transaction_statusrH   r.   r)   r^   create_taskrc   )r2   rC   futin_transs       r   releasezPool.release   s&   
 j&&((t4###;$$$$;##D)))Jtz!!!D$*#5!!!
${ 		92244H 


} (


!!$'''*((88C
r   c                      t          d          )Nz9"yield from" should be used as context manager expression)rN   r6   s    r   	__enter__zPool.__enter__   s    GI I 	Ir   c                     d S r5   r   )r2   argss     r   __exit__zPool.__exit__   s	     	r   c              #   Z   K   |                                  E d {V }t          | |          S r5   )rS   r   rB   s     r   __iter__zPool.__iter__   s7       ,,..((((((,T4888r   c              #      K   d}t          j        |t          d           |                                 E d {V }t	          | |          S )NzPwith await pool as conn deprecated, useasync with pool.acquire() as conn instead   )
stacklevel)warningswarnDeprecationWarningrS   r   )r2   msgrC   s      r   	__await__zPool.__await__  sT      :c-!<<<<,,..((((((,T4888r   c                 
   K   | S r5   r   r6   s    r   
__aenter__zPool.__aenter__	  s      r   c                 f   K   |                                   |                                  d {V  d S r5   )rH   rP   )r2   exc_typeexc_valexc_tbs       r   	__aexit__zPool.__aexit__  s=      

           r   N)__name__
__module____qualname____doc__r3   propertyr   r   r   r<   r:   rD   rF   rH   rL   rP   rS   rR   r   rc   rl   rn   rq   rs   r{   r}   r   r   r   r   r   r   !   s       % % %$   X   X ! ! X! A A XA   X        X      &6 6 6
, , ,1% 1% 1%f       4I I I  
9 9 9 9 9 9  ! ! ! ! !r   r   )r   r   Fr	   N)r   r'   rw   
connectionr   utilsr   r   r   r   r   AbstractServerr   r   r   r   <module>r      s               0 0 0 0 0 0 0 0 0 0 AC% % % % HJ 
 
 
 
m! m! m! m! m!7! m! m! m! m! m!r   