
    ,h J                       S r SSKJr  SSKrSSK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	  SSKJ
r
  SS	KJr  SS
KJr  SSK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  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  \R                  (       a  SSK J!r!   " S S\5      r" " S S\"5      r# " S  S!\#5      r$ " S" S#\5      r% " S$ S%\5      r& " S& S'\5      r' " S( S)\5      r(g)*zPool implementation classes.

    )annotationsN)Any)cast)List)Optional)Set)Type)TYPE_CHECKING)Union   )_AsyncConnDialect)_ConnectionFairy_ConnectionRecord)_CreatorFnType)_CreatorWRecFnType)ConnectionPoolEntry)Pool)PoolProxiedConnection   )exc)util)chop_traceback)queue)Literal)DBAPIConnectionc                      \ rS rSr% SrSr\R                  rS\	S'   S\	S'       S           SS j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)"	QueuePool-   a  A :class:`_pool.Pool`
that imposes a limit on the number of open connections.

:class:`.QueuePool` is the default pooling implementation used for
all :class:`_engine.Engine` objects other than SQLite with a ``:memory:``
database.

The :class:`.QueuePool` class **is not compatible** with asyncio and
:func:`_asyncio.create_async_engine`.  The
:class:`.AsyncAdaptedQueuePool` class is used automatically when
using :func:`_asyncio.create_async_engine`, if no other kind of pool
is specified.

.. seealso::

    :class:`.AsyncAdaptedQueuePool`

