
    dh                      ~    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y)
    N   )connect)_PoolContextManager_PoolConnectionContextManager_PoolAcquireContextManagerc           	      :    t        d| ||||d|}t        |      S )Nminsizemaxsizeechopool_recycleloop )_create_poolr   )r
   r   r   r   r   kwargscoros          G/var/www/netwell/bot/venv/lib/python3.12/site-packages/aiomysql/pool.pycreate_poolr      s2     Ht%1H@FHDt$$    c           	        K   |t        j                         }t        d| ||||d|}| dkD  r@|j                  4 d {    |j	                  d       d {    d d d       d {    |S |S 7 17 7 # 1 d {  7  sw Y   |S xY ww)Nr	   r   Fr   )asyncioget_event_loopPool_cond_fill_free_pool)r
   r   r   r   r   r   pools          r   r   r      s     |%%' @t)@8>@D{:: 	. 	.&&u---	. 	.K4K	.-	. 	. 	. 	.KsX   =BA1 BA7A3A7B(A5)	B3A75B7B
=B >B
B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y)r   zConnection poolc                 j   |dk  rt        d      ||k  r|dk7  rt        d      || _        || _        || _        d| _        t        j                  |xs d       | _        t        j                         | _
        t               | _        t               | _        d| _        d| _        || _        || _        y )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WAFGG
" &&go>
&&(
U
5
$r   c                     | j                   S N)r.   r0   s    r   r   z	Pool.echo6   s    zzr   c                     | j                   S r3   )r!   r4   s    r   r
   zPool.minsize:   s    }}r   c                 .    | j                   j                  S r3   )r'   r   r4   s    r   r   zPool.maxsize>   s    zz   r   c                 `    | j                   t        | j                        z   | j                  z   S r3   )freesizelenr*   r$   r4   s    r   sizez	Pool.sizeB   s"    }}s4::.@@r   c                 ,    t        | j                        S r3   )r9   r'   r4   s    r   r8   zPool.freesizeF   s    4::r   c                 V  K   | j                   4 d{    | j                  r?| j                  j                         }|j                          d{    | j                  r?| j                   j	                          ddd      d{    y7 z7 >7 	# 1 d{  7  sw Y   yxY ww)z#Close all free connections in pool.N)r   r'   popleftensure_closednotifyr0   conns     r   clearz
Pool.clearJ   s     :: 	  	 **zz))+((*** ** JJ		  	  	  +	  	  	  	 s\   B)BB):BBB#B=B)B	B)BB)B&BB&"B)c                     | j                   S )zW
        The readonly property that returns ``True`` if connections is closed.
        )r-   r4   s    r   closedzPool.closedR   s    
 ||r   c                 ,    | j                   ryd| _        y)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,   r4   s    r   closez
Pool.closeY   s     <<r   c                     | j                          t        | j                        D ]-  }|j                          | j                  j	                  |       / | j                  j                          y)zbTerminate pool.

        Close pool with instantly closing all acquired connections also.
        N)rF   listr*   r+   addrB   r@   s     r   	terminatezPool.terminatec   sT     	

$ 	'DJJL  &	' 	

