HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/testing/__pycache__/engines.cpython-310.pyc
o

���gf4�@s�ddlmZddlZddlZddlZddlmZddlmZddlmZddlZddl	Z	ddl
mZddlm
Z
dd	lmZd
dl
mZd
dl
mZd
d
lmZd
dlmZejrkd
dlmZd
dlmZd
dlmZGdd�d�Ze�Ze
dd��Ze
dd��Ze
dd��Ze
dd��Z d:dd�Z!Gdd�d�Z"d;d d!�Z#ej$			"	"d<d=d-d.��Z%ej$			/	"d>d?d2d.��Z%			"	"	"	"d@d3d.�Z%d:d4d5�Z&Gd6d7�d7�Z'Gd8d9�d9�Z(dS)A�)�annotationsN)�Any)�Dict)�Optional�)�config)�	decorator)�
gc_collect�)�event)�pool)�
await_only)�Literal)�Engine)�URL)�AsyncEnginec@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#S)$�ConnectionKillercCs"t��|_t�t�|_t�|_dS�N)�weakref�WeakKeyDictionary�
proxy_refs�collections�defaultdict�set�testing_engines�dbapi_connections��self�r�E/usr/local/lib/python3.10/dist-packages/sqlalchemy/testing/engines.py�__init__%s
zConnectionKiller.__init__cCsDt�|d|j�t�|d|j�t�|d|j�t�|d|j�dS)N�checkout�checkin�close�close_detached)r�listen�	_add_conn�_remove_conn)rrrrr�add_pool*szConnectionKiller.add_poolcCs|j�|�d|j|<dS)NT)r�addr)r�	dbapi_con�
con_record�	con_proxyrrrr&2szConnectionKiller._add_conncGs|j�|�dSr)r�discard)r�
dbapi_conn�argrrrr'6szConnectionKiller._remove_conncCs,|�|j�|dvsJ�|j|�|�dS)N)�class�global�function�fixture)r(rrr))r�engine�scoperrr�
add_engine9szConnectionKiller.add_enginec
C�Bz|�WdSty }zt�d|�WYd}~dSd}~ww)Nz5testing_reaper couldn't rollback/close connection: %s��	Exception�warnings�warn�r�fn�errr�_safe?s���zConnectionKiller._safecCs.t|j�D]}|dur|jr|�|j�qdSr)�listr�is_validr?�rollback�r�recrrr�rollback_allGs
��zConnectionKiller.rollback_allcCs^t|j�D]}|dur|jr|j�|j�|�|j�q|jD]}|�|j�q|j�	�dSr)
r@rrArr-�dbapi_connectionr?�_checkinrB�clear)rrD�conrrr�checkin_allLs�
zConnectionKiller.checkin_allcCs|��dSr)rJrrrr�	close_all[�zConnectionKiller.close_allcCs*tjsdSddlm}|�|jj|�dS�Nr)�	provision)r�bootstrapped_as_sqlalchemy�rN�prepare_for_drop_tablesr4�url)r�
connectionrNrrrrQ^sz(ConnectionKiller.prepare_for_drop_tablescCs�|j|}t|�D]2}t|j�D]}|dur*|jr*|jdur*|j|jur*|�|j�qt|d�r7t	|�
��q	|�
�q	|��dS)N�sync_engine)rr@rrA�_poolrr?rG�hasattrr
�disposerH)rr5�engrD�	proxy_refrrr�_drop_testing_enginesgs

�

z&ConnectionKiller._drop_testing_enginescC�|�d�dS)Nr2)rZrrrr�
after_testx�zConnectionKiller.after_testcCsjtjsdS|jjrdS|��ddlm}tj���}|�	|j
j|�Wd�dS1s.wYdSrM)rrO�	__class__�"__leave_connections_for_teardown__rJrPrN�db�connectrQr4rR)r�testrN�connrrr�after_test_outside_fixtures{s"�z,ConnectionKiller.after_test_outside_fixturescCs |��|�d�|�d�dS)Nr2r0)rJrZrrrr�stop_test_class_inside_fixtures�s
z0ConnectionKiller.stop_test_class_inside_fixturescCsDtjjrt�tjjr ttjj�}tjj��	Jd|��dSdS)NFz/%d connection recs not cleared after test suite)r�base�_strong_ref_connection_recordsr	�lenrH)r�lnrrr� stop_test_class_outside_fixtures�s���z1ConnectionKiller.stop_test_class_outside_fixturescCs"|��|jD]}|�|�qdSr)rJrrZ)rr5rrr�
final_cleanup�s
�zConnectionKiller.final_cleanupcCs|jD]}|jr
J�qdSr)rrArCrrr�assert_all_closed�s

