o znh@sLdZddlZddlmZddlmZGdddejZGd d d ejZdS) a8Provides a thread-local transactional wrapper around the root Engine class. The ``threadlocal`` module is invoked when using the ``strategy="threadlocal"`` flag with :func:`~sqlalchemy.engine.create_engine`. This module is semi-private and is invoked automatically when the threadlocal engine strategy is used. N)base)utilcs4eZdZfddZddZddZddZZS) TLConnectioncs tt|j|i|d|_dSNr)superr__init___TLConnection__opencount)selfargkw __class__H/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/threadlocal.pyr s zTLConnection.__init__cCs|jd7_|SNr)r r rrr_increment_connectszTLConnection._increment_connectcCs(|jdkr tj||jd8_dSrr r Connectioncloserrrrrs  zTLConnection.closecCsd|_tj|dSrrrrrr _force_close$szTLConnection._force_close)__name__ __module__ __qualname__r rrr __classcell__rrrrrs  rcseZdZdZeZeddfddZddZ dd Z d#d d Z d dZ ddZ ddZddZddZddZddZfddZeddZdd Zd!d"ZZS)$TLEnginezPAn Engine that includes support for thread-local managed transactions. z1.3aThe 'threadlocal' engine strategy is deprecated, and will be removed in a future release. The strategy is no longer relevant to modern usage patterns (including that of the ORM :class:`.Session` object) which make use of a :class:`.Connection` object in order to invoke statements.cs&tt|j|i|tj|_dSN)rrr r threadinglocal _connections)r argskwargsrrrr 1s zTLEngine.__init__cKs|jdi|S)Nr)_contextual_connect)r r rrrcontextual_connect=szTLEngine.contextual_connectcKs`t|jds d}n|j}|dus|jr,|j|||jj|fi|}t ||j_| SNconn) hasattrr!r'closed_tl_connection_cls_wrap_pool_connectpoolconnectweakrefrefr)r r connectionrrrr$@s  zTLEngine._contextual_connectNcCs2t|jds g|j_|jj|j|d|S)Ntrans)xid)r(r!r1appendr$begin_twophase)r r2rrrr4Rs zTLEngine.begin_twophasecC.t|jds g|j_|jj||SNr1)r(r!r1r3r$ begin_nestedrrrrr7Zs  zTLEngine.begin_nestedcCr5r6)r(r!r1r3r$beginrrrrr8bs zTLEngine.begincCs|Srrrrrr __enter__hszTLEngine.__enter__cCs |dur |dS|dSr)commitrollback)r type_value tracebackrrr__exit__ks  zTLEngine.__exit__cCs,t|jdr |jjs dS|jjddSNr1)r(r!r1preparerrrrrBqs zTLEngine.preparecC2t|jdr |jjs dS|jjd}|dSr@)r(r!r1popr:r r1rrrr:y  zTLEngine.commitcCrCr@)r(r!r1rDr;rErrrr;rFzTLEngine.rollbackcstj|_tt|dSr)rrr r!rrdisposerrrrrGs zTLEngine.disposecCs(t|jd p|jdup|jjSr&)r(r!r'r)rrrrr)s   zTLEngine.closedcCs:|js||j}||j`g|j_dSdSr)r)r$rr!r'rr1)r r0rrrrs   zTLEngine.closecCs d|jS)Nz TLEngine(%r))urlrrrr__repr__s zTLEngine.__repr__r)rrr__doc__rr*r deprecatedr r%r$r4r7r8r9r?rBr:r;rGpropertyr)rrIrrrrrr)s.   r) rJr.rrrrEnginerrrrrs