F1Type[sqla_queue.QueueCommon[ConnectionPoolEntry]]_queue_classz+sqla_queue.QueueCommon[ConnectionPoolEntry]_poolc                    [         R                  " X40 UD6  U R                  X%S9U l        SU-
  U l        US:X  a  SOUU l        X@l        [        R                  " 5       U l	        g)a  
Construct a QueuePool.

:param creator: a callable function that returns a DB-API
  connection object, same as that of :paramref:`_pool.Pool.creator`.

:param pool_size: The size of the pool to be maintained,
  defaults to 5. This is the largest number of connections that
  will be kept persistently in the pool. Note that the pool
  begins with no connections; once this number of connections
  is requested, that number of connections will remain.
  ``pool_size`` can be set to 0 to indicate no size limit; to
  disable pooling, use a :class:`~sqlalchemy.pool.NullPool`
  instead.

:param max_overflow: The maximum overflow size of the
  pool. When the number of checked-out connections reaches the
  size set in pool_size, additional connections will be
  returned up to this limit. When those additional connections
  are returned to the pool, they are disconnected and
  discarded. It follows then that the total number of
  simultaneous connections the pool will allow is pool_size +
  `max_overflow`, and the total number of "sleeping"
  connections the pool will allow is pool_size. `max_overflow`
  can be set to -1 to indicate no overflow limit; no limit
  will be placed on the total number of concurrent
  connections. Defaults to 10.

:param timeout: The number of seconds to wait before giving up
  on returning a connection. Defaults to 30.0. This can be a float
  but is subject to the limitations of Python time functions which
  may not be reliable in the tens of milliseconds.

:param use_lifo: use LIFO (last-in-first-out) when retrieving
  connections instead of FIFO (first-in-first-out). Using LIFO, a
  server-side timeout scheme can reduce the number of connections used
  during non-peak periods of use.   When planning for server-side
  timeouts, ensure that a recycle or pre-ping strategy is in use to
  gracefully handle stale connections.

  .. versionadded:: 1.3

  .. seealso::

    :ref:`pool_use_lifo`

    :ref:`pool_disconnects`

:param \**kw: Other keyword arguments including
  :paramref:`_pool.Pool.recycle`, :paramref:`_pool.Pool.echo`,
  :paramref:`_pool.Pool.reset_on_return` and others are passed to the
  :class:`_pool.Pool` constructor.

)use_lifor   N)
r   __init__r!   r"   	_overflow_max_overflow_timeout	threadingLock_overflow_lock)selfcreator	pool_sizemax_overflowtimeoutr$   kws          L/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/pool/impl.pyr&   QueuePool.__init__I   sZ    @ 	d*r*&&y&D
Y#,>R|'nn.    c                     U R                   R                  US5        g ! [        R                   a9     UR	                  5         U R                  5          g ! U R                  5         f = ff = fNF)r"   put
sqla_queueFullclose_dec_overflowr-   records     r3   _do_return_connQueuePool._do_return_conn   sS    	%JJNN65) 	%%""$""$		%s     A,AA,A((A,c                   U R                   S:  nU=(       a    U R                  U R                   :  n U R                  R                  X R                  5      $ ! [
        R                   a     Of = fU(       ar  U R                  U R                   :  aX  U(       d  U R                  5       $ [        R                  " SU R                  5       U R                  5       U R                  4-  SS9eU R                  5       (       aV   U R                  5       $ !   [        R                  " 5          U R!                  5         S S S 5        e ! , (       d  f       e = f= fU R                  5       $ )Nr%   zSQueuePool limit of size %d overflow %d reached, connection timed out, timeout %0.2f3o7r)code)r(   r'   r"   getr)   r9   Empty_do_getr   TimeoutErrorsizeoverflow_inc_overflow_create_connectionr   safe_reraiser<   )r-   use_overflowwaits      r3   rF   QueuePool._do_get   s&   ))B.D$2D2D D	::>>$66 	 		
 DNNd.@.@@||~%&&:yy{DMMOT]]CD  	  ..00&&(&&( ) )(<<>!s5   $A A/.A/D E(E9	E
E	Ec                   U R                   S:X  a  U =R                  S-  sl        gU R                     U R                  U R                   :  a  U =R                  S-  sl         S S S 5        g S S S 5        g! , (       d  f       g = f)Nr%   r   TFr(   r'   r,   r-   s    r3   rJ   QueuePool._inc_overflow   sf    #NNaN  ~~ 2 22!# ! 
  !  s   1A7-A77
Bc                    U R                   S:X  a  U =R                  S-  sl        gU R                     U =R                  S-  sl         S S S 5        g! , (       d  f       g = f)Nr%   r   TrQ   rR   s    r3   r<   QueuePool._dec_overflow   sG    #NNaN  NNaN !  s   A
A!c                   U R                   R                  S5        U R                  U R                  U R                  R
                  U R                  U R                  U R                  R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S9$ )NPool recreating)r/   r0   pre_pingr$   r1   recycleechologging_namereset_on_return	_dispatchdialect)loggerinfo	__class___creatorr"   maxsizer(   	_pre_pingr$   r)   _recyclerZ   _orig_logging_name_reset_on_returndispatch_dialectrR   s    r3   recreateQueuePool.recreate   s    *+~~MMjj((++^^ZZ((MMMM00 11mmMM  
 	
r5   c                     U R                   R                  S5      nUR                  5         M.  ! [        R                   a     Of = fSU R                  5       -
  U l        U R                  R                  SU R                  5       5        g )NFr   zPool disposed. %s)
r"   rD   r;   r9   rE   rH   r'   r_   r`   statusr-   conns     r3   disposeQueuePool.dispose   sr    zz~~e,

  ##  TYY[,dkkm<s   +0 AAc                    SU R                  5       U R                  5       U R                  5       U R                  5       4-  $ )Nz_Pool size: %d  Connections in pool: %d Current Overflow: %d Current Checked out connections: %d)rH   	checkedinrI   
checkedoutrR   s    r3   rm   QueuePool.status   s>     		 !	
	
r5   c                .    U R                   R                  $ N)r"   rc   rR   s    r3   rH   QueuePool.size   s    zz!!!r5   c                    U R                   $ rw   )r)   rR   s    r3   r1   QueuePool.timeout   s    }}r5   c                6    U R                   R                  5       $ rw   )r"   qsizerR   s    r3   rs   QueuePool.checkedin   s    zz!!r5   c                T    U R                   R                  (       a  U R                  $ S$ )Nr   )r"   rc   r'   rR   s    r3   rI   QueuePool.overflow   s    !%!3!3t~~::r5   c                ~    U R                   R                  U R                   R                  5       -
  U R                  -   $ rw   )r"   rc   r|   r'   rR   s    r3   rt   QueuePool.checkedout  s-    zz!!DJJ$4$4$66GGr5   )r(   r'   r,   r"   r)   N)   
   g      >@F)r.   )Union[_CreatorFnType, _CreatorWRecFnType]r/   intr0   r   r1   floatr$   boolr2   r   r>   r   returnNoner   r   )r   r   )r   zLiteral[True])r   r   r   r   r   str)r   r   )r   r   )__name__