��z"ConnectionKiller.assert_all_closedN)�__name__�
__module__�__qualname__r r(r&r'r6r?rErJrKrQrZr\rdrerjrkrlrrrrr$s$	
rcOs(z||i|��Wt��dSt��wr)�testing_reaperrl�r=�args�kwrrr�assert_conns_closed�srtcO�(z||i|��Wt��dSt��w)zBDecorator that rolls back all open connections after fn execution.N)rprErqrrr�rollback_open_connections�srvcOst��||i|��dS)z:Decorator that closes all connections before fn execution.N�rprJrqrrr�close_first�srxcOru)z9Decorator that closes all connections after fn execution.Nrwrqrrr�close_open_connections�sryccsZ�ddlm}|jD] }|r||vrq
t||d�}|s%ttd|�j|�}|��Vq
dS)Nrzsqlalchemy.dialects.%s)�sqlalchemy.dialects�dialects�__all__�getattr�
__import__�dialect)�exclude�d�name�modrrr�all_dialects�s�
��r�c@s>eZdZdd�Zdd�Zdd�Zdd�Zdd
d�Zdd
�ZdS)�ReconnectFixturecCs||_g|_d|_dS�NF)�dbapi�connections�
is_stopped)rr�rrrr ��
zReconnectFixture.__init__cC�t|j|�Sr)r}r��r�keyrrr�__getattr__�rLzReconnectFixture.__getattr__cOsN|jj|i|��}|jr|�|j�|��}|�d�Jd��|j�|�|S)Nzselect 1Fz%simulated connect failure didn't work)	r�rar�r?r#�cursor�executer��append)rrr�kwargsrc�cursrrrra�s
zReconnectFixture.connectc
Cr7)Nz.ReconnectFixture couldn't close connection: %sr8r<rrrr?�s��zReconnectFixture._safeFcCs,||_t|j�D]}|�|j�qg|_dSr)r�r@r�r?r#)r�stop�crrr�shutdown�s
zReconnectFixture.shutdowncCs
d|_dSr�)r�rrrr�restart�
zReconnectFixture.restartN)F)	rmrnror r�rar?r�r�rrrrr��s
r�csj|ptjj}tjjj}|si}t|�|d<t||���j���fdd�}�jjj�_	�jjj
�_|�_�S)N�modulecs �jj��d�jj_��dSr�)rr�r�r�r��_disposer4rrrWs

