
    -hK                     T   S r SSKJ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	  \	R                  " S	5      r\	R                  " S
5      r\	R                  " S5      r " S S\5      r " S S\5      r " S S\R"                  5      r " S S\5      r  SS jr0 r " S S\5      rg)z'Base constructs for connection pools.

    )dequeN   )event)exc)log)utilreset_rollbackreset_commit
reset_nonec                   D    \ rS rSrSrSrSrS rS rS r	S r
S rS	 rS
rg)_ConnDialect   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)rollbackselfdbapi_connections     iC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/pool/base.pydo_rollback_ConnDialect.do_rollback)   s    !!#    c                 $    UR                  5         g r   )commitr   s     r   	do_commit_ConnDialect.do_commit,   s    !r   c                 $    UR                  5         g r   closer   s     r   do_terminate_ConnDialect.do_terminate/        r   c                 $    UR                  5         g r   r   r   s     r   do_close_ConnDialect.do_close2   r"   r   c                     [        S5      e)NzJThe ping feature requires that a dialect is passed to the connection pool.NotImplementedErrorr   s     r   do_ping_ConnDialect.do_ping5   s    !-
 	
r   c                     U$ r    )r   
connections     r   get_driver_connection"_ConnDialect.get_driver_connection;   s    r   r,   N)__name__
__module____qualname____firstlineno____doc__is_asynchas_terminater   r   r    r$   r)   r.   __static_attributes__r,   r   r   r   r      s1     HM$"!!
r   r   c                       \ rS rSrSrSrg)_AsyncConnDialect?   Tr,   N)r0   r1   r2   r3   r5   r7   r,   r   r   r9   r9   ?   s    Hr   r9   c                       \ rS rSrSr\" 5       r        SS jr\R                  S 5       r
\S 5       r\R                  S 5       rS rSS	 jrS
 rSS jrS rS rS rS rS rS rS rSrg)PoolC   z)Abstract base class for connection pools.Nc
           	         U(       a  U=U l         U l        OSU l        [        R                  " XS9  Xl        X l        SU l        Xl        [        R                  R                  U[        SS/[        / SQ[        S/0SS	S
9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)aC  
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.  (requires version 1.4.43
 or greater)

 .. seealso::

    :ref:`pool_reset_on_return`

: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.

 .. versionadded:: 1.1 - ``dialect`` is now a public parameter
    to the :class:`_pool.Pool`.

: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)noneNFr   reset_on_returnF)resolve_symbol_names)only_propagate)logging_name_orig_logging_namer   instance_logger_creator_recycle_invalidate_time	_pre_pingr   symbolparse_user_argumentr	   r   r
   _reset_on_returnechodispatch_update_dialectr   listen)r   creatorrecyclerN   rD   rA   eventsdialectpre_ping	_dispatchfntargets               r   __init__Pool.__init__I   s    Z :FFD 7&*D#D0 !! $ ? ?T 21xj
 !& !@ 	!
 	MM!!)E!B#M$
T2. % r   c                 .    U R                   R                  $ r   )rQ   r5   r   s    r   _is_asyncioPool._is_asyncio   s    }}%%%r   c                      U R                   S   $ NrG   )__dict__r^   s    r   rG   Pool._creator   s    }}Z((r   c                 L    XR                   S'   U R                  U5      U l        g rb   )rc   _should_wrap_creator_invoke_creator)r   rS   s     r   rG   rd      s!    $+j!#88Ar   c                   ^  [         R                  " U R                  SS9nUS   SL=(       a    [	        US   5      =(       d    Sn[	        US   5      U-
  nUS   US   4S/S4:X  a  T$ US	:X  a  T$ U4S
 j$ ! [         a	    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,   crecrS   s    r   <lambda>+Pool._should_wrap_creator.<locals>.<lambda>       	r      Nr   connection_recordr      c                    > T" 5       $ r   r,   rk   s    r   rm   rn      ro   r   )r   get_callable_argspecrG   	TypeErrorlen)r   rS   argspec	defaultedpositionalss    `   r   rf   Pool._should_wrap_creator   s    	*//tLG AJd*>s71:C!	'!*o	1 AJ
#)<(=w'GGNAN *)!  	*))	*s   A9 9BBc                 ^   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 ! [
         a;  nU R                   R                  S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 closing connection %rTexc_info)	loggerdebugrQ   r    r$   BaseExceptionerror
isinstance	Exception)r   r-   	terminatees       r   _close_connectionPool._close_connection   s    'NY	


	**:6&&z2 	KK1:   a++ ,		s   "A' A' '
B,11B''B,c                     [        U 5      $ )z6Called by subclasses to create a new ConnectionRecord.)_ConnectionRecordr^   s    r   _create_connectionPool._create_connection  s     !&&r   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)getattrrI   	starttimetime
invalidate)r   r-   	exception_checkinrecs        r   _invalidatePool._invalidate  s[     j"6=d++cmm;$(IIKD!
J>>!!), ?8r   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.