__module____qualname____firstlineno____doc___is_asyncior9   Queuer!   __annotations__r&   r?   rF   rJ   r<   rj   rp   rm   rH   r1   rs   rI   rt   __static_attributes__ r5   r3   r   r   -   s    & K 	 C  76
 E/:E/ E/ 	E/
 E/ E/ E/N%"@	
"	=
"";Hr5   r   c                  N    \ rS rSr% SrSr\R                  rS\	S'   \
" 5       rSrg)AsyncAdaptedQueuePooli  a  An asyncio-compatible version of :class:`.QueuePool`.

This pool is used by default when using :class:`.AsyncEngine` engines that
were generated from :func:`_asyncio.create_async_engine`.   It uses an
asyncio-compatible queue implementation that does not use
``threading.Lock``.

The arguments and operation of :class:`.AsyncAdaptedQueuePool` are
otherwise identical to that of :class:`.QueuePool`.

Tr    r!   r   N)r   r   r   r   r   r   r9   AsyncAdaptedQueuer!   r   r   ri   r   r   r5   r3   r   r     s.    
 K$$ C  !"Hr5   r   c                  ,    \ rS rSr\R
                  rSrg)FallbackAsyncAdaptedQueuePooli  r   N)r   r   r   r   r9   FallbackAsyncAdaptedQueuer!   r   r   r5   r3   r   r     s    77Lr5   r   c                  J    \ 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r
g	)NullPooli  a  A Pool which does not pool connections.

Instead it literally opens and closes the underlying DB-API connection
per each connection open/close.

Reconnect-related functions such as ``recycle`` and connection
invalidation are not supported by this Pool implementation, since
no connections are held persistently.

The :class:`.NullPool` class **is compatible** with asyncio and
:func:`_asyncio.create_async_engine`.

c                    g)Nr   r   rR   s    r3   rm   NullPool.status-  s    r5   c                $    UR                  5         g rw   )r;   r=   s     r3   r?   NullPool._do_return_conn0  s    r5   c                "    U R                  5       $ rw   )rK   rR   s    r3   rF   NullPool._do_get3  s    &&((r5   c                   U R                   R                  S5        U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  S9$ )NrW   )rY   rZ   r[   r\   rX   r]   r^   )r_   r`   ra   rb   re   rZ   rf   rg   rd   rh   ri   rR   s    r3   rj   NullPool.recreate6  sg    *+~~MMMM00 11^^mmMM  	
 		
r5   c                    g rw   r   rR   s    r3   rp   NullPool.disposeD      r5   r   Nr   r   r   )r   r   r   )r   r   r   r   r   rm   r?   rF   rj   rp   r   r   r5   r3   r   r     s     )
r5   r   c                  |    \ rS rSrSrSr S     SS j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)SingletonThreadPooliH  a  A Pool that maintains one connection per thread.

Maintains one connection per each thread, never moving a connection to a
thread other than the one which it was created in.

.. warning::  the :class:`.SingletonThreadPool` will call ``.close()``
   on arbitrary connections that exist beyond the size setting of
   ``pool_size``, e.g. if more unique **thread identities**
   than what ``pool_size`` states are used.   This cleanup is
   non-deterministic and not sensitive to whether or not the connections
   linked to those thread identities are currently in use.

   :class:`.SingletonThreadPool` may be improved in a future release,
   however in its current status it is generally used only for test
   scenarios using a SQLite ``:memory:`` database and is not recommended
   for production use.

The :class:`.SingletonThreadPool` class **is not compatible** with asyncio
and :func:`_asyncio.create_async_engine`.


Options are the same as those of :class:`_pool.Pool`, as well as:

:param pool_size: The number of threads in which to maintain connections
    at once.  Defaults to five.