z$reconnecting_engine.<locals>.dispose)rr`rRrr�r��testing_enginerWr��
test_shutdownr��test_restart)rR�optionsr�rWrr�r�reconnecting_engine
s

r�FrR�
Optional[URL]r��Optional[Dict[str, Any]]�asyncio�Literal[False]�transfer_staticpool�bool�returnrcC�dSrr�rRr�r�r�rrrr��r�T�
Literal[True]rcCr�rrr�rrrr�'r�cCs�|r
|rJ�ddlm}nddlm}ddlm}|s"d}d}	d}
n|�dd�}|�d	d�}	|�d
d�}
|p9tjj	}||�}tjdusK|j
tjj	j
krTtjrTtj��}ni}|dur_|�
|�||fi|��}|
r�|jdkr�t�|d�d
d��}
t�|d�dd��}|r�ddlm}tjdur�ttjj|�r�d}|j�tjj�n|r�tjj|_|	dkr�|r�d|j_nd|_t|jtj�r�d|vr�d|vr�d|vr�d|j_d|j_|r�t�||	�|S)Nr)�create_async_engine)�
create_engine)�make_urlTr2F�
use_reaperr5�sqlite_savepoint�sqliteracSs
d|_dSr)�isolation_level)rF�connection_recordrrr�
do_connect\s
z"testing_engine.<locals>.do_connect�begincSr[)N�BEGIN)�exec_driver_sql)rcrrr�do_begin`sz testing_engine.<locals>.do_begin)�
StaticPoolr1r�pool_timeout�max_overflow)�sqlalchemy.ext.asyncior��
sqlalchemyr��sqlalchemy.engine.urlr��poprr`rR�
drivername�db_opts�copy�updater�r�listens_for�sqlalchemy.poolr��
isinstancer�_transfer_fromrT�_has_events�	QueuePool�_timeout�
_max_overflowrpr6)rRr�r�r��
share_pool�_sqlite_savepointr�r�r�r5r��use_optionsr4r�r�r�rrrr�0sd�




�

��csrddlm}|stjj}g��fdd�}�fdd�}�fdd�}||d	|��t�d
�r.J���_|�_|�_�S)a'Provides a mocking engine based on the current testing.db.

    This is normally used to test DDL generation flow as emitted
    by an Engine.

    It should not be used in other cases, as assert_compile() and
    assert_sql_execution() are much better choices with fewer
    moving parts.

    r)�create_mock_enginecs��|�dSr)r�)�sql�ars��bufferrr�executor�r]zmock_engine.<locals>.executorcs"dd��D�}||ksJ|��dS)NcSsg|]}t�ddt|���qS)z[\n\t]rP)�re�sub�str��.0�srrr�
<listcomp>�sz3mock_engine.<locals>.assert_sql.<locals>.<listcomp>r)�stmts�recvr�rr�
assert_sql�szmock_engine.<locals>.assert_sqlcs �j�d��fdd��jD��S)N�
c3s �|]}t|j�d��VqdS))rN)r��compiler��r�rr�	<genexpr>�s�z1mock_engine.<locals>.print_sql.<locals>.<genexpr>)r�join�mockr)r4r�r�	print_sql�szmock_engine.<locals>.print_sqlz://r�)	r�r�rr`r�rVr�r�r�)�dialect_namer�r�r�r�r)r�r4r�mock_engine�sr�c@s:eZdZdZdd�Zd
dd�Zdd�Zd	d
�Zdd�ZdS)�DBAPIProxyCursorzuProxy a DBAPI cursor.

    Tests can provide subclasses of this to intercept
    DBAPI-level cursor operations.

    cOs"||_||_|j|i|��|_dSr)r4rSr�)rr4rcrrr�rrrr �szDBAPIProxyCursor.__init__NcKs.|r
|jj||fi|��S|jj|fi|��Sr)r�r�)r�stmt�
parametersrsrrrr��szDBAPIProxyCursor.executecKs|jj||fi|��Sr)r��executemany)rr��paramsrsrrrr��szDBAPIProxyCursor.executemanycCs
t|j�Sr)�iterr�rrrr�__iter__�r�zDBAPIProxyCursor.__iter__cCr�r)r}r�r�rrrr��rLzDBAPIProxyCursor.__getattr__r)	rmrnro�__doc__r r�r�r�r�rrrrr��s
r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�DBAPIProxyConnectionz}Proxy a DBAPI connection.

    Tests can provide subclasses of this to intercept
    DBAPI-level connection operations.

    cCs||_||_||_dSr)rcr4�
cursor_cls)rr4rcr�rrrr �r�zDBAPIProxyConnection.__init__cOs|j|j|jg|�Ri|��Sr)r�r4rc)rrrr�rrrr��szDBAPIProxyConnection.cursorcCs|j��dSr)rcr#rrrrr#�r]zDBAPIProxyConnection.closecCr�r)r}rcr�rrrr��rLz DBAPIProxyConnection.__getattr__N)rmrnror�r r�r#r�rrrrr��sr�r)NN)NNFF)
rRr�r�r�r�r�r�r�r�r)NNTF)
rRr�r�r�r�r�r�r�r�r)NNFFFF))�
__future__rrr��typingrrrr:rrPr�utilrr	rrr
�util.typingr�
TYPE_CHECKINGr4r�
engine.urlr�ext.asynciorrrprtrvrxryr�r�r��overloadr�r�r�r�rrrr�<module>sp	

	



+��	
�
S&