r'   r^   s    r   recreatePool.recreate$  s     "##r   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`

r'   r^   s    r   disposePool.dispose0  s     "##r   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	_checkoutr^   s    r   connectPool.connect?  s      ))$//r   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)r   records     r   _return_connPool._return_connI  s     	V$r   c                     [        5       e)z7Implementation for :meth:`get`, supplied by subclasses.r'   r^   s    r   _do_getPool._do_getR       "##r   c                     [        5       e)z?Implementation for :meth:`return_conn`, supplied by subclasses.r'   )r   conns     r   r   Pool._do_return_connW  r   r   c                     [        5       er   r'   r^   s    r   statusPool.status\  s    !##r   )
rG   rQ   rI   rg   rE   rJ   rH   rM   rN   rD   )NNTNNFNF)NT)r0   r1   r2   r3   r4   r   rQ   r[   r   hybridpropertyr_   propertyrG   setterrf   r   r   r   r   r   r   r   r   r   r   r7   r,   r   r   r<   r<   C   s    3~H
 J/X 
& & ) ) __B B*4$'
-"
$$0%$
$
$r   r<   c                   4   \ rS rSrSrSS jrSrSrSrSr	 \
S 5       r\
S 5       r\R                  S 5       rS	r\R                   S
 5       r\R                   S 5       r\S 5       rSS jrSS jr\
