o
    y¬´\±  ã                   @   sL   d Z ddlZddlmZ ddlmZ G dd„ dejƒZG d	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                       s4   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Z‡  ZS )	ÚTLConnectionc                    s    t t| ƒj|i |¤Ž d| _d S ©Nr   )Úsuperr   Ú__init__Ú_TLConnection__opencount)ÚselfÚargÚkw©Ú	__class__© úO/var/www/html/env/lib/python3.10/site-packages/sqlalchemy/engine/threadlocal.pyr	      s   
zTLConnection.__init__c                 C   s   |  j d7  _ | S ©Nr   )r
   ©r   r   r   r   Ú_increment_connect   s   zTLConnection._increment_connectc                 C   s(   | j dkrtj | ¡ |  j d8  _ d S r   ©r
   r   Ú
ConnectionÚcloser   r   r   r   r      s   
zTLConnection.closec                 C   s   d| _ tj | ¡ d S r   r   r   r   r   r   Ú_force_close$   s   zTLConnection._force_close)Ú__name__Ú
__module__Ú__qualname__r	   r   r   r   Ú__classcell__r   r   r   r   r      s
    r   c                       s–   e Zd ZdZeZ‡ fdd„Zdd„ Zddd„Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡ fdd„Zedd„ ƒZdd„ Zdd„ Z‡  ZS ) ÚTLEnginezPAn Engine that includes support for thread-local managed
    transactions.

    c                    s&   t t| ƒj|i |¤Ž tj ¡ | _d S ©N)r   r   r	   r   Ú	threadingÚlocalÚ_connections)r   ÚargsÚkwargsr   r   r   r	   1   s   zTLEngine.__init__c                 K   s`   t | jdƒs	d }n| j ¡ }|d u s|jr,| j| |  | jj|¡fi |¤Ž}t 	|¡| j_| 
¡ S ©NÚconn)Úhasattrr!   r%   ÚclosedÚ_tl_connection_clsÚ_wrap_pool_connectÚpoolÚconnectÚweakrefÚrefr   )r   r   Ú
connectionr   r   r   Úcontextual_connect5   s   
þýzTLEngine.contextual_connectNc                 C   s2   t | jdƒs
g | j_| jj |  ¡ j|d�¡ | S )NÚtrans)Úxid)r&   r!   r0   Úappendr/   Úbegin_twophase)r   r1   r   r   r   r3   G   s   ÿzTLEngine.begin_twophasec                 C   ó.   t | jdƒs
g | j_| jj |  ¡  ¡ ¡ | S ©Nr0   )r&   r!   r0   r2   r/   Úbegin_nestedr   r   r   r   r6   O   s   
ÿzTLEngine.begin_nestedc                 C   r4   r5   )r&   r!   r0   r2   r/   Úbeginr   r   r   r   r7   W   s   zTLEngine.beginc                 C   s   | S r   r   r   r   r   r   Ú	__enter__]   s   zTLEngine.__enter__c                 C   s    |d u r
|   ¡  d S |  ¡  d S r   )ÚcommitÚrollback)r   Útype_ÚvalueÚ	tracebackr   r   r   Ú__exit__`   s   zTLEngine.__exit__c                 C   s,   t | jdƒr
| jjsd S | jjd  ¡  d S ©Nr0   éÿÿÿÿ)r&   r!   r0   Úpreparer   r   r   r   rA   f   s   
ÿþzTLEngine.preparec                 C   ó2   t | jdƒr
| jjsd S | jj d¡}| ¡  d S r?   )r&   r!   r0   Úpopr9   ©r   r0   r   r   r   r9   n   ó   
ÿþzTLEngine.commitc                 C   rB   r?   )r&   r!   r0   rC   r:   rD   r   r   r   r:   w   rE   zTLEngine.rollbackc                    s   t j ¡ | _tt| ƒ ¡  d S r   )r   r   r    r!   r   r   Údisposer   r   r   r   rF   €   s   zTLEngine.disposec                 C   s(   t | jdƒ p| j ¡ d u p| j ¡ jS r$   )r&   r!   r%   r'   r   r   r   r   r'   „   s
   ÿ
ýzTLEngine.closedc                 C   s:   | j s|  ¡  ¡  | j ¡ }| ¡  | j`g | j_d S d S r   )r'   r/   r   r!   r%   r   r0   )r   r.   r   r   r   r   Œ   s   
ûzTLEngine.closec                 C   s
   d| j  S )NzTLEngine(%r))Úurlr   r   r   r   Ú__repr__”   s   
zTLEngine.__repr__r   )r   r   r   Ú__doc__r   r(   r	   r/   r3   r6   r7   r8   r>   rA   r9   r:   rF   Úpropertyr'   r   rH   r   r   r   r   r   r   )   s$    
		
r   )	rI   r,   Ú r   r   r   r   ÚEnginer   r   r   r   r   Ú<module>   s   