
    fj                       S SK Jr  S SKrS SKJrJr  S SKrS SKrS SKrS SK	r	S SK
Jr  S SKJrJrJr  S SKrSSKJr  SSKJr  SS	KJr  SS
KJr  \R,                  " \5      r " S S\5      r " S S\R6                  \SS9r " S S5      r " S S5      r " S S5      rSSSSSSSSSS\R@                  \RB                  S.S jjr"g)    )annotationsN)	AwaitableCallable)TracebackType)AnyOptionalType   )compat
connection)
exceptions)protocolc                  f   ^  \ rS rSrSS.         SU 4S jjjr\      SS j5       rSrU =r$ )	PoolConnectionProxyMeta   F)wrapc                 > U(       a  [        [        R                  5       H  nUR                  S5      (       d  XS;   a  M   [	        [        R                  U5      n[
        R                  " U5      (       d  MW  [
        R                  " U5      nU R                  XW5      n[        R                  " X5      nXU'   M     SU;  a  [        R                  R                  US'   [        T	U ]5  XX#5      $ )N___doc__)dirr   
Connection
startswithgetattrinspect
isfunctioniscoroutinefunction_wrap_connection_method	functoolsupdate_wrapperr   super__new__)
mclsnamebasesdctr   attrnamemethiscoroutinewrapper	__class__s
            E/var/www/html/GQ-WA/venv/lib/python3.13/site-packages/asyncpg/pool.pyr"   PoolConnectionProxyMeta.__new__   s     
 5 56&&s++xz44h?))$//%99$?66xM#227A 'H 7 #!+!6!6!>!>Iwt566    c                R   ^  SU 4S jjnU(       a  [         R                  " U5        U$ )Nc                   > U R                   c%  [        R                  " SR                  T5      5      e[	        U R                   R
                  T5      nU" U R                   /UQ70 UD6$ )NzJcannot call Connection.{}(): connection has been released back to the pool)_conr   InterfaceErrorformatr   r+   )selfargskwargsr(   	meth_names       r,   call_con_methodHPoolConnectionProxyMeta._wrap_connection_method.<locals>.call_con_method=   se    yy  //DDJF!E#$ $
 499..	:D		3D3F33r.   )r4   r   r5   r   r6   r   returnr   )r   markcoroutinefunction)r7   r)   r8   s   `  r,   r   /PoolConnectionProxyMeta._wrap_connection_method9   s!    		4 ((9r.    )
r$   strr%   ztuple[Type[Any], ...]r&   zdict[str, Any]r   boolr:   r   )r7   r>   r)   r?   r:   zCallable[..., Any])	__name__
__module____qualname____firstlineno__r"   staticmethodr   __static_attributes____classcell__)r+   s   @r,   r   r      sn     77 %7 	7 7 
!7 76 %)	 r.   r   c                  L    \ rS rSrSr      SS jrS	S jrS
S jrSS jrSr	g)PoolConnectionProxyN   )r1   _holderc                >    X l         Xl        UR                  U 5        g N)r1   rJ   
_set_proxy)r4   holdercons      r,   __init__PoolConnectionProxy.__init__T   s     	tr.   c                .    [        U R                  U5      $ rL   )r   r1   )r4   attrs     r,   __getattr__PoolConnectionProxy.__getattr__[   s    tyy$''r.   c                j    U R                   c  g U R                   S sol         UR                  S 5        U$ rL   )r1   rM   )r4   rO   s     r,   _detachPoolConnectionProxy._detach_   s/    99DYt
r.   c                    U R                   c-  SR                  U R                  R                  [	        U 5      S9$ SR                  U R                  R                  U R                   [	        U 5      S9$ )Nz <{classname} [released] {id:#x}>)	classnameidz<{classname} {con!r} {id:#x}>)rZ   rO   r[   )r1   r3   r+   r@   r[   r4   s    r,   __repr__PoolConnectionProxy.__repr__g   sn    995<<..11bh = @ @ 399..11tyyRX : O Or.   N)rN   PoolConnectionHolderrO   zconnection.Connectionr:   None)rS   r>   r:   r   )r:   zOptional[connection.Connection])r:   r>   )
r@   rA   rB   rC   	__slots__rP   rT   rW   r]   rE   r=   r.   r,   rH   rH   N   s6     $I*1F	(Or.   rH   T)	metaclassr   c                      \ rS rSrSr          SS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrSS
 jrSS jrSS jrSS jrSS jrSS jrSS jrSrg)r_   p   )r1   _pool_loop_proxy_max_queries_setup_max_inactive_time_in_use_inactive_callback_timeout_generationc                   Xl         S U l        S U l        X l        X@l        X0l        S U l        S U l        S U l        S U l	        g rL   )
re   r1   rg   rh   rj   ri   rl   rk   rm   rn   )r4   poolmax_queriessetupmax_inactive_times        r,   rP   PoolConnectionHolder.__init__x   sF     
59	59'"36:15)-*.r.   c                j    U R                   S L=(       a    U R                   R                  5       (       + $ rL   )r1   	is_closedr\   s    r,   is_connected!PoolConnectionHolder.is_connected   s&    yy$BTYY-@-@-B)BBr.   c                $    U R                   (       + $ rL   rk   r\   s    r,   is_idlePoolConnectionHolder.is_idle   s    <<r.   c                  #    U R                   b  [        R                  " S5      eU R                  R	                  5       I S h  vN U l         U R                  R
                  U l        U R                  5         U R                  5         g  NE7f)NzMPoolConnectionHolder.connect() called while another connection already exists)r1   r   InternalClientErrorre   _get_new_connectionrn   _maybe_cancel_inactive_callback_setup_inactive_callbackr\   s    r,   connectPoolConnectionHolder.connect   so     99 00,- - **88::	::11,,.%%' ;s   ABB	ABc                Z  #    U R                   b  U R                   R                  5       (       a   S U l         U R                  5       I S h  vN   OU R                  U R                  R                  :w  ae  U R                  R
                  R                  U R                   R                  U R                  S95        S U l         U R                  5       I S h  vN   U R                  5         [        X R                   5      =U l        nU R                  b   U R                  U5      I S h  vN   U R                  R
                  R!                  5       U l        U$  GN N N4! [        [        R                  4 a1  n U R                   R                  5       I S h  vN    Ue! Ue= fS nAff = f7f)Ntimeout)r1   rv   r   rn   re   rf   create_taskcloserm   r   rH   rg   ri   	ExceptionasyncioCancelledErrorcreate_futurerk   )r4   proxyexs      r,   acquirePoolConnectionHolder.acquire   sE    99		 3 3 5 5DI,,.  !7!77JJ((		68DI,,.  ,,.1$		BBe;;"kk%((( zz''557A ! ! )w556 

 ))//+++H"Hsy   AF+	E
B	F+E=F+E &E'E +,F+F+E F(8FFFF#F  F##F((F+c                  #    U R                   c  [        R                  " S5      eU R                  R	                  5       (       a  g S U l        U R                  R                  R                  U R                  :  a"  U R                  R                  US9I S h  vN   g U R                  U R                  R                  :w  a"  U R                  R                  US9I S h  vN   g  UnU R                  R                  R                  5       (       at  [        R                  " 5       n[        R                   " U R                  R                  R#                  5       U5      I S h  vN   Ub  U[        R                  " 5       U-
  -  nU R                  R$                  b  [        R&                  " U5       IS h  vN   U R                  R%                  5       I S h  vN   U R                  R%                  U R                  5      I S h  vN   S S S 5      IS h  vN   O"U R                  R)                  US9I S h  vN    U R3                  5         U R5                  5         g  GN GN GN N N Ne NW! , IS h  vN  (       d  f       NI= f NQ! [*        [,        R.                  4 a(  n U R                  R1                  5         Ue! Ue= fS nAff = f7f)NzAPoolConnectionHolder.release() called on a free connection holderr   )rk   r   r~   r1   rv   rm   	_protocolqueries_countrh   r   rn   re   _is_cancellingtime	monotonicr   wait_for_wait_for_cancellation_resetr   resetr   r   r   	terminate_releaser   )r4   r   budgetstartedr   s        r,   releasePoolConnectionHolder.release   s/    <<00+, , 99   99,,0A0AA ))//'/222tzz555 ))//'/222	Fyy""1133 ..*ooII''>>@   %dnn.88Fzz  ,!>>&11))**,,,**++DII666 211 iioofo555 	 	%%'[ 3 3 2,6 2111 67112 		 		##%b		s   BKIAKIK$A<J	  I"!AJ	 4I%5J	 8I-I',I-I)I-J	 I+J	 KJ	 5J6J	 :#KK"J	 %J	 'I-)I-+J	 -J3I64J J	 KJ	 	K$K >K KKKKc                T   #    U R                   c  g U R                   I S h  vN   g  N7frL   rz   r\   s    r,   wait_until_released(PoolConnectionHolder.wait_until_released  s     <<,,s   (&(c                p   #    U R                   b#  U R                   R                  5       I S h  vN   g g  N7frL   )r1   r   r\   s    r,   r   PoolConnectionHolder.close  s/     99  ))//### ! $s   +646c                T    U R                   b  U R                   R                  5         g g rL   )r1   r   r\   s    r,   r   PoolConnectionHolder.terminate  s#    99  II! !r.   c                    U R                   b  [        R                  " S5      eU R                  (       a@  U R                  R
                  R                  U R                  U R                  5      U l         g g )Nz/pool connection inactivity timer already exists)rl   r   r~   rj   re   rf   
call_later_deactivate_inactive_connectionr\   s    r,   r   -PoolConnectionHolder._setup_inactive_callback  se    "".00AC C ""&*jj&6&6&A&A'')M)M'OD# #r.   c                b    U R                   b"  U R                   R                  5         S U l         g g rL   )rl   cancelr\   s    r,   r   4PoolConnectionHolder._maybe_cancel_inactive_callback  s-    "".##**,&*D# /r.   c                    U R                   b  [        R                  " S5      eU R                  b+  U R                  R	                  5         U R                  5         g g )Nz/attempting to deactivate an acquired connection)rk   r   r~   r1   r   _release_on_closer\   s    r,   r   4PoolConnectionHolder._deactivate_inactive_connection"  sU    <<#00AC C 99  II! ""$ !r.   c                R    U R                  5         U R                  5         S U l        g rL   )r   r   r1   r\   s    r,   r   &PoolConnectionHolder._release_on_close0  s    ,,.	r.   c                H   U R                   c  gU R                   R                  5       (       d  U R                   R                  S5        SU l         U R                  b!  U R                  R	                  5         SU l        U R
                  R                  R                  U 5        g)zRelease this connection holder.N)rk   done
set_resultrg   rW   re   _queue
put_nowaitr\   s    r,   r   PoolConnectionHolder._release5  sx    <<||  ""LL##D) ;;"KK!DK 	

$$T*r.   )
r1   rn   rk   rl   rj   rh   re   rg   ri   rm   N)
rp   z'Pool'rq   floatrr   z:Optional[Callable[[PoolConnectionProxy], Awaitable[None]]]rs   r   r:   r`   )r:   r?   )r:   r`   )r:   rH   )r   Optional[float]r:   r`   )r@   rA   rB   rC   ra   rP   rw   r{   r   r   r   r   r   r   r   r   r   r   r   rE   r=   r.   r,   r_   r_   p   s     I// 	/
 J/ !/ 
/*C 	(#J=(~$"O+
%
+r.   r_   c                     \ rS rSrSrSrSSSSS.S jrS rS rS	 r	S
 r
S rS rS rS0S jrS rSS.     S1S jjrSS.   S2S jjrSSS. S3S jjrSSS.S jrSSS.S jrSSS.S jrSSSSSSSSSSSSS.S jrSSSSSSSSSSS.
S jrSSSSSSSSSSSSSSSSS.S jrSSSSS .S! jrSS.S" jrS# rSS.S$ jrS% rS& rS' rS( r S) r!S* r"S+ r#S, r$S- r%S. r&S/r'g)4PooliI  au  A connection pool.

Connection pool can be used to manage a set of connections to the database.
Connections are first acquired from the pool, then used, and then released
back to the pool.  Once a connection is released, it's reset to close all
open cursors and other resources *except* prepared statements.

Pools are created by calling :func:`~asyncpg.pool.create_pool`.
)r   rf   _minsize_maxsize_init_connectr   _connect_args_connect_kwargs_holders_initialized_initializing_closing_closed_connection_class_record_classrn   ri   rh   !_max_inactive_connection_lifetimeN)r   rr   initr   c               :   [        U5      S:  a  [        R                  " S[        SS9  U	c  [        R
                  " 5       n	Xl        US::  a  [        S5      eUS:  a  [        S5      eX:  a  [        S5      eUS::  a  [        S	5      eUS:  a  [        S
5      e[        U
[        R                  5      (       d  [        SR                  U
5      5      e[        U[        R                  5      (       d  [        SR                  U5      5      eXl        X l        / U l        SU l        SU l        S U l        Xl        Xl        SU l        SU l        SU l        Ub  UO[        R4                  U l        Xl        Xl        X`l        Xpl        Xl         X0l!        UU l"        g )Nr
   zPassing multiple positional arguments to asyncpg.Pool constructor is deprecated and will be removed in asyncpg 0.17.0.  The non-deprecated form is asyncpg.Pool(<dsn>, **kwargs)   )
stacklevelr   z,max_size is expected to be greater than zeroz3min_size is expected to be greater or equal to zeroz!min_size is greater than max_sizez/max_queries is expected to be greater than zerozKmax_inactive_connection_lifetime is expected to be greater or equal to zerozMconnection_class is expected to be a subclass of asyncpg.Connection, got {!r}zErecord_class is expected to be a subclass of asyncpg.Record, got {!r}F)#lenwarningswarnDeprecationWarningr   get_event_looprf   
ValueError
issubclassr   r   	TypeErrorr3   r   Recordr   r   r   r   r   r   r   r   r   r   rn   r   r   r   r   ri   r   r   rh   r   )r4   min_sizemax_sizerq    max_inactive_connection_lifetimer   rr   r   r   loopconnection_classrecord_classconnect_argsconnect_kwargss                 r,   rP   Pool.__init__\  s    |q MM0 #q2 <))+D
q=KLLa<EG G @AA!NOO+a/#$ $ *J,A,ABB//5v6F/GI I ,88++16,+?A A ! !"!1)#*#6J<N<N)-
', 	.r.   c                V  #    U R                   (       a  U $ U R                  (       a  [        R                  " S5      eU R                  (       a  [        R                  " S5      eSU l         U R                  5       I S h  vN   U SU l        SU l         $  N! SU l        SU l         f = f7f)Nz)pool is being initialized in another taskpool is closedTF)r   r   r   r2   r   _initializer\   s    r,   _async__init__Pool._async__init__  s     K++;= =<<++,<==!	%""$$$!&D $D	 % "'D $Ds0   A)B),B ?B B B)B B&&B)c                  #    [         R                  " U R                  S9U l        [	        U R                  5       Hc  n[        U U R                  U R                  U R                  S9nU R                  R                  U5        U R                  R                  U5        Me     U R                  (       a  U R                  S   nUR                  5       I S h  vN   U R                  S:  a{  / n[        [        U R                  S S 5      5       H8  u  pRXPR                  S-
  :  a    O#UR                  UR                  5       5        M:     [         R                   " U6 I S h  vN   g g g  N N	7f)N)maxsize)rq   rs   rr   r
   )r   	LifoQueuer   r   ranger_   rh   r   ri   r   appendr   r   r   	enumeratereversedgather)r4   r   chfirst_chconnect_tasksis         r,   r   Pool._initialize  s&    ''>t}}%A% --"&"H"Hkk	#B MM  $KK""2& & == }}R(H""$$$}}q  "&xcr0B'CDEAMMA--!((6	 E nnm444 !  % 5s%   CE+E'B	E+E) E+)E+c                @    U R                   =(       d    U R                  $ )zOReturn ``True`` if the pool is closing or is closed.

.. versionadded:: 0.28.0
)r   r   r\   s    r,   
is_closingPool.is_closing  s    
 ||,t}},r.   c                :    [        S U R                   5       5      $ )zQReturn the current number of connections in this pool.

.. versionadded:: 0.25.0
c              3  @   #    U  H  oR                  5       v   M     g 7frL   )rw   .0hs     r,   	<genexpr> Pool.get_size.<locals>.<genexpr>  s     ;]>>##]s   sumr   r\   s    r,   get_sizePool.get_size  s    
 ;T]];;;r.   c                    U R                   $ )zQReturn the minimum number of connections in this pool.

.. versionadded:: 0.25.0
)r   r\   s    r,   get_min_sizePool.get_min_size      
 }}r.   c                    U R                   $ )zYReturn the maximum allowed number of connections in this pool.

.. versionadded:: 0.25.0
)r   r\   s    r,   get_max_sizePool.get_max_size  r  r.   c                :    [        S U R                   5       5      $ )zVReturn the current number of idle connections in this pool.

.. versionadded:: 0.25.0
c              3  n   #    U  H+  oR                  5       =(       a    UR                  5       v   M-     g 7frL   )rw   r{   r   s     r,   r   %Pool.get_idle_size.<locals>.<genexpr>  s#     K]>>#3		3]s   35r   r\   s    r,   get_idle_sizePool.get_idle_size  s    
 KT]]KKKr.   c                     U/U l         X l        g)aZ  Set the new connection arguments for this pool.

The new connection arguments will be used for all subsequent
new connection attempts.  Existing connections will remain until
they expire. Use :meth:`Pool.expire_connections()
<asyncpg.pool.Pool.expire_connections>` to expedite the connection
expiry.

:param str dsn:
    Connection arguments specified using as a single string in
    the following format:
    ``postgres://user:pass@host:port/database?option=value``.

:param \*\*connect_kwargs:
    Keyword arguments for the :func:`~asyncpg.connection.connect`
    function.

.. versionadded:: 0.16.0
N)r   r   )r4   dsnr   s      r,   set_connect_argsPool.set_connect_args  s    * "U-r.   c                  #    U R                   " U R                  U R                  U R                  U R                  S.U R
                  D6I S h  vN n[        XR                  5      (       d  U R                  nUR                   SUR                   3n[        U5      nUR                  S:X  a  UR                  nOUR                   SUR                   3n[        R                  " SU SU S35      eU R                  b   U R                  U5      I S h  vN   U$ U$  N N
! [        [        R                  4 a'  n UR!                  5       I S h  vN    Ue! Ue= fS nAff = f7f)N)r   r   r   .builtinsz9expected pool connect callback to return an instance of 'z', got '')r   r   rf   r   r   r   
isinstancerA   r@   typer   r2   r   r   r   r   r   )r4   rO   goodgood_nbadbad_nr   s          r,   r   Pool._get_new_connection  sT    MM!33++	

 ""
 
 #5566))D($--9Fs)C~~+>>*!CLL>:++8<wa1 
 ::!jjo%% 
s
K
, &w556 

 ))+%%H"Hsg   AE'DB2E'D# D!D# E'!D# #E$>EEEEEEE$$E'r   c                  #    U R                  5        ISh  vN nUR                  " U/UQ7SU06I Sh  vN sSSS5      ISh  vN   $  N3 N N	! , ISh  vN  (       d  f       g= f7f)zExecute an SQL command (or commands).

Pool performs this operation using one of its connections.  Other than
that, it behaves identically to
:meth:`Connection.execute() <asyncpg.connection.Connection.execute>`.

.. versionadded:: 0.10.0
Nr   )r   execute)r4   queryr   r5   rO   s        r,   r  Pool.executeA  sD      <<>>SUCTC7CC ">>C ">>>S   A+AA+AAAA+AA+AA+A(AA($A+c                  #    U R                  5        ISh  vN nUR                  XUS9I Sh  vN sSSS5      ISh  vN   $  N- N N	! , ISh  vN  (       d  f       g= f7f)a  Execute an SQL *command* for each sequence of arguments in *args*.

Pool performs this operation using one of its connections.  Other than
that, it behaves identically to
:meth:`Connection.executemany()
<asyncpg.connection.Connection.executemany>`.

.. versionadded:: 0.10.0
Nr   )r   executemany)r4   commandr5   r   rO   s        r,   r$  Pool.executemanyR  s>       <<>>SHH ">>H ">>>R   A%AA%AAAA%A	 A%A	A%A"AA"A%r   r   c                  #    U R                  5        ISh  vN nUR                  " U/UQ7UUS.6I Sh  vN sSSS5      ISh  vN   $  N4 N N	! , ISh  vN  (       d  f       g= f7f)a  Run a query and return the results as a list of :class:`Record`.

Pool performs this operation using one of its connections.  Other than
that, it behaves identically to
:meth:`Connection.fetch() <asyncpg.connection.Connection.fetch>`.

.. versionadded:: 0.10.0
Nr(  )r   fetchr4   r   r   r   r5   rO   s         r,   r*  
Pool.fetche  sV      <<>>S  )	  ">> ">>>S   A,AA,AAAA,AA,AA,A)AA)%A,r   columnr   c                  #    U R                  5        ISh  vN nUR                  " U/UQ7X#S.6I Sh  vN sSSS5      ISh  vN   $  N3 N N	! , ISh  vN  (       d  f       g= f7f)zRun a query and return a value in the first row.

Pool performs this operation using one of its connections.  Other than
that, it behaves identically to
:meth:`Connection.fetchval()
<asyncpg.connection.Connection.fetchval>`.

.. versionadded:: 0.10.0
Nr.  )r   fetchval)r4   r   r/  r   r5   rO   s         r,   r1  Pool.fetchval|  sQ      <<>>S>>%+> > ">>> ">>>r"  c                  #    U R                  5        ISh  vN nUR                  " U/UQ7UUS.6I Sh  vN sSSS5      ISh  vN   $  N4 N N	! , ISh  vN  (       d  f       g= f7f)zRun a query and return the first row.

Pool performs this operation using one of its connections.  Other than
that, it behaves identically to
:meth:`Connection.fetchrow() <asyncpg.connection.Connection.fetchrow>`.

.. versionadded:: 0.10.0
Nr(  )r   fetchrowr+  s         r,   r4  Pool.fetchrow  sV      <<>>S  )	  ">> ">>>r-  c                  #    U R                  5        ISh  vN nUR                  XX4S9I Sh  vN sSSS5      ISh  vN   $  N- N N	! , ISh  vN  (       d  f       g= f7f)a6  Run a query for each sequence of arguments in *args*
and return the results as a list of :class:`Record`.

Pool performs this operation using one of its connections.  Other than
that, it behaves identically to
:meth:`Connection.fetchmany()
<asyncpg.connection.Connection.fetchmany>`.

.. versionadded:: 0.30.0
Nr(  )r   	fetchmany)r4   r   r5   r   r   rO   s         r,   r7  Pool.fetchmany  sH      <<>>SW '   ">> ">>>r'  )columnsschema_namer   r3   oids	delimiternullheaderquoteescapeforce_quoteencodingc                  #    U R                  5        ISh  vN nUR                  UUUUUUUUU	U
UUUUS9I Sh  vN sSSS5      ISh  vN   $  N9 N N	! , ISh  vN  (       d  f       g= f7f)a  Copy table contents to a file or file-like object.

Pool performs this operation using one of its connections.  Other than
that, it behaves identically to
:meth:`Connection.copy_from_table()
<asyncpg.connection.Connection.copy_from_table>`.

.. versionadded:: 0.24.0
N)outputr9  r:  r   r3   r;  r<  r=  r>  r?  r@  rA  rB  )r   copy_from_table)r4   
table_namerD  r9  r:  r   r3   r;  r<  r=  r>  r?  r@  rA  rB  rO   s                   r,   rE  Pool.copy_from_table  so     6 <<>>S,,'#'! -   ">> ">>>sS   A1AA1 AAAA1AA1AA1A.A A.*A1)
r   r3   r;  r<  r=  r>  r?  r@  rA  rB  c                  #    U R                  5        ISh  vN nUR                  " U/UQ7UUUUUUUU	U
UUS.6I Sh  vN sSSS5      ISh  vN   $  N= N N	! , ISh  vN  (       d  f       g= f7f)a  Copy the results of a query to a file or file-like object.

Pool performs this operation using one of its connections.  Other than
that, it behaves identically to
:meth:`Connection.copy_from_query()
<asyncpg.connection.Connection.copy_from_query>`.

.. versionadded:: 0.24.0
N)rD  r   r3   r;  r<  r=  r>  r?  r@  rA  rB  )r   copy_from_query)r4   r   rD  r   r3   r;  r<  r=  r>  r?  r@  rA  rB  r5   rO   s                  r,   rI  Pool.copy_from_query  ss     2 <<>>S,, #'!  ">> ">>>U   A5AA5$AA AA5AA5AA5A2!A$"A2.A5)r9  r:  r   r3   r;  freezer<  r=  r>  r?  r@  rA  force_not_null
force_nullrB  wherec                  #    U R                  5        ISh  vN nUR                  UUUUUUUUU	U
UUUUUUUUS9I Sh  vN sSSS5      ISh  vN   $  N= N N	! , ISh  vN  (       d  f       g= f7f)zCopy data to the specified table.

Pool performs this operation using one of its connections.  Other than
that, it behaves identically to
:meth:`Connection.copy_to_table()
<asyncpg.connection.Connection.copy_to_table>`.

.. versionadded:: 0.24.0
N)sourcer9  r:  r   r3   r;  rL  r<  r=  r>  r?  r@  rA  rM  rN  rB  rO  )r   copy_to_table)r4   rF  rQ  r9  r:  r   r3   r;  rL  r<  r=  r>  r?  r@  rA  rM  rN  rB  rO  rO   s                       r,   rR  Pool.copy_to_table  s{     > <<>>S**'#'-%!% +   ">> ">>>rK  )r9  r:  r   rO  c          
        #    U R                  5        ISh  vN nUR                  UUUUUUS9I Sh  vN sSSS5      ISh  vN   $  N1 N N	! , ISh  vN  (       d  f       g= f7f)a%  Copy a list of records to the specified table using binary COPY.

Pool performs this operation using one of its connections.  Other than
that, it behaves identically to
:meth:`Connection.copy_records_to_table()
<asyncpg.connection.Connection.copy_records_to_table>`.

.. versionadded:: 0.24.0
N)recordsr9  r:  r   rO  )r   copy_records_to_table)r4   rF  rU  r9  r:  r   rO  rO   s           r,   rV  Pool.copy_records_to_table7  sW     & <<>>S22' 3   ">> ">>>sS   A)A	A)AAAA)AA)AA)A&AA&"A)c                   [        X5      $ )a  Acquire a database connection from the pool.

:param float timeout: A timeout for acquiring a Connection.
:return: An instance of :class:`~asyncpg.connection.Connection`.

Can be used in an ``await`` expression or with an ``async with`` block.

.. code-block:: python

    async with pool.acquire() as con:
        await con.execute(...)

Or:

.. code-block:: python

    con = await pool.acquire()
    try:
        await con.execute(...)
    finally:
        await pool.release(con)
)PoolAcquireContext)r4   r   s     r,   r   Pool.acquireT  s    . "$00r.   c                   ^ ^#    U U4S jnT R                   (       a  [        R                  " S5      eT R                  5         Tc  U" 5       I S h  vN $ [        R
                  " U" 5       TS9I S h  vN $  N& N7f)Nc                   >#    TR                   R                  5       I S h  vN n  U R                  5       I S h  vN nTU l        U$  N& N! [        [
        R                  4 a    TR                   R                  U 5        e f = f7frL   )r   getr   rm   r   r   r   r   )r   r   r4   r   s     r,   _acquire_impl$Pool._acquire.<locals>._acquire_impln  sp     {{((B	 jjl* & )*w556 &&r*s5   BABA A
A 
B
A 7BBzpool is closingr   )r   r   r2   _check_initr   r   )r4   r   r^  s   `` r,   _acquirePool._acquirem  si     	 ==++,=>>?&((2 2 2 )2s$   AA;A7!A;2A93A;9A;c                 #    [        U5      [        Ld  UR                  R                  U La#  [        R
                  " SR                  US95      eUR                  c  gU R                  5         UR                  R                  5         UR                  nUc  UR                  n[        R                  " UR                  U5      5      I Sh  vN $  N7f)a  Release a database connection back to the pool.

:param Connection connection:
    A :class:`~asyncpg.connection.Connection` object to release.
:param float timeout:
    A timeout for releasing the connection.  If not specified, defaults
    to the timeout provided in the corresponding call to the
    :meth:`Pool.acquire() <asyncpg.pool.Pool.acquire>` method.

.. versionchanged:: 0.14.0
    Added the *timeout* parameter.
zWPool.release() received invalid connection: {connection!r} is not a member of this poolr   N)r  rH   rJ   re   r   r2   r3   r1   r`  _on_releaserm   r   shieldr   )r4   r   r   r   s       r,   r   Pool.release  s      $77""((4++>>Df) ?E ?+, ,
 ??" 	##%?kkG
 ^^BJJw$78888s   C
CCCc                  #    U R                   (       a  gU R                  5         SU l        Sn U R                  R	                  SU R
                  5      nU R                   Vs/ s H  o"R                  5       PM     nn[        R                  " U6 I Sh  vN   U R                   Vs/ s H  o"R                  5       PM     nn[        R                  " U6 I Sh  vN    Ub  UR                  5         SU l         SU l        gs  snf  Nps  snf  N3! [        [        R                  4 a    U R                  5         e f = f! Ub  UR                  5         SU l         SU l        f = f7f)a2  Attempt to gracefully close all connections in the pool.

Wait until all pool connections are released, close them and
shut down the pool.  If any error (including cancellation) occurs
in ``close()`` the pool will terminate by calling
:meth:`Pool.terminate() <pool.Pool.terminate>`.

It is advisable to use :func:`python:asyncio.wait_for` to set
a timeout.

.. versionchanged:: 0.16.0
    ``close()`` now waits until all pool connections are released
    before closing them and the pool.  Errors raised in ``close()``
    will cause immediate pool termination.
NT<   F)r   r`  r   rf   r   _warn_on_long_closer   r   r   r   r   r   r   r   r   )r4   warning_callbackr   release_corosclose_coross        r,   r   
Pool.close  s@      <<	"#zz44D,, . 48==B3@R&&(=  B..-000 &*]]4%2r
]  4..+...  + '')DL!DM!B04.7112 	NN	
  + '')DL!DMsd   ,E#4D #D <D DD 'D D DD "E# D D ,D::D= =#E  E#c                .    [         R                  S5        g )NzPool.close() is taking over 60 seconds to complete. Check if you have any unreleased connections left. Use asyncio.wait_for() to set a timeout for Pool.close().)loggerwarningr\   s    r,   ri  Pool._warn_on_long_close  s     ' 	(r.   c                    U R                   (       a  gU R                  5         U R                   H  nUR                  5         M     SU l         g)z&Terminate all connections in the pool.NT)r   r`  r   r   r4   r   s     r,   r   Pool.terminate  s6    <<--BLLN  r.   c                6   #    U =R                   S-  sl         g7f)zExpire all currently open connections.

Cause all currently open connections to get replaced on the
next :meth:`~asyncpg.pool.Pool.acquire()` call.

.. versionadded:: 0.16.0
r
   N)rn   r\   s    r,   expire_connectionsPool.expire_connections  s      	As   c                    U R                   (       d=  U R                  (       a  [        R                  " S5      e[        R                  " S5      eU R                  (       a  [        R                  " S5      eg )Nzipool is being initialized, but not yet ready: likely there is a race between creating a pool and using itzpool is not initializedr   )r   r   r   r2   r   r\   s    r,   r`  Pool._check_init  s^      !! //    ++,EFF<<++,<== r.   c                |    U R                    H,  nUR                  c  M  UR                  R                  5         M.     g rL   )r   r1   _drop_local_statement_cachers  s     r,   _drop_statement_cachePool._drop_statement_cache  s*    --Bww"335  r.   c                |    U R                    H,  nUR                  c  M  UR                  R                  5         M.     g rL   )r   r1   _drop_local_type_cachers  s     r,   _drop_type_cachePool._drop_type_cache  s*    --Bww"..0  r.   c                >    U R                  5       R                  5       $ rL   )r   	__await__r\   s    r,   r  Pool.__await__  s    ""$..00r.   c                B   #    U R                  5       I S h  vN   U $  N7frL   )r   r\   s    r,   
__aenter__Pool.__aenter__  s!     !!### 	$s   c                @   #    U R                  5       I S h  vN   g  N7frL   )r   )r4   excs     r,   	__aexit__Pool.__aexit__  s     jjls   )r   r   r   r   r   r   rn   r   r   r   r   rf   r   rh   r   r   r   r   r   ri   rL   )r   r>   r   r   r:   r>   )r%  r>   r   r   )r:   list)(r@   rA   rB   rC   r   ra   rP   r   r   r   r  r  r  r  r  r   r  r$  r*  r1  r4  r7  rE  rI  rR  rV  r   ra  r   r   ri  r   rv  r`  r|  r  r  r  r  rE   r=   r.   r,   r   r   I  s   I O-b% 5B-<L.0&X "&	DD !	D
 
D, "&II
 !I.  
. 34T > 48d " 7; * !+d (^ )3t : "& 1220 48 $9L+"Z(	>611r.   r   c                  P    \ rS rSrSrS	S jrS r   S
       SS jjrS rSr	g)rY  i  )r   r   r   rp   c                8    Xl         X l        S U l        SU l        g )NF)rp   r   r   r   )r4   rp   r   s      r,   rP   PoolAcquireContext.__init__  s    		r.   c                   #    U R                   c  U R                  (       a  [        R                  " S5      eU R                  R                  U R                  5      I S h  vN U l         U R                   $  N7f)Nz a connection is already acquired)r   r   r   r2   rp   ra  r   r\   s    r,   r  PoolAcquireContext.__aenter__  sT     ??&$))++,NOO $		 2 24<< @@ As   AA7A5 A7Nc                   #    SU l         U R                  nS U l        U R                  R                  U5      I S h  vN   g  N7fNT)r   r   rp   r   )r4   exc_typeexc_valexc_tbrO   s        r,   r  PoolAcquireContext.__aexit__#  s6      	ooii$$$s   9AAAc                v    SU l         U R                  R                  U R                  5      R	                  5       $ r  )r   rp   ra  r   r  r\   s    r,   r  PoolAcquireContext.__await__.  s+    	yy!!$,,/99;;r.   )r   r   rp   r   )rp   r   r   r   r:   r`   )NNN)r  zOptional[Type[BaseException]]r  zOptional[BaseException]r  zOptional[TracebackType]r:   r`   )
r@   rA   rB   rC   ra   rP   r  r  r  rE   r=   r.   r,   rY  rY    sL    9I 37+/*.		%/	% )	% (		%
 
	%<r.   rY  
   iP  g     r@)r   r   rq   r   r   rr   r   r   r   r   r   c               2    [        U 4U
UUUUU	UUUUUS.UD6$ )at  Create a connection pool.

Can be used either with an ``async with`` block:

.. code-block:: python

    async with asyncpg.create_pool(user='postgres',
                                   command_timeout=60) as pool:
        await pool.fetch('SELECT 1')

Or to perform multiple operations on a single connection:

.. code-block:: python

    async with asyncpg.create_pool(user='postgres',
                                   command_timeout=60) as pool:
        async with pool.acquire() as con:
            await con.execute('''
               CREATE TABLE names (
                  id serial PRIMARY KEY,
                  name VARCHAR (255) NOT NULL)
            ''')
            await con.fetch('SELECT 1')

Or directly with ``await`` (not recommended):

.. code-block:: python

    pool = await asyncpg.create_pool(user='postgres', command_timeout=60)
    con = await pool.acquire()
    try:
        await con.fetch('SELECT 1')
    finally:
        await pool.release(con)

.. warning::
    Prepared statements and cursors returned by
    :meth:`Connection.prepare() <asyncpg.connection.Connection.prepare>`
    and :meth:`Connection.cursor() <asyncpg.connection.Connection.cursor>`
    become invalid once the connection is released.  Likewise, all
    notification and log listeners are removed, and ``asyncpg`` will
    issue a warning if there are any listener callbacks registered on a
    connection that is being released to the pool.

:param str dsn:
    Connection arguments specified using as a single string in
    the following format:
    ``postgres://user:pass@host:port/database?option=value``.

:param \*\*connect_kwargs:
    Keyword arguments for the :func:`~asyncpg.connection.connect`
    function.

:param Connection connection_class:
    The class to use for connections.  Must be a subclass of
    :class:`~asyncpg.connection.Connection`.

:param type record_class:
    If specified, the class to use for records returned by queries on
    the connections in this pool.  Must be a subclass of
    :class:`~asyncpg.Record`.

:param int min_size:
    Number of connection the pool will be initialized with.

:param int max_size:
    Max number of connections in the pool.

:param int max_queries:
    Number of queries after a connection is closed and replaced
    with a new connection.

:param float max_inactive_connection_lifetime:
    Number of seconds after which inactive connections in the
    pool will be closed.  Pass ``0`` to disable this mechanism.

:param coroutine connect:
    A coroutine that is called instead of
    :func:`~asyncpg.connection.connect` whenever the pool needs to make a
    new connection.  Must return an instance of type specified by
    *connection_class* or :class:`~asyncpg.connection.Connection` if
    *connection_class* was not specified.

:param coroutine setup:
    A coroutine to prepare a connection right before it is returned
    from :meth:`Pool.acquire()`.  An example use
    case would be to automatically set up notifications listeners for
    all connections of a pool.

:param coroutine init:
    A coroutine to initialize a connection when it is created.
    An example use case would be to setup type codecs with
    :meth:`Connection.set_builtin_type_codec() <\
    asyncpg.connection.Connection.set_builtin_type_codec>`
    or :meth:`Connection.set_type_codec() <\
    asyncpg.connection.Connection.set_type_codec>`.

:param coroutine reset:
    A coroutine to reset a connection before it is returned to the pool by
    :meth:`Pool.release()`.  The function is supposed
    to reset any changes made to the database session so that the next
    acquirer gets the connection in a well-defined state.

    The default implementation calls :meth:`Connection.reset() <\
    asyncpg.connection.Connection.reset>`, which runs the following::

        SELECT pg_advisory_unlock_all();
        CLOSE ALL;
        UNLISTEN *;
        RESET ALL;

    The exact reset query is determined by detected server capabilities,
    and a custom *reset* implementation can obtain the default query
    by calling :meth:`Connection.get_reset_query() <\
    asyncpg.connection.Connection.get_reset_query>`.

:param loop:
    An asyncio event loop instance.  If ``None``, the default
    event loop will be used.

:return: An instance of :class:`~asyncpg.pool.Pool`.

.. versionchanged:: 0.10.0
   An :exc:`~asyncpg.exceptions.InterfaceError` will be raised on any
   attempted operation on a released connection.

.. versionchanged:: 0.13.0
   An :exc:`~asyncpg.exceptions.InterfaceError` will be raised on any
   attempted operation on a prepared statement or a cursor created
   on a connection that has been released to the pool.

.. versionchanged:: 0.13.0
   An :exc:`~asyncpg.exceptions.InterfaceWarning` will be produced
   if there are any active listeners (added via
   :meth:`Connection.add_listener()
   <asyncpg.connection.Connection.add_listener>`
   or :meth:`Connection.add_log_listener()
   <asyncpg.connection.Connection.add_log_listener>`) present on the
   connection at the moment of its release to the pool.

.. versionchanged:: 0.22.0
   Added the *record_class* parameter.

.. versionchanged:: 0.30.0
   Added the *connect* and *reset* parameters.
)r   r   r   r   rq   r   r   rr   r   r   r   )r   )r  r   r   rq   r   r   rr   r   r   r   r   r   r   s                r,   create_poolr  3  sE    ~ )!)I  r.   rL   )#
__future__r   r   collections.abcr   r   r   r   loggingr   typesr   typingr   r   r	   r    r   r   r   r   	getLoggerr@   ro  r  r   _ConnectionProxyrH   r_   r   rY  r   r   r  r=   r.   r,   <module>r     s    #  /      & &      
		8	$/d /dO*55$;#ODV+ V+rG GT< <@m!16!+!6!6%__mr.   