o
    g2                     @  s   d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ ddlmZ dd	lm	Z	 dd
l
mZ ddlmZ ddlmZ ejsEesRddlmZ ddlmZ nd dlmZ d dlmZ edeg ef dZdddZG dd deZG dd dZdS )    )annotationsN)Any)Callable)Optional)TypeVar   )exc)util)HAS_CYEXTENSION)Protocol)Self   )_distill_params_20)_distill_raw_params_C)boundkeystrreturnCallable[[_C], _C]c                   s   t j fdd}|S )zDecorator, memoize a function in a connection.info stash.

    Only applicable to functions which take no arguments other than a
    connection.  The memo will be stored in ``connection.info[key]``.
    c                   s@   |  }z|j  W S  ty   | || |j < }| Y S w N)connectinfoKeyError)fnself
connectionvalr    X/var/www/html/ecg_monitoring/venv/lib/python3.10/site-packages/sqlalchemy/engine/util.py	decorated+   s   z%connection_memoize.<locals>.decorated)r	   	decorator)r   r!   r   r   r    connection_memoize$   s   r#   c                   @  s   e Zd ZU ded< dS )_TConsSubjectzOptional[TransactionalContext]_trans_context_managerN)__name__
__module____qualname____annotations__r   r   r   r    r$   7   s   
 r$   c                   @  s   e Zd ZU dZdZded< d$ddZd$d	d
Zd$ddZd%ddZ	d&ddZ
d&ddZd&ddZed'ddZd(ddZd)d!d"Zd#S )*TransactionalContextzApply Python context manager behavior to transaction objects.

    Performs validation to ensure the subject of the transaction is not
    used if the transaction were ended prematurely.

    )_outer_trans_ctx_trans_subject__weakref__zOptional[_TConsSubject]r,   r   boolc                 C     t  r   NotImplementedErrorr   r   r   r    _transaction_is_activeG      z+TransactionalContext._transaction_is_activec                 C  r/   r   r0   r2   r   r   r    _transaction_is_closedJ   r4   z+TransactionalContext._transaction_is_closedc                 C  r/   )a  indicates the object is in a state that is known to be acceptable
        for rollback() to be called.

        This does not necessarily mean rollback() will succeed or not raise
        an error, just that there is currently no state detected that indicates
        rollback() would fail or emit warnings.

        It also does not mean that there's a transaction in progress, as
        it is usually safe to call rollback() even if no transaction is
        present.

        .. versionadded:: 1.4.28

        r0   r2   r   r   r    _rollback_can_be_calledM   s   z,TransactionalContext._rollback_can_be_calledr$   c                 C  r/   r   r0   r2   r   r   r    _get_subject^   r4   z!TransactionalContext._get_subjectNonec                 C  r/   r   r0   r2   r   r   r    commita   r4   zTransactionalContext.commitc                 C  r/   r   r0   r2   r   r   r    rollbackd   r4   zTransactionalContext.rollbackc                 C  r/   r   r0   r2   r   r   r    closeg   r4   zTransactionalContext.closesubjectc                 C  s$   |j }|r| stdd S d S )NzCan't operate on closed transaction inside context manager.  Please complete the context manager before emitting further commands.)r%   r3   r   InvalidRequestError)clsr<   trans_contextr   r   r    _trans_ctx_checkj   s   z%TransactionalContext._trans_ctx_checkr   c                 C  s$   |   }|j}|| _|| _| |_| S r   )r7   r%   r+   r,   )r   r<   r?   r   r   r    	__enter__u   s   zTransactionalContext.__enter__type_r   value	tracebackc                 C  sJ  t | dd }|d u p|j| u}|d u rg|  rgz<z|   W n    t  |  r/|   W d    n1 s9w   Y  Y W |sL|d usHJ | j|_d  | _	| _d S |s`|d us\J | j|_d  | _	| _w z*|  su| 
 st|   n|  r}|   W |s|d usJ | j|_d  | _	| _d S |s|d usJ | j|_d  | _	| _w )Nr,   )getattrr%   r3   r9   r	   safe_reraiser6   r:   r+   r,   r5   r;   )r   rB   rC   rD   r<   out_of_band_exitr   r   r    __exit__   sJ   

zTransactionalContext.__exit__N)r   r.   )r   r$   )r   r8   )r<   r$   r   r8   )r   r   )rB   r   rC   r   rD   r   r   r8   )r&   r'   r(   __doc__	__slots__r)   r3   r5   r6   r7   r9   r:   r;   classmethodr@   rA   rH   r   r   r   r    r*   ;   s   
 








r*   )r   r   r   r   )
__future__r   typingr   r   r   r    r   r	   util._has_cyr
   util.typingr   r   TYPE_CHECKING_py_utilr   r   sqlalchemy.cyextension.utilr   r#   r$   r*   r   r   r   r    <module>   s(   