r   c                    K   | j                   ry| j                  st        d      | j                  r7| j                  j	                         }|j                          | j                  r7| j                  4 d{    | j                  | j                  kD  r<| j                  j                          d{    | j                  | j                  kD  r<ddd      d{    d| _         y7 q7 87 # 1 d{  7  sw Y   d| _         yxY ww)z(Wait for closing all pool's connections.Nz..wait_closed() should be called after .close()T)
r-   r,   RuntimeErrorr'   r=   rF   r   r:   r8   waitr@   s     r   wait_closedzPool.wait_closedq   s      <<}}  0 1 1 jj::%%'DJJL jj :: 	( 	())dmm+jjoo''' ))dmm+	( 	( 		('	( 	( 	( 	( s`   A'D*D:C,;D>7C25C.6C2DC0 D.C20D2D8C;9D Dc                 :    | j                         }t        ||       S )z&Acquire free connection from the pool.)_acquirer   )r0   r   s     r   acquirezPool.acquire   s    }})$55r   c                 &  K   | j                   rt        d      | j                  4 d {    	 | j                  d       d {    | j                  r|| j                  j                         }|j                  rJ |       || j                  vsJ || j                  f       | j                  j                  |       |cd d d       d {    S | j                  j                          d {    7 7 7 ,7 # 1 d {  7  sw Y   y xY ww)Nz,Cannot acquire connection after closing poolT)
r,   rL   r   r   r'   r=   rD   r*   rI   rM   r@   s     r   rP   zPool._acquire   s     ==MNN:: 
	, 
	,**4000::::--/D#{{0D0?tzz1ED$**3EE1JJNN4(
	, 
	, 
	, **//+++ 
	,0
	, ,
	, 
	, 
	,su   (DC4DC<C6A:C<?DC8DC<.C:/C<4D6C<8D:C<<DDD
Dc                 `  K   t        | j                        }d}||k  rC| j                  d   }|j                  j                         s|j                  j	                         r+| j                  j                          |j                          n|j                  j                  r+| j                  j                          |j                          n| j                  dkD  r_| j                  j                         |j                  z
  | j                  kD  r+| j                  j                          |j                          n| j                  j                          |dz  }||k  rC| j                  | j                  k  r| xj                  dz  c_        	 t!        d| j"                  | j                  d| j$                   d {   }| j                  j'                  |       | j(                  j+                          | xj                  dz  c_        | j                  | j                  k  r| j                  ry |r| j,                  r| j                  | j,                  k  r| xj                  dz  c_        	 t!        d| j"                  | j                  d| j$                   d {   }| j                  j'                  |       | j(                  j+                          | xj                  dz  c_        y y y 7 4# | xj                  dz  c_        w xY w7 n# | xj                  dz  c_        w xY ww)Nr   r   )r   r   r   )r9   r'   _readerat_eof	exceptionpoprF   eof_receivedr/   r"   time
last_usagerotater:   r
   r$   r   r.   r#   appendr   r?   r   )r0   override_min	free_sizenrA   s        r   r   zPool._fill_free_pool   sR    

O	)m::b>D||""$(>(>(@

 

 **

 

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

 

 

!!#FA+ )m. ii$,,&OOq O%$ :$**4:: :'+'8'8: : 

!!$'

!!#1$ ii$,,& ::T\\1IOOq O%$ :$**4:: :'+'8'8: : 

!!$'

!!#1$ 2J<: 1$: 1$sg   EL.#.L./K8 K59K8 ;.L.*A	L.4/L #L$9L L.5K8 8LL.L L++L.c                    K   | j                   4 d {    | j                   j                          d d d       d {    y 7 /7 # 1 d {  7  sw Y   y xY wwr3   )r   r?   r4   s    r   _wakeupzPool._wakeup   sL     :: 	  	 JJ	  	  	  	  	  	  	 sA   AAAAAAAAAAAAc                 r   | j                   j                         }|j                  d       || j                  v r0|j                  sJ |       | j                  j                  |       |S || j                  v sJ || j                  f       | j                  j                  |       |j                  s|j                         }|r|j                          |S | j                  r|j                          n| j                  j                  |       | j                   j                  | j                               }|S )zcRelease free connection back to the connection pool.

        This is **NOT** a coroutine.
        N)r"   create_future
set_resultr+   rD   remover*   get_transaction_statusrF   r,   r'   r]   create_taskrb   )r0   rA   futin_transs       r   releasezPool.release   s    
 jj&&(t4###;;$$;##D)Jtzz!5D$**#55!

${{224H


}}



!!$'**((8C
r   c                     t        d      )Nz9"yield from" should be used as context manager expression)rL   r4   s    r   	__enter__zPool.__enter__   s    GI 	Ir   c                      y r3   r   )r0   argss     r   __exit__zPool.__exit__   s     	r   c              #   V   K   | j                         E d {   }t        | |      S 7 wr3   )rQ   r   r@   s     r   __iter__zPool.__iter__   s(      ,,.(,T488 )s   )')c              #      K   d}t        j                  |t        d       | j                         E d {   }t	        | |      S 7 w)NzPwith await pool as conn deprecated, useasync with pool.acquire() as conn instead   )
stacklevel)warningswarnDeprecationWarningrQ   r   )r0   msgrA   s      r   	__await__zPool.__await__  s>     :c-!<,,.(,T488 )s   2AAAc                    K   | S wr3   r   r4   s    r   
__aenter__zPool.__aenter__	  s     s   c                 `   K   | j                          | j                          d {    y 7 wr3   )rF   rN   )r0   exc_typeexc_valexc_tbs       r   	__aexit__zPool.__aexit__  s!     

   s   $.,.N)__name__
__module____qualname____doc__r1   propertyr   r
   r   r:   r8   rB   rD   rF   rJ   rN   rQ   rP   r   rb   rk   rm   rp   rr   rz   r|   r   r   r   r   r   r   !   s    %$     ! ! A A     &6
,1%f 4I
9 9!r   r   )r   
   FrT   N)r   r%   rv   
connectionr   utilsr   r   r   r   r   AbstractServerr   r   r   r   <module>r      sO       0 0 AC% HJ 
m!7!! m!r   