S 5       r\
S 5       rS rSS jrS rS rSS jrS rSrg)r   i`  ae  Internal object which maintains an individual DBAPI connection
referenced by a :class:`_pool.Pool`.

The :class:`._ConnectionRecord` object always exists for any particular
DBAPI connection whether or not that DBAPI connection has been
"checked out".  This is in contrast to the :class:`._ConnectionFairy`
which is only a public facade to the DBAPI connection while it is checked
out.

A :class:`._ConnectionRecord` may exist for a span longer than that
of a single DBAPI connection.  For example, if the
:meth:`._ConnectionRecord.invalidate`
method is called, the DBAPI connection associated with this
:class:`._ConnectionRecord`
will be discarded, but the :class:`._ConnectionRecord` may be used again,
in which case a new DBAPI connection is produced when the
:class:`_pool.Pool`
next uses this record.

The :class:`._ConnectionRecord` is delivered along with connection
pool events, including :meth:`_events.PoolEvents.connect` and
:meth:`_events.PoolEvents.checkout`, however :class:`._ConnectionRecord`
still
remains an internal object whose API and internals may change.

.. seealso::

    :class:`._ConnectionFairy`

c                 \    Xl         U(       a  U R                  5         [        5       U l        g r   )_ConnectionRecord__pool_ConnectionRecord__connectr   finalize_callback)r   poolr   s      r   r[   _ConnectionRecord.__init__  s    NN!&r   FNc                 |    U R                   c  gU R                  R                  R                  U R                   5      $ )a  The connection object as returned by the driver after a connect.

For normal sync drivers that support the DBAPI protocol, this object
is the same as the one referenced by
:attr:`._ConnectionRecord.dbapi_connection`.

For adapted drivers, like the Asyncio ones, this is the actual object
that was returned by the driver ``connect`` call.

As :attr:`._ConnectionRecord.dbapi_connection` it may be ``None``
if this :class:`._ConnectionRecord` has been marked as invalidated.

.. versionadded:: 1.4.24

N)r   r   rQ   r.   r^   s    r   driver_connection#_ConnectionRecord.driver_connection  s9    $   (;;''==%% r   c                     U R                   $ )zAn alias to :attr:`._ConnectionRecord.dbapi_connection`.

This alias is deprecated, please use the new name.

.. deprecated:: 1.4.24

r   r^   s    r   r-   _ConnectionRecord.connection       $$$r   c                     Xl         g r   r   r   values     r   r-   r          %r   r   c                     0 $ )a  The ``.info`` dictionary associated with the DBAPI connection.

This dictionary is shared among the :attr:`._ConnectionFairy.info`
and :attr:`_engine.Connection.info` accessors.

.. note::

    The lifespan of this dictionary is linked to the
    DBAPI connection itself, meaning that it is **discarded** each time
    the DBAPI connection is closed and/or invalidated.   The
    :attr:`._ConnectionRecord.record_info` dictionary remains
    persistent throughout the lifespan of the
    :class:`._ConnectionRecord` container.

r,   r^   s    r   info_ConnectionRecord.info  s	    " 	r   c                     0 $ )a}  An "info' dictionary associated with the connection record
itself.

Unlike the :attr:`._ConnectionRecord.info` dictionary, which is linked
to the lifespan of the DBAPI connection, this dictionary is linked
to the lifespan of the :class:`._ConnectionRecord` container itself
and will remain persistent throughout the life of the
:class:`._ConnectionRecord`.

.. versionadded:: 1.1

r,   r^   s    r   record_info_ConnectionRecord.record_info  s	     	r   c                   ^^^ TR                  5       m TR                  5       nTR                  5       m[        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           	      :   > [         =(       a    [        S TTU TSS9$ )NFtransaction_was_reset)_finalize_fairy)refrN   r   r   s    r   rm   ,_ConnectionRecord.checkout.<locals>.<lambda>  s$     c4d%r   z#Connection %r checked out from pool)r   get_connectionr   r   safe_reraise_checkin_failed_should_log_debugr   weakrefr   	fairy_ref_strong_ref_connection_recordsr   r   )clsr   r   errfairyr   rN   r   s    `    @@r   checkout_ConnectionRecord.checkout  s    lln	"113 %%' !13=%kk
 	
 /2&s+KK57G -  	""$##CE#B % 	 %$ 	s/   B 
C#C3C	C
C	CC#c                 @    U R                  US9  U R                  US9  g )Nr   r   )r   checkin)r   r   r   s      r   r   !_ConnectionRecord._checkin_failed  s$    #1 	 	
r   c                    U R                   c!  U(       a  [        R                  " SU -  5        g S U l         U R                  nU R                  nU R
                  (       a5  U R
                  R                  5       nU" U5        U R
                  (       a  M5  UR                  R                  (       a  UR                  R                  X 5        UR                  U 5        g )NzDouble checkin attempted on %s)
r   r   warnr   r   r   poprO   r   r   )r   r   r-   r   	finalizers        r   r   _ConnectionRecord.checkin  s    >>!&8 II6=>**
{{$$..224Ij! $$$ ==  MM!!*3$r   c                     U R                   S L$ r   )r   r^   s    r   in_use_ConnectionRecord.in_use$  s    ~~T))r   c                     U R                   $ r   )r   r^   s    r   last_connect_time#_ConnectionRecord.last_connect_time(  s    ~~r   c                 @    U R                   b  U R                  5         g g r   )r   _ConnectionRecord__closer^   s    r   r   _ConnectionRecord.close,  s      ,LLN -r   c                 |   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)aP  Invalidate the DBAPI connection held by this
:class:`._ConnectionRecord`.

This method is called for all connection invalidations, including
when the :meth:`._ConnectionFairy.invalidate` or
:meth:`_engine.Connection.invalidate` methods are called,
as well as when any
so-called "automatic invalidation" condition occurs.

: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.

 .. versionadded:: 1.0.3

.. seealso::

    :ref:`pool_connection_invalidation`

