
    ,hl                    J   % S r SSKJr  SSKJr  SSK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
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  \(       a*  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&  \RN                  " SS9 " S  S!5      5       r( " S" S#\5      r)\\)\S$   4   r*\+" \)5      u  r,r-r. " S% S&5      r/ " S' S(\/5      r0 " S) S*\5      r1 " S+ S,\5      r2 " S- S.\Rf                  \Rh                  5      r5 " S/ S05      r6 " S1 S2\65      r7 " S3 S4\75      r8  S>               S?S5 jjr90 r:S6\;S7'    " S8 S9\65      r< " S: S;\<5      r= " S< S=\<5      r>g)@z'Base constructs for connection pools.

    )annotations)dequeN)Enum)Any)Callable)cast)Deque)Dict)List)Optional)Tuple)TYPE_CHECKING)Union   )event)exc)log)util)Literal)Protocol)DBAPIConnection)DBAPICursor)Dialect)_DispatchCommon)_ListenerFnType)
dispatcher)	_InfoTypeT)frozenc                  @    \ rS rSr% SrSrS\S'    S\S'    S\S'   Srg	)
PoolResetState2   zdescribes the state of a DBAPI connection as it is being passed to
the :meth:`.PoolEvents.reset` connection pool event.

.. versionadded:: 2.0.0b3

transaction_was_resetterminate_onlyasyncio_safeboolr#   r$   r%    N)__name__
__module____qualname____firstlineno____doc__	__slots____annotations____static_attributes__r'       L/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/pool/base.pyr    r    2   s4     LI
 	 r0   r    c                  $    \ rS rSrSrSrSrSrSrg)
ResetStyle_   z1Describe options for "reset on return" behaviors.r      r   r'   N)	r(   r)   r*   r+   r,   reset_rollbackreset_commit
reset_noner/   r'   r0   r1   r3   r3   _   s    ;NLJr0   r3   )TNFcommitrollbackc                  \    \ rS rS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
rg)_ConnDialectn   zpartial implementation of :class:`.Dialect`
which provides DBAPI connection methods.

When a :class:`_pool.Pool` is combined with an :class:`_engine.Engine`,
the :class:`_engine.Engine` replaces this with its own
:class:`.Dialect`.