:class:`.SingletonThreadPool` is used by the SQLite dialect
automatically when a memory-based database is used.
See :ref:`sqlite_toplevel`.

Fc                    [         R                  " X40 UD6  [        R                  " 5       U l        [        R                  " 5       U l        [        5       U l        X l        g rw   )	r   r&   r*   local_conn_fairyset
_all_connsrH   )r-   r.   r/   r2   s       r3   r&   SingletonThreadPool.__init__k  s?     	d*r*__&
oo'47E	r5   c                   U R                   R                  S5        U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  S9	$ )NrW   )r/   rY   rZ   rX   r[   r\   r]   r^   )r_   r`   ra   rb   rH   re   rZ   rd   rf   rg   rh   ri   rR   s    r3   rj   SingletonThreadPool.recreatew  sn    *+~~MMiiMM^^00 11mmMM  

 
	
r5   c                    U R                    H  n UR                  5         M     U R                   R                  5         g! [         a     M@  f = f)zDispose of this pool.N)r   r;   	Exceptionclearrn   s     r3   rp   SingletonThreadPool.dispose  sH     OOD

 $ 	   s   A  
AAc                    [        U R                  5      U R                  :  aP  U R                  R                  5       nUR	                  5         [        U R                  5      U R                  :  a  MO  g g rw   )lenr   rH   popr;   r-   cs     r3   _cleanupSingletonThreadPool._cleanup  sI    $//"dii/##%AGGI $//"dii/r5   c                H    S[        U 5      [        U R                  5      4-  $ )Nz"SingletonThreadPool id:%d size: %d)idr   r   rR   s    r3   rm   SingletonThreadPool.status  s'    3tH 7
 
 	
r5   c                >     U R                   ?g ! [         a     g f = frw   )r   currentAttributeErrorr=   s     r3   r?   #SingletonThreadPool._do_return_conn  s#    	# 		s    
c                    [         (       a)  [        [        U R                  R	                  5       5      nOU R                  R	                  5       nU(       a  U$  U R                  5       n[        R                  " U5      U R                  l        [        U R                  5      U R                  :  a  U R                  5         U R                  R                  U5        U$ ! [
         a     Nf = frw   )r
   r   r   r   r   r   rK   weakrefrefr   r   rH   r   addr   s     r3   rF   SingletonThreadPool._do_get  s    	},djj.@.@.BCJJ&&(  ##%$[[^

t499,MMOA  		s   AC 
C,+C,c                     [        [        U R                  R                  5       5      nUb  UR	                  5       $  [        R                  " X R                  5      $ ! [
         a     N,f = frw   )r   r   r   r   _checkout_existingr   	_checkoutr-   recs     r3   connectSingletonThreadPool.connect  sg    	0')<)<)>?C --//   ))$<<  		s   (A 
A+*A+)r   r   r   rH   N)r   )r.   r   r/   r   r2   r   )r   r   r   r   r   r   )r   r   )r   r   r   r   r   r   r&   rj   rp   r   rm   r?   rF   r   r   r   r5   r3   r   r   H  sX    @ K
 
:
 
 	

 

"=r5   r   c                      \ rS rSrSr\R                  SS j5       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)
StaticPooli  af  A Pool of exactly one connection, used for all requests.

Reconnect-related functions such as ``recycle`` and connection
invalidation (which is also used to support auto-reconnect) are only
partially supported right now and may not yield good results.

The :class:`.StaticPool` class **is compatible** with asyncio and
:func:`_asyncio.create_async_engine`.

c                    [        U 5      $ rw   r   rR   s    r3   
connectionStaticPool.connection  s     &&r5   c                    g)Nr   r   rR   s    r3   rm   StaticPool.status  s    r5   c                    SU R                   ;   a@  U R                  R                  b(  U R                  R                  5         U R                   S	 g g g Nr   )__dict__r   dbapi_connectionr;   rR   s    r3   rp   StaticPool.dispose  sD    DMM)00<OO!!#l+ = *r5   c                   U R                   R                  S5        U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  S9$ )NrW   )r.   rY   r\   rX   rZ   r[   r]   r^   )r_   r`   ra   rb   re   rg   rd   rZ   rf   rh   ri   rR   s    r3   rj   StaticPool.recreate  sg    *+~~MMMM 11^^00mmMM  	
 		