Nz*%sInvalidate connection %r (reason: %s:%s)zSoft  z%sInvalidate connection %rTr   )r   r   rO   soft_invalidater   r   r   	__class__r0   r   _soft_invalidate_timer   r   r   softs      r   r   _ConnectionRecord.invalidate0  s    0   (KK  00%%t KK  ++D,A,A4K=KK##<R%%$$ KK##,R%% )-D&LL4L($(D!r   c                 d   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                   $ )NFr   z)Connection %r exceeded timeout; recyclingTz=Connection %r invalidated due to pool invalidation; recyclingzCConnection %r invalidated due to local soft invalidation; recyclingr   )r   r   clearr   r   rH   r   r   r   rI   r   r   )r   rT   s     r   r    _ConnectionRecord.get_connectione  sB      (IIOONNKK  2%		dnn,t{{/C/CCKK##;%% G[[))DNN:KK##%%
 G''$..8KK##%%
 GLL4L(IIOONN$$$r   c                     U R                   S L =(       dC    U R                  R                  U R                  :  =(       d    U R                  U R                  :  $ r   )r   r   rI   r   r   r^   s    r   _is_hard_or_soft_invalidated._ConnectionRecord._is_hard_or_soft_invalidated  sG    !!T) ={{++dnn<=**T^^;	
r   c                 8   U R                   R                  5         U R                  R                  R                  (       a0  U R                  R                  R	                  U R
                  U 5        U R                  R                  U R
                  US9  S U l        g )Nr   )r   r  r   rO   r   r   r   )r   r   s     r   __close_ConnectionRecord.__close  ss    $$&;;%%KK  &&t'<'<dC%%!!Y 	& 	
 !%r   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   r   r   r   rg   r   r   freshrO   first_connect
for_modifyexec_once_unless_exceptionr   _exec_w_sync_on_first_runr   r   r   )r   r   r-   r   s       r   	__connect_ConnectionRecord.__connect  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;)__poolr   r   r   r   r
  r   )TNFr   ) r0   r1   r2   r3   r4   r[   r
  r   r   r   r   r   r-   r   r   r   memoized_propertyr   r   classmethodr   r   r   r   r   r   r   r   r  r   r   r7   r,   r   r   r   r   `  s   >) EII   0 % % & & 	 $ 
   8
 , * *  3)j/%b
%Er   r   c                    U(       a  [         R                  US5        O1U(       a*  [         R                  [        R                  " U5      S5        Ub!  UR                  ULa  gU b   eUR
                  n UR                  R                  =(       a    UR                  R                  (       + nU(       a  U(       + =(       d    UnU(       + n	O	U(       + nSn	U Gb  U(       a#  U(       a  UR                  R                  SU 5         U=(       d    [        U UU5      nUR
                  U L d   eU	(       a  UR                  X%5        U(       a  U(       a  X&l        UR                  5         U	(       aH  UR                  R                   (       a  UR                  R!                  U 5        UR#                  U 5        O6SU -  n
UR                  R%                  U
5        [&        R(                  " U
5        U(       a  UR                  b  UR3                  5         ggg! [*         aP  nUR                  R%                  SSS9  U(       a  UR-                  US9  [/        U[0        5      (       d  e  SnAN|SnA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.
NTz$Connection %r being returned to poolad  The garbage collector is trying to clean up connection %r. This feature is unsupported on unsupported on asyncio dbapis that lack a "terminate" feature, since no IO can be performed at this stage to reset the connection. Please close out all connections when they are no longer used, calling ``close()`` or using a context manager to manage their lifetime.z!Exception during reset or similarr}   r   )r   r   r   r   r   r   rQ   r5   r6   r   r   r   _reset_pooldetachrO   close_detachedr   r   r   r   r   r   r   r   r   )r   rq   r   r   rN   r   r   dont_restore_gcedr  can_manipulate_connectionmessager   s               r   r   r     s   $ &**35	&**7;;u+=tD
&&c1''',== 	Bt}}'B'B#B  &&-#(+G!&&$(!#KK6 
*	 - !E
 ))-====(T9$"&KLLN,}}33445EF**+;<1 )
)G KK%%g.IIg& .88D!!# E  	KK3d   !!,,q,1a++ ,	s    B1H 56H 
I,AI''I,c                       \ rS rSrSrS rSr Sr \S 5       r	\S 5       r
\
R                  S 5       r
\SS j5       rS	 rSS
 jr\rSS jr\S 5       r\S 5       r\R*                  S 5       r\S 5       rSS jrS rS rS rS rSS jrSrg)r   i*  a2  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 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:`._ConnectionRecord`

c                 (    Xl         X l        X0l        g r   )r   r   _echo)r   r   rq   rN   s       r   r[   _ConnectionFairy.__init__?  s     0"3
r   Nc                 .    U R                   R                  $ )zThe connection object as returned by the driver after a connect.

.. versionadded:: 1.4.24

.. seealso::

    :attr:`._ConnectionFairy.dbapi_connection`

    :attr:`._ConnectionRecord.driver_connection`

    :ref:`faq_dbapi_connection`

)r   r   r^   s    r   r   "_ConnectionFairy.driver_connection[  s     &&888r   c                     U R                   $ )zAn alias to :attr:`._ConnectionFairy.dbapi_connection`.

This alias is deprecated, please use the new name.

.. deprecated:: 1.4.24

r   r^   s    r   r-   _ConnectionFairy.connectionl  r   r   c                     Xl         g r   r   r   s     r   r-   r$  w  r   r   c                 $   U(       d@  [         R                  U5      nXl        SUl        Ub  [        R
                  " U5      Ul        UR                  c  [        R                  " 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  W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        WR/                  5         [        R                  " S5      e! [        R(                   Ga0  nUR*                  (       aH  UR                  R-                  S	U5        UR                  R/                  U5        UR1                  X7SS
9  OBUR                  R-                  SUR                  U5        UR                  R/                  U5         UR                  R3                  5       Ul        Oe! [4         aX  n[6        R8                  " 5          UR                  R;                  USS9  AS S S 5         S nAO! , (       d  f        S nAO= fS nAff = fUS-  n S nAOeS nAf[4         aU  n	[6        R8                  " 5          UR                  n
U
b  U
R;                  U	SS9  AS S S 5        e ! , (       d  f       e = fS n	A	ff = fUS:  a  GMI  GN)Nr   zThis connection is closedrr   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)Tr   z+Reconnection attempts exhausted on checkout)r   r   r  _counterr   r   currentr   r   InvalidRequestErrorrO   rJ   r   r
  r  r   r   rQ   r)   InvalidatePoolErrorDisconnectionErrorinvalidate_poolr   r   r   r   r   r   r   r   )r   r   threadconnsr   attemptsconnection_is_freshresultr   r   be_outerr   s              r   r   _ConnectionFairy._checkout{  sR   %..t4EKEN&&-kk%&8#!!)))*EFF!&&t~~^^q L l"'":":"@"@-2E$$*N>>. ;; KK-- @ % 6 6 "&!6!6u7M7M!N%${{ $ 1 1%;$)$:$:!"
 #&"9"9";;  & ))G!22
 &&**E,D,De l 	FG%%&ABBo )) $$$KK$$9 	 ,,77:$$U$>KK$$M..	 ,,77:"00??A * % "**,00@@/3 A  " -,,," A  &&(22C++$/3 ,   )  )( G lls   /D1I" "P7BN"L32N"3
N=NM;.N6N";
NNN"NNN""P/O?!O.%	O?.
O<	8O??Pc                 >    [         R                  U R                  U S9$ )N)r   )r   r   r  r^   s    r   _checkout_existing#_ConnectionFairy._checkout_existing  s    ))$**D)AAr   c           
          [        U R                  U R                  U R                  S U R                  UU S9  S U l        S U l        g )N)r   r   )r   r   r   r  r  )r   r   s     r   r   _ConnectionFairy._checkin  sE    !!##JJJJ"7	
 !%"&r   c                    UR                   R                  (       a%  UR                   R                  X R                  5        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 )Nz.Connection %s reset, transaction already resetz Connection %s rollback-on-returnzConnection %s commit-on-return)rO   resetr   rM   r	   r  r   r   r   rQ   r   r
   r   )r   r   r   s      r   r  _ConnectionFairy._reset  s    ==MM&=&=>  N2$::KK%%H--  ::KK%%:-- ))$/""l2zz!!4)) MM##D) 3r   c                 .    U R                   R                  $ r   )r  r   r^   s    r   _logger_ConnectionFairy._logger  s    zz   r   c                     U R                   SL$ )zZReturn True if this :class:`._ConnectionFairy` still refers
to an active DBAPI connection.Nr   r^   s    r   r   _ConnectionFairy.is_valid  s    
 $$D00r   c                 .    U R                   R                  $ )aB  Info dictionary associated with the underlying DBAPI connection
referred to by this :class:`.ConnectionFairy`, allowing user-defined
data to be associated with the connection.

The data here will follow along with the DBAPI connection including
after it is returned to the connection pool and used again
in subsequent instances of :class:`._ConnectionFairy`.  It is shared
with the :attr:`._ConnectionRecord.info` and
:attr:`_engine.Connection.info`
accessors.

The dictionary associated with a particular DBAPI connection is
discarded when the connection itself is discarded.

)r   r   r^   s    r   r   _ConnectionFairy.info"  s    " &&+++r   c                 R    U R                   (       a  U R                   R                  $ g)ag  Info dictionary associated with the :class:`._ConnectionRecord
container referred to by this :class:`.ConnectionFairy`.

Unlike the :attr:`._ConnectionFairy.info` dictionary, the lifespan
of this dictionary is persistent across connections that are
disconnected and/or invalidated within the lifespan of a
:class:`._ConnectionRecord`.

.. versionadded:: 1.1

N)r   r   r^   s    r   r   _ConnectionFairy.record_info5  s"     ""**666r   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)au  Mark this connection as invalidated.