Fc                $    UR                  5         g N)r:   selfdbapi_connections     r1   do_rollback_ConnDialect.do_rollback{   s    !!#r0   c                $    UR                  5         g r?   )r9   r@   s     r1   	do_commit_ConnDialect.do_commit~   s    !r0   c                $    UR                  5         g r?   closer@   s     r1   do_terminate_ConnDialect.do_terminate        r0   c                $    UR                  5         g r?   rI   r@   s     r1   do_close_ConnDialect.do_close   rM   r0   c                    [        S5      e)NzJThe ping feature requires that a dialect is passed to the connection pool.NotImplementedErrorr@   s     r1   _do_ping_w_event_ConnDialect._do_ping_w_event   s    !-
 	
r0   c                    U$ r?   r'   )rA   
connections     r1   get_driver_connection"_ConnDialect.get_driver_connection   s    r0   r'   N)rB   PoolProxiedConnectionreturnNone)rB   r   r[   r\   )rB   r   r[   r&   )rW   r   r[   r   )r(   r)   r*   r+   r,   is_asynchas_terminaterC   rF   rK   rO   rT   rX   r/   r'   r0   r1   r<   r<   n   s1     HM$"!!
r0   r<   c                      \ rS rSrSrSrg)_AsyncConnDialect   Tr'   N)r(   r)   r*   r+   r]   r/   r'   r0   r1   r`   r`      s    Hr0   r`   c                      \ rS rSrSS jrSrg)_CreatorFnType   c                    g r?   r'   rA   s    r1   __call___CreatorFnType.__call__   s    3r0   r'   Nr[   r   r(   r)   r*   r+   rg   r/   r'   r0   r1   rc   rc      s    .r0   rc   c                      \ rS rSrSS jrSrg)_CreatorWRecFnType   c                    g r?   r'   rA   recs     r1   rg   _CreatorWRecFnType.__call__   s    Sr0   r'   N)rp   ConnectionPoolEntryr[   r   rj   r'   r0   r1   rl   rl      s    Hr0   rl   c                     \ rS rSr% SrS\S'   S\S'   S\S'   \" 5       rS	\S
'   S\S'   S\S'   S\S'           S%                 S&S jjr\	R                  S'S j5       r\S(S j5       r\R                      S)S j5       r\R                  S*S j5       r    S+S jrSS.     S,S jjrS-S jr  S.       S/S jjrS0S jrS*S jrS1S jrS2S  jrS-S! jrS2S" jrS3S# jrS$rg)4Pool   z)Abstract base class for connection pools.zdispatcher[Pool]dispatchlog._EchoFlagTypeechoOptional[str]_orig_logging_namezUnion[_ConnDialect, Dialect]_dialect)Union[_CreatorFnType, _CreatorWRecFnType]_creator_argrl   _invoke_creatorfloat_invalidate_timeNFc
           	        U(       a  U=U l         U l        OSU l        [        R                  " XS9  Xl        X l        SU l        Xl        [        R                  " U[        R                  SS/[        R                  / SQ[        R                  S/0S5      U l        X0l        U	(       a  U R                   R#                  U	S	S
9  U(       a  Xpl        U(       a#  U H  u  p[&        R(                  " XU
5        M     gg)a  
Construct a Pool.

:param creator: a callable function that returns a DB-API
  connection object.  The function will be called with
  parameters.

:param recycle: If set to a value other than -1, number of
  seconds between connection recycling, which means upon
  checkout, if this timeout is surpassed the connection will be
  closed and replaced with a newly opened connection. Defaults to -1.

:param logging_name:  String identifier which will be used within
  the "name" field of logging records generated within the
  "sqlalchemy.pool" logger. Defaults to a hexstring of the object's
  id.

:param echo: if True, the connection pool will log
 informational output such as when connections are invalidated
 as well as when connections are recycled to the default log handler,
 which defaults to ``sys.stdout`` for output..   If set to the string
 ``"debug"``, the logging will include pool checkouts and checkins.

 The :paramref:`_pool.Pool.echo` parameter can also be set from the
 :func:`_sa.create_engine` call by using the
 :paramref:`_sa.create_engine.echo_pool` parameter.

 .. seealso::

     :ref:`dbengine_logging` - further detail on how to configure
     logging.

:param reset_on_return: Determine steps to take on
 connections as they are returned to the pool, which were
 not otherwise handled by a :class:`_engine.Connection`.
 Available from :func:`_sa.create_engine` via the
 :paramref:`_sa.create_engine.pool_reset_on_return` parameter.

 :paramref:`_pool.Pool.reset_on_return` can have any of these values:

 * ``"rollback"`` - call rollback() on the connection,
   to release locks and transaction resources.
   This is the default value.  The vast majority
   of use cases should leave this value set.
 * ``"commit"`` - call commit() on the connection,
   to release locks and transaction resources.
   A commit here may be desirable for databases that
   cache query plans if a commit is emitted,
   such as Microsoft SQL Server.  However, this
   value is more dangerous than 'rollback' because
   any data changes present on the transaction
   are committed unconditionally.
 * ``None`` - don't do anything on the connection.
   This setting may be appropriate if the database / DBAPI
   works in pure "autocommit" mode at all times, or if
   a custom reset handler is established using the
   :meth:`.PoolEvents.reset` event handler.

 * ``True`` - same as 'rollback', this is here for
   backwards compatibility.
 * ``False`` - same as None, this is here for
   backwards compatibility.

 For further customization of reset on return, the
 :meth:`.PoolEvents.reset` event hook may be used which can perform
 any connection activity desired on reset.

 .. seealso::

    :ref:`pool_reset_on_return`

    :meth:`.PoolEvents.reset`

:param events: a list of 2-tuples, each of the form
 ``(callable, target)`` which will be passed to :func:`.event.listen`
 upon construction.   Provided here so that event listeners
 can be assigned via :func:`_sa.create_engine` before dialect-level
 listeners are applied.

:param dialect: a :class:`.Dialect` that will handle the job
 of calling rollback(), close(), or commit() on DBAPI connections.
 If omitted, a built-in "stub" dialect is used.   Applications that
 make use of :func:`_sa.create_engine` should not use this parameter
 as it is handled by the engine creation strategy.

:param pre_ping: if True, the pool will emit a "ping" (typically
 "SELECT 1", but is dialect-specific) on the connection
 upon checkout, to test if the connection is alive or not.   If not,
 the connection is transparently re-connected and upon success, all
 other pooled connections established prior to that timestamp are
 invalidated.     Requires that a dialect is passed as well to
 interpret the disconnection error.

 .. versionadded:: 1.2

N)echoflagr   r:   T)noneNFr9   reset_on_returnF)only_propagate)logging_namerz   r   instance_logger_creator_recycler   	_pre_pingr   parse_user_argument_for_enumr3   r6   r8   r7   _reset_on_returnrx   rv   _updater{   r   listen)rA   creatorrecyclerx   r   r   eventsdialectpre_ping	_dispatchfntargets               r1   __init__Pool.__init__   s    X :FFD 7&*D#D0 !! $ A A))J+=%%'<''(
 !
 	MM!!)E!B#M$
T2. % r0   c                .    U R                   R                  $ r?   )r{   r]   rf   s    r1   _is_asyncioPool._is_asyncio3  s    }}%%%r0   c                    U R                   $ r?   )r}   rf   s    r1   r   Pool._creator7  s       r0   c                <    Xl         U R                  U5      U l        g r?   )r}   _should_wrap_creatorr~   )rA   r   s     r1   r   r   ;  s     $  $88Ar0   c                    U ? U ?g r?   )r}   r~   rf   s    r1   r   r   E  s      r0   c                  ^  [         R                  " U R                  SS9nUR                  b  [        UR                  5      nOSn[        US   5      U-
  nUS   US   4S/S4:X  a  [	        [        U5      $ US:X  a  [	        [        U5      $ [	        [
        U5      mU4S	 j$ ! [         a    [	        [
        U5      mU4S js $ f = f)
z\Detect if creator accepts a single argument, or is sent
as a legacy style no-arg function.

T)no_selfc                   > T" 5       $ r?   r'   rp   
creator_fns    r1   <lambda>+Pool._should_wrap_creator.<locals>.<lambda>W      z|r0   r      connection_recordr?   r5   c                   > T" 5       $ r?   r'   r   s    r1   r   r   j  r   r0   )	r   get_callable_argspecr   	TypeErrorr   rc   defaultslenrl   )rA   r   argspec	defaultedpositionalsr   s        @r1   r   Pool._should_wrap_creatorK  s    	,//tLG
 'G,,-II'!*o	1 AJ
#)<(=w'GG*G44A*G44 ng6J+++  	,ng6J++	,s   B% % CC	terminatec               x   U R                   R                  SU(       a  SOSU5         U(       a  U R                  R                  U5        g U R                  R	                  U5        g ! [
         aH  nU R                   R                  SU(       a  SOS S3USS	9  [        U[        5      (       d  e  S nAg S nAff = f)
Nz%s connection %rzHard-closingClosingz
Exception terminatingclosingz connection %rTexc_info)	loggerdebugr{   rK   rO   BaseExceptionerror
isinstance	Exception)rA   rW   r   es       r1   _close_connectionPool._close_connectionl  s     	'NY	

	**:6&&z2 	KKi]YG H  !	   a++ ,	s   "A' A' '
B91>B44B9c                    [        U 5      $ )z6Called by subclasses to create a new ConnectionRecord.)_ConnectionRecordrf   s    r1   _create_connectionPool._create_connection  s     !&&r0   c                    [        USS5      nU(       a  U R                  UR                  :  a  [        R                  " 5       U l        U(       a%  [        USS5      (       a  UR	                  U5        ggg)ab  Mark all connections established within the generation
of the given connection as invalidated.

If this pool's last invalidate time is before when the given
connection was created, update the timestamp til now.  Otherwise,
no action is performed.

Connections with a start time prior to this pool's invalidation
time will be recycled upon next checkout.
_connection_recordNis_validF)getattrr   	starttimetime
invalidate)rA   rW   	exception_checkinrp   s        r1   _invalidatePool._invalidate  s[      j"6=d++cmm;$(IIKD!
J>>!!), ?8r0   c                    [        5       e)zReturn a new :class:`_pool.Pool`, of the same class as this one
and configured with identical creation arguments.

This method is used in conjunction with :meth:`dispose`
to close out an entire :class:`_pool.Pool` and create a new one in
its place.

rR   rf   s    r1   recreatePool.recreate  s     "##r0   c                    [        5       e)zDispose of this pool.

This method leaves the possibility of checked-out connections
remaining open, as it only affects connections that are
idle in the pool.

.. seealso::

    :meth:`Pool.recreate`

rR   rf   s    r1   disposePool.dispose       "##r0   c                ,    [         R                  U 5      $ )zReturn a DBAPI connection from the pool.

The connection is instrumented such that when its
``close()`` method is called, the connection will be returned to
the pool.

)_ConnectionFairy	_checkoutrf   s    r1   connectPool.connect  s      ))$//r0   c                &    U R                  U5        g)zGiven a _ConnectionRecord, return it to the :class:`_pool.Pool`.

This method is called when an instrumented DBAPI connection
has its ``close()`` method called.

N)_do_return_connrA   records     r1   _return_connPool._return_conn  s     	V$r0   c                    [        5       e)z7Implementation for :meth:`get`, supplied by subclasses.rR   rf   s    r1   _do_getPool._do_get       "##r0   c                    [        5       e)z?Implementation for :meth:`return_conn`, supplied by subclasses.rR   r   s     r1   r   Pool._do_return_conn  r   r0   c                    [        5       e)z6Returns a brief description of the state of this pool.rR   rf   s    r1   statusPool.status      !##r0   )r   r}   r{   r   r~   rz   r   r   r   rx   r   )NNTNNFN)r   r|   r   intrx   rw   r   ry   r   _ResetStyleArgTyper   z+Optional[List[Tuple[_ListenerFnType, str]]]r   z&Optional[Union[_ConnDialect, Dialect]]r   r&   r   zOptional[_DispatchCommon[Pool]]r[   r&   )r[   r|   )r   r|   r[   r\   r[   r\   )r   r|   r[   rl   )rW   r   r   r&   r[   r\   )r[   rr   NT)rW   rZ   r   Optional[BaseException]r   r&   r[   r\   )r[   rt   )r[   rZ   )r   rr   r[   r\   )r[   str)r(   r)   r*   r+   r,   r.   r<   r{   r   r   hybridpropertyr   propertyr   setterdeleterr   r   r   r   r   r   r   r   r   r   r   r/   r'   r0   r1   rt   rt      s   3
%%-9^H*;;;''
 "&&*.2>B:>59H/:H/ H/  	H/
 $H/ ,H/ <H/ 8H/ H/ 3H/T 
& & ! ! __B@B	B B ! !
,@,	,D AF)9=	.' .2	-)- +- 	-
 
-,
$$0%$
$
$r0   rt   c                      \ rS rSr% SrSrS\S'    S\S'    \R                  SS j5       r	\R                  SS	 j5       r
 S     SS jjrSrg
)ManagesConnectioni  a  Common base for the two connection-management interfaces
:class:`.PoolProxiedConnection` and :class:`.ConnectionPoolEntry`.

These two objects are typically exposed in the public facing API
via the connection pool event hooks, documented at :class:`.PoolEvents`.

.. versionadded:: 2.0

r'   Optional[DBAPIConnection]rB   Optional[Any]driver_connectionc                    [        5       e)a   Info dictionary associated with the underlying DBAPI connection
referred to by this :class:`.ManagesConnection` instance, allowing
user-defined data to be associated with the connection.

The data in this dictionary is persistent for the lifespan
of the DBAPI connection itself, including across pool checkins
and checkouts.  When the connection is invalidated
and replaced with a new one, this dictionary is cleared.

For a :class:`.PoolProxiedConnection` instance that's not associated
with a :class:`.ConnectionPoolEntry`, such as if it were detached, the
attribute returns a dictionary that is local to that
:class:`.ConnectionPoolEntry`. Therefore the
:attr:`.ManagesConnection.info` attribute will always provide a Python
dictionary.

.. seealso::

    :attr:`.ManagesConnection.record_info`


rR   rf   s    r1   infoManagesConnection.info  s    0 "##r0   c                    [        5       e)a  Persistent info dictionary associated with this
:class:`.ManagesConnection`.

Unlike the :attr:`.ManagesConnection.info` dictionary, the lifespan
of this dictionary is that of the :class:`.ConnectionPoolEntry`
which owns it; therefore this dictionary will persist across
reconnects and connection invalidation for a particular entry
in the connection pool.

For a :class:`.PoolProxiedConnection` instance that's not associated
with a :class:`.ConnectionPoolEntry`, such as if it were detached, the
attribute returns None. Contrast to the :attr:`.ManagesConnection.info`
dictionary which is never None.


.. seealso::

    :attr:`.ManagesConnection.info`

rR   rf   s    r1   record_infoManagesConnection.record_info,  s    , "##r0   Nc                    [        5       e)a  Mark the managed connection as invalidated.

:param e: an exception object indicating a reason for the invalidation.

:param soft: if True, the connection isn't closed; instead, this
 connection will be recycled on next checkout.

.. seealso::

    :ref:`pool_connection_invalidation`


rR   rA   r   softs      r1   r   ManagesConnection.invalidateD  s      "##r0   r[   r   r[   zOptional[_InfoType]NFr   r   r	  r&   r[   r\   )r(   r)   r*   r+   r,   r-   r.   r   ro_memoized_propertyr  r  r   r/   r'   r0   r1   r   r     s     I//( %$( 
$ $2 
$ $0 ?D$($7;$	$ $r0   r   c                  :    \ rS rSrSrSr\SS j5       rSS jrSr	g)	rr   iW  a  Interface for the object that maintains an individual database
connection on behalf of a :class:`_pool.Pool` instance.

The :class:`.ConnectionPoolEntry` object represents the long term
maintainance of a particular connection for a pool, including expiring or
invalidating that connection to have it replaced with a new one, which will
continue to be maintained by that same :class:`.ConnectionPoolEntry`
instance. Compared to :class:`.PoolProxiedConnection`, which is the
short-term, per-checkout connection manager, this object lasts for the
lifespan of a particular "slot" within a connection pool.

The :class:`.ConnectionPoolEntry` object is mostly visible to public-facing
API code when it is delivered to connection pool event hooks, such as
:meth:`_events.PoolEvents.connect` and :meth:`_events.PoolEvents.checkout`.

.. versionadded:: 2.0  :class:`.ConnectionPoolEntry` provides the public
   facing interface for the :class:`._ConnectionRecord` internal class.

r'   c                    [        5       e)z3Return True the connection is currently checked outrR   rf   s    r1   in_useConnectionPoolEntry.in_usen  s     "##r0   c                    [        5       e)zAClose the DBAPI connection managed by this connection pool entry.rR   rf   s    r1   rJ   ConnectionPoolEntry.closet  r   r0   Nr   r   )
r(   r)   r*   r+   r,   r-   r   r  rJ   r/   r'   r0   r1   rr   rr   W  s%    ( I$ $
$r0   rr   c                     \ rS rSr% SrSrS\S'   S\S'   S\S	'   S
\S'   S&S'S jjrS\S'   \S(S j5       r	\\
R                  " SS5      S)S j5       5       rSrS
\S'   \
R                  S*S j5       r\
R                  S+S j5       r\S,S j5       r S&     S-S jjrS&S.S jjr\S/S j5       r\S0S j5       rS1S jr S2     S3S jjrS4S  jrS/S! jrSS".S5S# jjrS1S$ jrS%rg)6r   iy  a  Maintains a position in a connection pool which references a pooled
connection.

This is an internal object used by the :class:`_pool.Pool` implementation
to provide context management to a DBAPI connection maintained by
that :class:`_pool.Pool`.   The public facing interface for this class
is described by the :class:`.ConnectionPoolEntry` class.  See that
class for public API details.

.. seealso::

    :class:`.ConnectionPoolEntry`

    :class:`.PoolProxiedConnection`

)__pool	fairy_reffinalize_callbackfreshr   rB   __weakref____dict__z(Deque[Callable[[DBAPIConnection], None]]r  r&   r  'Optional[weakref.ref[_ConnectionFairy]]r  r   r   c                    SU l         S U l        SU l        S U l        Xl        U(       a  U R                  5         [        5       U l        g )NFr   )r  r  r   rB   _ConnectionRecord__pool_ConnectionRecord__connectr   r  )rA   poolr   s      r1   r   _ConnectionRecord.__init__  s;    
 $NN!&r0   r   rB   c                |    U R                   c  g U R                  R                  R                  U R                   5      $ r?   )rB   r  r{   rX   rf   s    r1   r   #_ConnectionRecord.driver_connection  s7      (;;''==%% r0   2.0zXThe _ConnectionRecord.connection attribute is deprecated; please use 'driver_connection'c                    U R                   $ r?   rB   rf   s    r1   rW   _ConnectionRecord.connection       $$$r0   r   _soft_invalidate_timec                    0 $ r?   r'   rf   s    r1   r  _ConnectionRecord.info      	r0   c                    0 $ r?   r'   rf   s    r1   r  _ConnectionRecord.record_info  r-  r0   c                "  ^^^ [         (       a  [        [        TR                  5       5      mOTR                  5       m TR	                  5       nTR                  5       m[        TUTT5      n[        R                  " UUUU4S j5      =Tl        nT[        U'   T(       a  TR                  R!                  SU5        U$ ! [
         aE  n[        R                  " 5          TR                  USS9  S S S 5        e ! , (       d  f       e = fS nAff = f)NF_fairy_was_createdc           	     2   > [         b  [        S TTU TSS9$ S $ )NFr#   )_finalize_fairy)refrx   r!  rp   s    r1   r   ,_ConnectionRecord.checkout.<locals>.<lambda>  s1     #.  #tS$e  	r0   z#Connection %r checked out from pool)r   r   r   r   get_connectionr   r   safe_reraise_checkin_failed_should_log_debugr   weakrefr6  r  _strong_ref_connection_recordsr   r   )clsr!  rB   errfairyr6  rx   rp   s    `    @@r1   checkout_ConnectionRecord.checkout  s    =($,,.9C,,.C	"113 %%' '7dC%kk	
 		
 /2&s+KK57G 3  	""$##CE#B % 	 %$ 	s/   B? ?
D	D	C8/	D	8
D	D		Dc                @    U R                  US9  U R                  US9  g )Nr   r1  )r   checkin)rA   r?  r2  s      r1   r:  !_ConnectionRecord._checkin_failed  s&     	#1 	 	
r0   c                   U R                   c!  U(       a  [        R                  " SU -  5        g S U l         U R                  nU R                  nU R
                  (       a8  U R
                  R                  5       nUb  U" U5        U R
                  (       a  M8  UR                  R                  (       a  UR                  R                  X 5        UR                  U 5        g )NzDouble checkin attempted on %s)
r  r   warnrB   r  r  poprv   rE  r   )rA   r2  rW   r!  	finalizers        r1   rE  _ConnectionRecord.checkin  s    >>!&8 II6=>**
{{$$..224I%*% $$$ ==  MM!!*3$r0   c                    U R                   S L$ r?   )r  rf   s    r1   r  _ConnectionRecord.in_use  s    ~~T))r0   c                    U R                   $ r?   )r   rf   s    r1   last_connect_time#_ConnectionRecord.last_connect_time  s    ~~r0   c                @    U R                   b  U R                  5         g g r?   )rB   _ConnectionRecord__closerf   s    r1   rJ   _ConnectionRecord.close  s      ,LLN -r0   NFc                |   U R                   c  g U(       a1  U R                  R                  R                  U R                   X5        O0U R                  R                  R	                  U R                   X5        UbQ  U R                  R
                  R                  SU(       a  SOSU R                   UR                  R                  U5        O:U R                  R
                  R                  SU(       a  SOSU R                   5        U(       a  [        R                  " 5       U l
        g U R                  SS9  S U l         g )Nz*%sInvalidate connection %r (reason: %s:%s)zSoft  z%sInvalidate connection %rTr   )rB   r  rv   soft_invalidater   r   r  	__class__r(   r   r*  rR  r  s      r1   r   _ConnectionRecord.invalidate  s       (KK  00%%t KK  ++D,A,A4K=KK##<R%%$$ KK##,R%% )-D&LL4L($(D!r0   c                   SnU R                   c,  U R                  R                  5         U R                  5         GO*U R                  R
                  S:  am  [        R                  " 5       U R                  -
  U R                  R
                  :  a3  U R                  R                  R                  SU R                   5        SnOU R                  R                  U R                  :  a3  U R                  R                  R                  SU R                   5        SnOLU R                  U R                  :  a2  U R                  R                  R                  SU R                   5        SnU(       a9  U R                  SS9  U R                  R                  5         U R                  5         U R                   c   eU R                   $ )NFr   z)Connection %r exceeded timeout; recyclingTz=Connection %r invalidated due to pool invalidation; recyclingzCConnection %r invalidated due to local soft invalidation; recyclingr   )rB   r  clearr   r  r   r   r   r   r   r*  rR  )rA   r   s     r1   r8   _ConnectionRecord.get_connection4  sT      (IIOONNKK  2%		dnn,t{{/C/CCKK##;%% G[[))DNN:KK##%%
 G''$..8KK##%%
 GLL4L(IIOONN$$000$$$r0   c                    U R                   S L =(       dC    U R                  R                  U R                  :  =(       d    U R                  U R                  :  $ r?   )rB   r  r   r   r*  rf   s    r1   _is_hard_or_soft_invalidated._ConnectionRecord._is_hard_or_soft_invalidatedh  sG    !!T) ={{++dnn<=**T^^;	
r0   r   c               V   U R                   R                  5         U R                  R                  R                  (       a0  U R                  R                  R	                  U R
                  U 5        U R
                  c   eU R                  R                  U R
                  US9  S U l        g )Nr   )r  rZ  r  rv   rJ   rB   r   )rA   r   s     r1   __close_ConnectionRecord.__closeo  s    $$&;;%%KK  &&t'<'<dC$$000%%!!Y 	& 	
 !%r0   c                   U R                   nS U l         [        R                  " 5       U l        UR	                  U 5      =U l        nUR
                  R                  SU5        SU l        UR                  R                  (       aI  UR                  R                  R                  UR                  5      R                  U R                  U 5        UR                  R                  R                  UR                  5      R                  U R                  U 5        g ! [         aY  n[        R                   " 5          UR
                  R                  SU5        S S S 5         S nAg ! , (       d  f        S nAg = fS nAff = f)NzCreated new connection %rTzError on connect(): %s)r  rB   r   r   r~   r   r   r  rv   first_connect
for_modifyexec_once_unless_exceptionr   _exec_w_sync_on_first_runr   r   r9  )rA   r!  rW   r   s       r1   	__connect_ConnectionRecord.__connecty  s   {{ !%	E!YY[DN151E1Ed1KKD!JKK9:FDJ }}**++66MM,,T-B-BDI MM!!,,''(=(=tD  	?""$!!":A> %$$$	?s6   AD 
E;"E67E!E6!
E3	+E63E66E;)r  r*  rB   r  r  r  r   )T)r!  rt   r   r&   r[   r   )r[   r   r  r  )r!  rt   r[   r   )r?  r   r2  r&   r[   r\   )r2  r&   r[   r\   r   )r[   r   r   r  r  ri   )r   r&   r[   r\   )r(   r)   r*   r+   r,   r-   r.   r   r   r   r   
deprecatedrW   r*  r  r  r  classmethodrA  r:  rE  r  rO  rJ   r   r8  r]  rR  r   r/   r'   r0   r1   r   r   y  s\   "	I @?K66	) 0/  	__	)
% % $%5$	  
  ! !H >B
 
6:
	
 . * *  
 ?D)()7;)	)B2%h
 ,1 %Er0   r   c                   USLnU(       aB  Uc   e[         R                  US5        Uc   eUR                  ULa  gU b   eUR                  n O1U(       a*  [         R                  [        R
                  " U5      S5        UR                  R                  nU(       a  USL =(       d    Un	U(       + n
UR                  R                  (       + =(       d    UR                  R                  nUR                  R                  =(       a    UR                  R                  nO	USL n	S=pSnU Gb2  U(       a#  U(       a  UR                  R                  SU 5         U(       d  Uc   e[        UU UU5      nUR                  U L d   eUR                  UUU	U
S9  U	(       aj  U(       a  X&l        UR                  5         U(       aF  UR                  R                   (       a  UR                  R!                  U 5        UR#                  U US9  U	(       aR  U(       aK  U(       aD  S
U < SU(       d  SOS S3nUR                  R'                  U5        [.        R0                  " U5        U(       a  UR                  b  UR3                  5         Ub  SUl        SUl        A AAg! [$         aP  nUR                  R'                  SSS9  U(       a  UR)                  US	9  [+        U[,        5      (       d  e  SnANSnAff = f! U	(       aU  U(       aM  U(       aE  S
U < SU(       d  SOS S3nUR                  R'                  U5        [.        R0                  " U5        f f f f = f)aK  Cleanup for a :class:`._ConnectionFairy` whether or not it's already
been garbage collected.

When using an async dialect no IO can happen here (without using
a dedicated thread), since this is called outside the greenlet
context and with an already running loop. In this case function
will only log a message and raise a warning.
NTFz$Connection %r being returned to poolr"   r   z!Exception during reset or similarr   rD  zFThe garbage collector is trying to clean up non-checked-in connection z, which will be z*dropped, as it cannot be safely terminated
terminatedz.  Please ensure that SQLAlchemy pooled connections are returned to the pool explicitly, either by calling ``close()`` or by using appropriate context managers to manage their lifecycle.)r=  rI  r  rB   r<  r6  r{   r]   r^   r   r   r   _reset_pooldetachrv   close_detachedr   r   r   r   r   r   r   rH  rE  r   )rB   r   r!  r6  rx   r#   r@  is_gc_cleanupdont_restore_gcedrp  can_manipulate_connection!can_close_or_terminate_connectionrequires_terminate_for_closer   messages                  r1   r5  r5    s9   ( tOM&**35 ,,,&&c1''',==	&**7;;u+=tD .."d*;m(5$5!&&&E$--*E*E 	* MM""Bt}}'B'B 	%
 #d*HLL!',$#KK68H9	#(444($%	 ))-====LL&;%6	   $"&KLLN4}}33445EF**("> +  -,=11A0D E'  A E)'''  !!'*		'".88D!!# !%#' O  	KK3d   !!,,q,1a++ ,	 -,=11A0D E'  A E)'''  !!'*		'"! ->-vs-   B.J 
K.AK)$K1 )K..K1 1AMz6Dict[weakref.ref[_ConnectionFairy], _ConnectionRecord]r=  c                      \ rS rSrSrSr\R                  (       a  SS jrSS jr	SS jr
\SS j5       r\SS j5       rSS	 jrSS
 jrSrg)rZ   i#  a   A connection-like adapter for a :pep:`249` DBAPI connection, which
includes additional methods specific to the :class:`.Pool` implementation.

:class:`.PoolProxiedConnection` is the public-facing interface for the
internal :class:`._ConnectionFairy` implementation object; users familiar
with :class:`._ConnectionFairy` can consider this object to be equivalent.

.. versionadded:: 2.0  :class:`.PoolProxiedConnection` provides the public-
   facing interface for the :class:`._ConnectionFairy` internal class.

r'   c                    g r?   r'   rf   s    r1   r9   PoolProxiedConnection.commit4  s    #r0   c                    g r?   r'   rA   argskwargss      r1   cursorPoolProxiedConnection.cursor6  s    Cr0   c                    g r?   r'   rf   s    r1   r:   PoolProxiedConnection.rollback8  s    Cr0   c                    [        5       e)z_Return True if this :class:`.PoolProxiedConnection` still refers
to an active DBAPI connection.rR   rf   s    r1   r   PoolProxiedConnection.is_valid:      
 "##r0   c                    [        5       e)zNReturn True if this :class:`.PoolProxiedConnection` is detached
from its pool.rR   rf   s    r1   is_detached!PoolProxiedConnection.is_detachedA  r  r0   c                    [        5       e)a  Separate this connection from its Pool.

This means that the connection will no longer be returned to the
pool when closed, and will instead be literally closed.  The
associated :class:`.ConnectionPoolEntry` is de-associated from this
DBAPI connection.

Note that any overall connection limiting constraints imposed by a
Pool implementation may be violated after a detach, as the detached
connection is removed from the pool's knowledge and control.

rR   rf   s    r1   rp  PoolProxiedConnection.detachH  s     "##r0   c                    [        5       e)a  Release this connection back to the pool.

The :meth:`.PoolProxiedConnection.close` method shadows the
:pep:`249` ``.close()`` method, altering its behavior to instead
:term:`release` the proxied connection back to the connection pool.

Upon release to the pool, whether the connection stays "opened" and
pooled in the Python process, versus actually closed out and removed
from the Python process, is based on the pool implementation in use and
its configuration and current state.

rR   rf   s    r1   rJ   PoolProxiedConnection.closeX  r   r0   Nr   r}  r   r~  r   r[   r   r   )r(   r)   r*   r+   r,   r-   typingr   r9   r  r:   r   r   r  rp  rJ   r/   r'   r0   r1   rZ   rZ   #  sP    
 I%G'$ $ $ $$ $r0   rZ   c                      \ rS rSr% SrSrS\S'   S\S'       SS jr\SS	 j5       r	\SS
 j5       r
\SS j5       r S     SS jjr\R                  SS j5       rSS jrSS jrSrg)_AdhocProxiedConnectionih  aL  provides the :class:`.PoolProxiedConnection` interface for cases where
the DBAPI connection is not actually proxied.

This is used by the engine internals to pass a consistent
:class:`.PoolProxiedConnection` object to consuming dialects in response to
pool events that may not always have the :class:`._ConnectionFairy`
available.

rB   r   	_is_validr   rB   rr   r   c                *    Xl         X l        SU l        g r   r  )rA   rB   r   s      r1   r    _AdhocProxiedConnection.__init__x  s    
 !1"3r0   c                .    U R                   R                  $ r?   r   r   rf   s    r1   r   )_AdhocProxiedConnection.driver_connection  s    &&888r0   c                    U R                   $ r?   r'  rf   s    r1   rW   "_AdhocProxiedConnection.connection  s    $$$r0   c                    U R                   $ )zImplement is_valid state attribute.

for the adhoc proxied connection it's assumed the connection is valid
as there is no "invalidate" routine.

r  rf   s    r1   r    _AdhocProxiedConnection.is_valid  s     ~~r0   Nc                    SU l         g r  r  r  s      r1   r   "_AdhocProxiedConnection.invalidate  s     r0   c                .    U R                   R                  $ r?   r   r  rf   s    r1   r  #_AdhocProxiedConnection.record_info  s    &&222r0   c                :    U R                   R                  " U0 UD6$ r?   rB   r  r|  s      r1   r  _AdhocProxiedConnection.cursor  s    $$++T<V<<r0   c                .    [        U R                  U5      $ r?   r   rB   rA   keys     r1   __getattr__#_AdhocProxiedConnection.__getattr__      t,,c22r0   )r   r  rB   )rB   r   r   rr   )r[   r   ri   r   r  r  r  r  )r  r   r[   r   )r(   r)   r*   r+   r,   r-   r.   r   r   r   rW   r   r   r   ro_non_memoized_propertyr  r  r  r/   r'   r0   r1   r  r  h  s     HI%%++) / 9 9 % %   ?D(7;	
 
""3 #3=3r0   r  c                     \ rS rSr% SrSrS\S'   S\S'   S\S	'           S#S
 jrS\S'   \S$S j5       r	\\
R                  " SS5      S%S j5       5       r\  S&       S'S jj5       rS(S jrS)S*S jjrS+S jr          S,S jr\S-S j5       r\S.S j5       r\S.S j5       r\
R,                  S/S j5       r\
R0                  S0S j5       r S1     S2S jjrS3S jrS4S jrS+S jrS+S  jrS)S5S! jjrS"r g)6r   i  a  Proxies a DBAPI connection and provides return-on-dereference
support.

This is an internal object used by the :class:`_pool.Pool` implementation
to provide context management to a DBAPI connection delivered by
that :class:`_pool.Pool`.   The public facing interface for this class
is described by the :class:`.PoolProxiedConnection` class.  See that
class for public API details.

The name "fairy" is inspired by the fact that the
:class:`._ConnectionFairy` object's lifespan is transitory, as it lasts
only for the length of a specific DBAPI connection being checked out from
the pool, and additionally that as a transparent proxy, it is mostly
invisible.

.. seealso::

    :class:`.PoolProxiedConnection`

    :class:`.ConnectionPoolEntry`


)rB   r   _echoro  _counterr  r  rt   r!  r   rB   rw   r  c                B    Xl         SU l        X l        X0l        X@l        g )Nr   )ro  r  rB   r   r  )rA   r!  rB   r   rx   s        r1   r   _ConnectionFairy.__init__  s!     
 0"3
r0   Optional[_ConnectionRecord]r   c                J    U R                   c  g U R                   R                  $ r?   r  rf   s    r1   r   "_ConnectionFairy.driver_connection  s#    ""*&&888r0   r%  zWThe _ConnectionFairy.connection attribute is deprecated; please use 'driver_connection'c                    U R                   $ r?   r'  rf   s    r1   rW   _ConnectionFairy.connection  r)  r0   Nc                   U(       d3  [         R                  U5      nUb  [        R                  " U5      Ul        UR
                  c   S5       eUR                  c   S5       eU=R                  S-  sl        UR                  R                  (       d  UR                  (       a  UR                  S:w  a  U$ SnUS:  GaZ  UR
                  R                  nSUR
                  l
         UR                  (       a  U(       d  UR                  (       a&  UR                  R                  SUR                  5        UR                  R                  UR                  5      nU(       dL  UR                  (       a&  UR                  R                  SUR                  5        [         R"                  " 5       eO7UR                  (       a&  UR                  R                  S	UR                  5        UR                  R                  UR                  UR
                  U5        U$ UR                  R)                  S5        UR+                  5         [         R8                  " S5      e! [         R$                   Ga(  nUR&                  (       aH  UR                  R)                  S
U5        UR
                  R+                  U5        UR-                  X7SS9  OBUR                  R)                  SUR                  U5        UR
                  R+                  U5         UR
                  R/                  5       Ul        O]! [0         aP  n[2        R4                  " 5          UR
                  R7                  USS9  AS S S 5        e ! , (       d  f       e = fS nAff = fUS-  n S nAOeS nAf[0         aU  n	[2        R4                  " 5          UR
                  n
U
b  U
R7                  U	SS9  AS S S 5        e ! , (       d  f       e = fS n	A	ff = fUS:  a  GMA  GN)Nz,can't 'checkout' a detached connection fairyz0can't 'checkout' an invalidated connection fairyr5   r   r   FzPool pre-ping on connection %sz;Pool pre-ping on connection %s failed, will invalidate poolz)Connection %s is fresh, skipping pre-pingzoDisconnection detected on checkout, invalidating all pooled connections prior to current timestamp (reason: %r)r   zVDisconnection detected on checkout, invalidating individual connection %s (reason: %r)Tr1  z+Reconnection attempts exhausted on checkoutzThis connection is closed)r   rA  r<  r6  currentr   rB   r  rv   r   r  r  r   r   r{   rT   r   InvalidatePoolErrorDisconnectionErrorinvalidate_poolr  r   r   r8  r   r   r9  r:  InvalidRequestError)r>  r!  threadconnsr@  attemptsconnection_is_freshresultr   r?  be_outerrp   s              r1   r   _ConnectionFairy._checkout  sv    %..t4E&&-kk%&8# $$0	:9	:0 "".	>=	>. 	!&&t~~^^q L l"'":":"@"@-2E$$*S>>. ;; KK-- @ % 6 6 "&!?!?!22"  &${{ $ 1 1%;$)$:$:!"
 #&"9"9";;  & ))G!22
 &&**E,D,De r 	FG%%&ABBu )) '$$KK$$9 	 ,,77:$$U$>KK$$M..	 ,,77:00??A * % **,00@@/3 A  " -  -, " A  &&(22C++$/3 ,   )  )( Q llsz   'D1I O4/BNL+*N+
N5N 
M/&	N /
M=9N  NNO4O/4!O	O/
O,	(O//O4c                >    [         R                  U R                  U S9$ )N)r@  )r   r   ro  rf   s    r1   _checkout_existing#_ConnectionFairy._checkout_existingf  s    ))$**D)AAr0   c           
     r    [        U R                  U R                  U R                  S U R                  UU S9  g )N)r#   r@  )r5  rB   r   ro  r  )rA   r#   s     r1   r   _ConnectionFairy._checkini  s3    !!##JJJJ"7	
r0   c                $    U R                  5         g r?   r  rf   s    r1   _close_ConnectionFairy._closet  s    r0   c           
        UR                   R                  (       a:  UR                   R                  U R                  U R                  [	        UUUS95        U(       d  g UR
                  [        L a  U(       a9  U R                  (       a'  UR                  R                  SU R                  5        g g U R                  (       a&  UR                  R                  SU R                  5        UR                  R                  U 5        g UR
                  [        L aS  U R                  (       a&  UR                  R                  SU R                  5        UR                  R                  U 5        g g )Nr"   z.Connection %s reset, transaction already resetz Connection %s rollback-on-returnzConnection %s commit-on-return)rv   resetrB   r   r    r   r6   r  r   r   r{   rC   r7   rF   )rA   r!  r#   r$   r%   s        r1   rn  _ConnectionFairy._resetw  s    ==MM%%''*?#1!-   N2$::KK%%H--  ::KK%%:-- ))$/""l2zz!!4)) MM##D) 3r0   c                .    U R                   R                  $ r?   )ro  r   rf   s    r1   _logger_ConnectionFairy._logger  s    zz   r0   c                    U R                   S L$ r?   r'  rf   s    r1   r   _ConnectionFairy.is_valid  s    $$D00r0   c                    U R                   S L $ r?   )r   rf   s    r1   r  _ConnectionFairy.is_detached  s    &&$..r0   c                L    U R                   c  0 $ U R                   R                  $ r?   )r   r  rf   s    r1   r  _ConnectionFairy.info  s%    ""*I**///r0   c                J    U R                   c  g U R                   R                  $ r?   r  rf   s    r1   r  _ConnectionFairy.record_info  s#    ""***666r0   c                    U R                   c  [        R                  " S5        g U R                  (       a  U R                  R	                  XS9  U(       d  S U l         U R                  5         g g )Nz.Can't invalidate an already-closed connection.)r   r	  )rB   r   rH  r   r   r   r  s      r1   r   _ConnectionFairy.invalidate  s]       (IIFG""##...> %)D! MMO r0   c                X    U R                   c   eU R                   R                  " U0 UD6$ r?   r  r|  s      r1   r  _ConnectionFairy.cursor  s0    $$000$$++T<V<<r0   c                .    [        U R                  U5      $ r?   r  r  s     r1   r  _ConnectionFairy.__getattr__  r  r0   c                   U R                   b  U R                   nS Ul        S Ul        U R                  R	                  U R                   5        U R
                  R                  5       U l        S U l         U R                  R                  R                  (       a1  U R                  R                  R                  U R                  U5        g g g r?   )	r   r  rB   ro  r   r  copyrv   rp  ro   s     r1   rp  _ConnectionFairy.detach  s    "".))C CM#'C JJ&&t'>'>? 		(DI&*D#zz""))

##**4+@+@#F * /r0   c                p    U =R                   S-  sl         U R                   S:X  a  U R                  5         g g )Nr5   r   r  r   rf   s    r1   rJ   _ConnectionFairy.close  s*    ==AMMO r0   c                n    U =R                   S-  sl         U R                   S:X  a  U R                  US9  g g )Nr5   r   r4  r  )rA   transaction_resets     r1   _close_special_ConnectionFairy._close_special  s0    ==AMM0AMB r0   )r   r  r  ro  rB   r  )r!  rt   rB   r   r   r   rx   rw   ri  ri   )NN)r!  rt   r  zOptional[threading.local]r@  Optional[_ConnectionFairy]r[   r   )r[   r   )F)r#   r&   r[   r\   r   )
r!  rt   r#   r&   r$   r&   r%   r&   r[   r\   )r[   zlog._IdentifiedLoggerTyper   r  r  r  r  r  )r  r   r[   r   )r  r&   r[   r\   )!r(   r)   r*   r+   r,   r-   r.   r   r   r   r   rj  rW   rk  r   r  r   r  rn  r  r   r  r  r  r  r  r   r  r  rp  rJ   r  r/   r'   r0   r1   r   r     s   0I J%% * -	
   439 9
 	__	)
% %  26,0	{C{C /{C *	{C
 
{C {CzB	
)*)*  $)* 	)*
 )* 
)*V ! ! 1 1 / / 
0 0 
""7 #7 ?D(7;	 =3G"
C Cr0   r   )FN)rB   r   r   r  r!  rt   r6  r  rx   zOptional[log._EchoFlagType]r#   r&   r@  r  r[   r\   )?r,   
__future__r   collectionsr   dataclassesenumr   	threadingr   r  r   r   r   r	   r
   r   r   r   r   r   r<  rU  r   r   r   r   util.typingr   r   engine.interfacesr   r   r   r   r   r   sql._typingr   	dataclassr    r3   r   listr6   r7   r8   r<   r`   rc   rl   
IdentifiedEventTargetrt   r   rr   r   r5  r=  r.   rZ   r  r   r'   r0   r1   <module>r     s   #                       ! "3/+''"' d#) ) $)X  346  ,0
+; (j   F /X /I I{$3>>5,, {$|	y$ y$x$+ $DZE+ ZEJ	 #((,A/A2A A
	A &A  A &A 
AT   ! 
B$- B$J833 83vIC, ICr0   