r5   c                "   ^ SU4S jjnX l         g )Nc                >   > TR                   R                  nUc   eU$ rw   )r   r   )r   ro   other_static_pools     r3   r.   *StaticPool._transfer_from.<locals>.creator  s%    $//@@D###Kr5   )r   r   r   r   _invoke_creator)r-   r   r.   s    ` r3   _transfer_fromStaticPool._transfer_from  s    	
  'r5   c                    [        5       erw   )NotImplementedErrorrR   s    r3   rK   StaticPool._create_connection  s    !##r5   c                    g rw   r   r=   s     r3   r?   StaticPool._do_return_conn  r   r5   c                z    U R                   nUR                  5       (       a  U R                  S	 U R                   nU$ r   )r   _is_hard_or_soft_invalidatedr   r   s     r3   rF   StaticPool._do_get  s4    oo++--l+//C
r5   r   N)r   r   r   r   )r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   memoized_propertyr   rm   rp   rj   r   rK   r?   rF   r   r   r5   r3   r   r     sD    	 
' ',
'$r5   r   c                  j    \ rS rSr% SrS\S'   S\S'   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)AssertionPooli  aa  A :class:`_pool.Pool` that allows at most one checked out connection at
any given time.

This will raise an exception if more than one connection is checked out
at a time.  Useful for debugging code that is using more connections
than desired.

The :class:`.AssertionPool` class **is compatible** with asyncio and
:func:`_asyncio.create_async_engine`.

zOptional[ConnectionPoolEntry]r   zOptional[List[str]]_checkout_tracebackc                    S U l         SU l        UR                  SS5      U l        S U l        [
        R                  " U /UQ70 UD6  g )NFstore_tracebackT)r   _checked_outr   _store_tracebackr   r   r&   )r-   argsr2   s      r3   r&   AssertionPool.__init__  sC    
! "'8$ ?#' d(T(R(r5   c                    g)Nr   r   rR   s    r3   rm   AssertionPool.status  s    r5   c                j    U R                   (       d  [        S5      eSU l         XR                  L d   eg )Nzconnection is not checked outF)r   AssertionErrorr   r=   s     r3   r?   AssertionPool._do_return_conn  s/       !@AA!###r5   c                j    SU l         U R                  (       a  U R                  R                  5         g g r7   )r   r   r;   rR   s    r3   rp   AssertionPool.dispose#  s&    !::JJ r5   c                   U R                   R                  S5        U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  S9$ )NrW   )rZ   rX   rY   r\   r[   r]   r^   )r_   r`   ra   rb   rZ   rd   re   rg   rf   rh   ri   rR   s    r3   rj   AssertionPool.recreate(  sg    *+~~MM^^MM 1100mmMM  	
 		
r5   c                ~   U R                   (       aI  U R                  (       a(  SSR                  [        U R                  5      5      -  nOSn[	        SU-   5      eU R
                  (       d  U R                  5       U l        SU l         U R                  (       a  [        R                  " 5       U l        U R
                  $ )Nz at:
%s z!connection is already checked outT)
r   r   joinr   r   r   rK   r   	tracebackformat_stack)r-   suffixs     r3   rF   AssertionPool._do_get5  s    ''#bgg"4#;#;<'   !Dv!MNNzz002DJ   '0'='='?D$zzr5   )r   r   r   r   N)r   r   r2   r   r   r   r   )r   r   r   )r   r   r   r   r   r   r&   rm   r?   rp   rj   rF   r   r   r5   r3   r   r     s3    
 )(,,)$

r5   r   ))r   
__future__r   r*   r	  typingr   r   r   r   r   r	   r
   r   r   baser   r   r   r   r   r   r   r   r  r   r   r   r   r9   util.typingr   engine.interfacesr   r   r   r   r   r   r   r   r   r5   r3   <module>r     s    #              # " #   $ %  '   ! & !	3UH UHp#I #*8$9 8't 'Tw=$ w=t> >BBD Br5   