This method can be called directly, and is also called as a result
of the :meth:`_engine.Connection.invalidate` method.   When invoked,
the DBAPI connection is immediately closed and discarded from
further use by the pool.  The invalidation mechanism proceeds
via the :meth:`._ConnectionRecord.invalidate` internal method.

: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.

 .. versionadded:: 1.0.3

.. seealso::

    :ref:`pool_connection_invalidation`

Nz.Can't invalidate an already-closed connection.)r   r   )r   r   r   r   r   r   r   s      r   r   _ConnectionFairy.invalidateG  sY    ,   (IIFG""##...>$(D!MMO r   c                 :    U R                   R                  " U0 UD6$ )zReturn a new DBAPI cursor for the underlying connection.

This method is a proxy for the ``connection.cursor()`` DBAPI
method.

)r   cursor)r   argskwargss      r   rG  _ConnectionFairy.cursorf  s      $$++T<V<<r   c                 .    [        U R                  U5      $ r   )r   r   )r   keys     r   __getattr___ConnectionFairy.__getattr__o  s    t,,c22r   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)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
containing ConnectionRecord is separated from the DB-API connection,
and will create a new connection when next used.

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.
N)	r   r   r   r  r   r   copyrO   r  )r   r   s     r   r  _ConnectionFairy.detachr  s     "".))C CM#'C JJ&&t'>'>?		(DI&*D#zz""))

##**4+@+@#F * /r   c                 p    U =R                   S-  sl         U R                   S:X  a  U R                  5         g g )Nrr   r   r'  r   r^   s    r   r   _ConnectionFairy.close  s*    ==AMMO r   c                 n    U =R                   S-  sl         U R                   S:X  a  U R                  US9  g g )Nrr   r   r   rS  )r   transaction_resets     r   _close_special_ConnectionFairy._close_special  s0    ==AMM0AMB r   )r   r  r   r   )NNr   r  )r0   r1   r2   r3   r4   r[   r   r   r   r   r-   r   r  r   r4  r   _closer  r<  r   r   r  r   r   r   rG  rM  r  r   rW  r7   r,   r   r   r   r   *  s   &
   9 9  % % & & nC nC`B' F*2 ! ! 1 1 
, ,$  ">=3G2
Cr   r   )FN)r4   collectionsr   r   r   r   r   r   r   r   rK   r	   r
   r   objectr   r9   
Identifiedr<   r   r   r   r   r,   r   r   <module>r]     s           -.{{>*[[&
 6  F Z$3>> Z$z`E `ER  
]$H "$ iCv iCr   