B 4]@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) TLConnectioncstt|j||d|_dS)Nr)superr__init___TLConnection__opencount)selfargkw) __class__P/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/engine/threadlocal.pyrszTLConnection.__init__cCs|jd7_|S)Nr)r )r rrr_increment_connectszTLConnection._increment_connectcCs(|jdkrtj||jd8_dS)Nr)r r Connectionclose)r rrrrs  zTLConnection.closecCsd|_tj|dS)Nr)r rrr)r rrr _force_close$szTLConnection._force_close)__name__ __module__ __qualname__rrrr __classcell__rr)r rrs 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||tj|_dS)N)rrrr threadinglocal _connections)r argskwargs)r rrr1s zTLEngine.__init__cKs |jf|S)N)_contextual_connect)r r rrrcontextual_connect=szTLEngine.contextual_connectcKs\t|jdsd}n |j}|dks*|jrT|j|||jj|f|}t ||j_| S)Nconn) hasattrrr closed_tl_connection_clsZ_wrap_pool_connectZpoolZconnectweakrefrefr)r r connectionrrrr@s  zTLEngine._contextual_connectNcCs2t|jdsg|j_|jj|j|d|S)Ntrans)xid)r!rr'appendrbegin_twophase)r r(rrrr*Rs  zTLEngine.begin_twophasecCs.t|jdsg|j_|jj||S)Nr')r!rr'r)r begin_nested)r rrrr+Zs  zTLEngine.begin_nestedcCs.t|jdsg|j_|jj||S)Nr')r!rr'r)rbegin)r rrrr,bs zTLEngine.begincCs|S)Nr)r rrr __enter__hszTLEngine.__enter__cCs|dkr|n|dS)N)commitrollback)r Ztype_value tracebackrrr__exit__ks zTLEngine.__exit__cCs,t|jdr|jjsdS|jjddS)Nr')r!rr'prepare)r rrrr4qs zTLEngine.preparecCs2t|jdr|jjsdS|jjd}|dS)Nr'r3)r!rr'popr.)r r'rrrr.ys  zTLEngine.commitcCs2t|jdr|jjsdS|jjd}|dS)Nr'r3)r!rr'r5r/)r r'rrrr/s  zTLEngine.rollbackcstj|_tt|dS)N)rrrrrrdispose)r )r rrr6s zTLEngine.disposecCs(t|jd p&|jdkp&|jjS)Nr )r!rr r")r rrrr"szTLEngine.closedcCs6|js2||j}||j`g|j_dS)N)r"rrrr rr')r r&rrrrs   zTLEngine.closecCs d|jS)Nz TLEngine(%r))Zurl)r rrr__repr__szTLEngine.__repr__)N)rrr__doc__rr#rZ deprecatedrrrr*r+r,r-r2r4r.r/r6propertyr"rr7rrr)r rr)s&     r) r8r$rrrrZEnginerrrrrs