
    ؄_                     v    d Z ddlZddlmZ ddlmZ  G d dej                  Z G d	 d
ej                  ZdS )a8  Provides 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   )utilc                   0     e Zd Z fdZd Zd Zd Z xZS )TLConnectionc                 V     t          t          |           j        |i | d| _        d S Nr   )superr   __init___TLConnection__opencount)selfargkw	__class__s      b/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/sqlalchemy/engine/threadlocal.pyr   zTLConnection.__init__   s3    *lD!!*C62666    c                 &    | xj         dz  c_         | S Nr   )r   r   s    r   _increment_connectzTLConnection._increment_connect   s    Ar   c                 z    | j         dk    rt          j                            |            | xj         dz  c_         d S r   r   r   
Connectioncloser   s    r   r   zTLConnection.close   s@    q  O!!$'''Ar   c                 R    d| _         t          j                            |            d S r
   r   r   s    r   _force_closezTLConnection._force_close$   s&    d#####r   )__name__
__module____qualname__r   r   r   r   __classcell__r   s   @r   r   r      se                
$ $ $ $ $ $ $r   r   c                        e Zd ZdZeZ ej        dd           fd            Zd Z	d Z
ddZd	 Zd
 Zd Zd Zd Zd Zd Z fdZed             Zd Zd Z xZS )TLEnginezPAn Engine that includes support for thread-local managed
    transactions.

    z1.3a!  The '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:`_engine.Connection` object in order to invoke statements.c                      t          t          |           j        |i | t          j                                        | _        d S N)r   r$   r   r   	threadinglocal_connections)r   argskwargsr   s      r   r   zTLEngine.__init__1   sC     	'h&7777 N0022r   c                      | j         di |S )N )_contextual_connect)r   r   s     r   contextual_connectzTLEngine.contextual_connect>   s    't'--"---r   c                 4   t          | j        d          sd }n| j                                        }||j        rK | j        | |                     | j        j        |          fi |}t          j	        |          | j        _        |
                                S Nconn)hasattrr)   r2   closed_tl_connection_cls_wrap_pool_connectpoolconnectweakrefrefr   )r   r   
connections      r   r.   zTLEngine._contextual_connectA   s    t(&11 	2JJ*//11J!2 10''	(9:FF   J
 &-[%<%<D",,...r   Nc                     t          | j        d          sg | j        _        | j        j                            |                                                     |                     | S )Ntrans)xid)r3   r)   r=   appendr.   begin_twophase)r   r>   s     r   r@   zTLEngine.begin_twophaseS   sg    t('22 	)&(D#&&$$&&55#5>>	
 	
 	
 r   c                     t          | j        d          sg | j        _        | j        j                            |                                                                            | S Nr=   )r3   r)   r=   r?   r.   begin_nestedr   s    r   rC   zTLEngine.begin_nested[   sb    t('22 	)&(D#&&$$&&3355	
 	
 	
 r   c                     t          | j        d          sg | j        _        | j        j                            |                                                                            | S rB   )r3   r)   r=   r?   r.   beginr   s    r   rE   zTLEngine.beginc   sY    t('22 	)&(D#&&t'?'?'A'A'G'G'I'IJJJr   c                     | S r&   r-   r   s    r   	__enter__zTLEngine.__enter__i   s    r   c                 ^    ||                                   d S |                                  d S r&   )commitrollback)r   type_value	tracebacks       r   __exit__zTLEngine.__exit__l   s)    =KKMMMMMMMOOOOOr   c                     t          | j        d          r| j        j        sd S | j        j        d                                          d S Nr=   )r3   r)   r=   preparer   s    r   rR   zTLEngine.preparer   sO    )733	$*	 F#++-----r   c                     t          | j        d          r| j        j        sd S | j        j                            d          }|                                 d S rP   )r3   r)   r=   poprI   r   r=   s     r   rI   zTLEngine.commitz   sV    )733	$*	 F!'++B//r   c                     t          | j        d          r| j        j        sd S | j        j                            d          }|                                 d S rP   )r3   r)   r=   rT   rJ   rU   s     r   rJ   zTLEngine.rollback   s[    )733	$*	 F!'++B//r   c                     t           j                                        | _        t	          t
          |                                            d S r&   )r   r'   r(   r)   r   r$   dispose)r   r   s    r   rX   zTLEngine.dispose   s;     N0022h%%'''''r   c                     t          | j        d           p8| j                                        d u p| j                                        j        S r1   )r3   r)   r2   r4   r   s    r   r4   zTLEngine.closed   sR     )6222 / %%''4// %%''.	
r   c                     | j         sh|                                                                  | j                                        }|                                 | j        `g | j        _        d S d S r&   )r4   r.   r   r)   r2   r   r=   )r   r;   s     r   r   zTLEngine.close   st    { 	)$$&&,,...*//11J##%%%!&&(D###	) 	)r   c                     d| j         z  S )NzTLEngine(%r))urlr   s    r   __repr__zTLEngine.__repr__   s    ((r   r&   )r   r   r    __doc__r   r5   r   
deprecatedr   r/   r.   r@   rC   rE   rG   rN   rR   rI   rJ   rX   propertyr4   r   r]   r!   r"   s   @r   r$   r$   )   sZ        
 &T_	0 3 3 3 3 3. . ./ / /$           . . .    ( ( ( ( ( 
 
 X
) ) )) ) ) ) ) ) )r   r$   )	r^   r9    r   r   r   r   Enginer$   r-   r   r   <module>rc      s                 $ $ $ $ $4? $ $ $&x) x) x) x) x)t{ x) x) x) x) x)r   