
    KiK5                    b   S SK Jr  S SKrS SKrS SKrS SKJr  S SKJr  S SKJr  S SKJr  S SK	r	S SK
r
SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  \R*                  (       a  SSKJr  SSKJr  SSKJr   " S S5      r\" 5       r\S 5       r\S 5       r\S 5       r \S 5       r!S'S jr" " S S5      r#S(S jr$\RJ                    S)       S*S jj5       r&\RJ                    S)       S+S jj5       r&  S(SS .       S,S! jjjr&S'S" jr' " S# S$5      r( " S% S&5      r)g)-    )annotationsN)Any)Dict)Optional)Union   )config)	decorator)
gc_collect   )event)pool)
await_only)Literal)Engine)URL)AsyncEnginec                      \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rSrg)ConnectionKiller%   c                    [         R                  " 5       U l        [        R                  " [
        5      U l        [        5       U l        g N)weakrefWeakKeyDictionary
proxy_refscollectionsdefaultdictsettesting_enginesdbapi_connectionsselfs    \/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/sqlalchemy/testing/engines.py__init__ConnectionKiller.__init__&   s/    !335*66s;!$    c                   [         R                  " USU R                  5        [         R                  " USU R                  5        [         R                  " USU R                  5        [         R                  " USU R                  5        g )Ncheckoutcheckincloseclose_detached)r   listen	_add_conn_remove_conn)r"   r   s     r#   add_poolConnectionKiller.add_pool+   sY    T:t~~6T9d&7&78T7D$5$56T+T->->?r&   c                X    U R                   R                  U5        SU R                  U'   g )NT)r    addr   )r"   	dbapi_con
con_record	con_proxys       r#   r-   ConnectionKiller._add_conn3   s$    ""9-%)	"r&   c                :    U R                   R                  U5        g r   )r    discard)r"   
dbapi_connargs      r#   r.   ConnectionKiller._remove_conn7   s    &&z2r&   c                    U R                  UR                  5        US;   d   eU R                  U   R                  U5        g )N)classglobalfunctionfixture)r/   r   r   r2   )r"   enginescopes      r#   
add_engineConnectionKiller.add_engine:   s:    fkk"BBBBU#''/r&   c                t     U" 5         g ! [          a#  n[        R                  " SU-  5         S nAg S nAff = f)Nz5testing_reaper couldn't rollback/close connection: %s	Exceptionwarningswarnr"   fnes      r#   _safeConnectionKiller._safe@   s5    	D 	MMG!K 	   
 
727c                    [        U R                  5       H6  nUc  M  UR                  (       d  M  U R                  UR                  5        M8     g r   )listr   is_validrM   rollbackr"   recs     r#   rollback_allConnectionKiller.rollback_allH   s2    (C3<<<

3<<( )r&   c                |   [        U R                  5       H[  nUc  M  UR                  (       d  M  U R                  R	                  UR
                  5        U R                  UR                  5        M]     U R                   H  nU R                  UR                  5        M      U R                  R                  5         g r   )
rQ   r   rR   r    r8   dbapi_connectionrM   _checkinrS   clear)r"   rU   cons      r#   checkin_allConnectionKiller.checkin_allM   s     (C3<<<&&..s/C/CD

3<<( ) ))CJJs||$ *$$&r&   c                $    U R                  5         g r   )r]   r!   s    r#   	close_allConnectionKiller.close_all\   s    r&   c                    [         R                  (       d  g SSKJn  UR	                  UR
                  R                  U5        g Nr   	provision)r	   bootstrapped_as_sqlalchemy re   prepare_for_drop_tablesrA   url)r"   
connectionre   s      r#   rh   (ConnectionKiller.prepare_for_drop_tables_   s-    00))**;*;*?*?Lr&   c                   U R                   U   n[        U5       H  n[        U R                  5       H`  nUc  M  UR                  (       d  M  UR                  c  M*  UR                  UR
                  L d  ME  U R                  UR                  5        Mb     [        US5      (       a  [        UR                  5       5        M  UR                  5         M     UR                  5         g Nsync_engine)r   rQ   r   rR   _poolr   rM   rZ   hasattrr   disposer[   )r"   rB   engrU   	proxy_refs        r#   _drop_testing_engines&ConnectionKiller._drop_testing_enginesh   s    ""5)9C!$//2	(Y-?-?-?!3%OOsxx7

9#5#56 3 sM**3;;=)  			r&   c                    U R                   U   n[        U5       H?  n[        US5      (       a  [        UR	                  5       5        M/  UR	                  5         MA     g rm   )r   rQ   rp   r   rq   )r"   rB   rr   rU   s       r#   _dispose_testing_engines)ConnectionKiller._dispose_testing_enginesz   sD    ""5)9CsM**3;;=)	 r&   c                &    U R                  S5        g )Nr?   )rt   r!   s    r#   
after_testConnectionKiller.after_test   s    "":.r&   c                P   [         R                  (       d  g UR                  R                  (       a  g U R	                  5         SSKJn  [         R                  R                  5        nUR                  UR                  R                  U5        S S S 5        g ! , (       d  f       g = frc   )r	   rf   	__class__"__leave_connections_for_teardown__r]   rg   re   dbconnectrh   rA   ri   )r"   testre   conns       r#   after_test_outside_fixtures,ConnectionKiller.after_test_outside_fixtures   se    00>><<
 	 YY D--dkkootD !  s   ''B
B%c                h    U R                  5         U R                  S5        U R                  S5        g )Nr?   r=   )r]   rt   r!   s    r#   stop_test_class_inside_fixtures0ConnectionKiller.stop_test_class_inside_fixtures   s*    "":.""7+r&   c                   [         R                  R                  (       a  [        5         [         R                  R                  (       aV  [	        [         R                  R                  5      n[         R                  R                  R                  5           SU-  5       e[        R                  (       a2  [        R                  R                  (       a  U R                  S5        g g g )Nz/%d connection recs not cleared after test suiter>   )
r   base_strong_ref_connection_recordsr   lenr[   r	   optionslow_connectionsrw   )r"   lns     r#    stop_test_class_outside_fixtures1ConnectionKiller.stop_test_class_outside_fixtures   s     9933Lyy77AAB		88>>@LDKL>>fnn<< ))(3 =>r&   c                l    U R                  5         U R                   H  nU R                  U5        M     g r   )r]   r   rt   )r"   rB   s     r#   final_cleanupConnectionKiller.final_cleanup   s,    ))E&&u- *r&   c                P    U R                    H  nUR                  (       d  M   e   g r   )r   rR   rT   s     r#   assert_all_closed"ConnectionKiller.assert_all_closed   s    ??C|||u #r&   )r    r   r   N)__name__
__module____qualname____firstlineno__r$   r/   r-   r.   rC   rM   rV   r]   r`   rh   rt   rw   rz   r   r   r   r   r   __static_attributes__ r&   r#   r   r   %   s_    '
@*30)
'M$/E$,
4".
r&   r   c                p     U " U0 UD6  [         R                  5         g ! [         R                  5         f = fr   )testing_reaperr   rK   argskws      r#   assert_conns_closedr      s+    +
DB((*((*    5c                p     U " U0 UD6  [         R                  5         g! [         R                  5         f = f)zBDecorator that rolls back all open connections after fn execution.N)r   rV   r   s      r#   rollback_open_connectionsr      s+    &
DB##%##%r   c                <    [         R                  5         U " U0 UD6  g)z:Decorator that closes all connections before fn execution.Nr   r]   r   s      r#   close_firstr      s      OOr&   c                p     U " U0 UD6  [         R                  5         g! [         R                  5         f = f)z9Decorator that closes all connections after fn execution.Nr   r   s      r#   close_open_connectionsr      s+    %
DB""$""$r   c              #     #    SS K Jn  UR                   HX  nU (       a  X ;   a  M  [        XS 5      nU(       d"  [        [	        SU-  5      R                  U5      nUR                  5       v   MZ     g 7f)Nr   zsqlalchemy.dialects.%s)sqlalchemy.dialectsdialects__all__getattr
__import__dialect)excludednamemods       r#   all_dialectsr      s]     #		tat$3d:;DDdC kkm s   A0A2c                  <    \ rS rSrS rS rS rS rS
S jrS r	Sr
g	)ReconnectFixture   c                ,    Xl         / U l        SU l        g NF)dbapiconnections
is_stopped)r"   r   s     r#   r$   ReconnectFixture.__init__   s    
r&   c                .    [        U R                  U5      $ r   )r   r   r"   keys     r#   __getattr__ReconnectFixture.__getattr__   s    tzz3''r&   c                   U R                   R                  " U0 UD6nU R                  (       aC  U R                  UR                  5        UR                  5       nUR                  S5         S5       eU R                  R                  U5        U$ )Nzselect 1z%simulated connect failure didn't work)	r   r   r   rM   r*   cursorexecuter   append)r"   r   kwargsr   curss        r#   r   ReconnectFixture.connect   so    zz!!4262??JJtzz";;=D LL$AAA5##D)Kr&   c                t     U" 5         g ! [          a#  n[        R                  " SU-  5         S nAg S nAff = f)Nz.ReconnectFixture couldn't close connection: %srF   rJ   s      r#   rM   ReconnectFixture._safe  s4    	PD 	PMMJQNOO	PrO   c                    Xl         [        U R                  5       H  nU R                  UR                  5        M      / U l        g r   )r   rQ   r   rM   r*   )r"   stopcs      r#   shutdownReconnectFixture.shutdown	  s6     d&&'AJJqww (r&   c                    SU l         g r   )r   r!   s    r#   restartReconnectFixture.restart  s	    r&   )r   r   r   N)F)r   r   r   r   r$   r   r   rM   r   r   r   r   r&   r#   r   r      s!     
(P	 r&   r   c                  ^^ U =(       d    [         R                  R                  n [         R                  R                  R                  nU(       d  0 n[        U5      US'   [        X5      mTR                  mUU4S jnTR                  R                  R                  Tl	        TR                  R                  R                  Tl        UTl        T$ )Nmodulec                    > TR                   R                  R                  5         STR                   R                  l        T " 5         g r   )r   r   r   r   )_disposerA   s   r#   rq   $reconnecting_engine.<locals>.dispose!  s0    %%'*/'
r&   )r	   r   ri   r   r   r   testing_enginerq   r   test_shutdownr   test_restart)ri   r   r   rq   r   rA   s       @@r#   reconnecting_enginer     s    

CII##E(/GHC)F~~H
 ">>//88F ....66FFNMr&   c                   g r   r   ri   r   asyncios      r#   r   r   ,  s     r&   c                   g r   r   r   s      r#   r   r   5  s     r&   F)r   c          
     
   U(       a  SSK Jn  OSSKJn  SSKJn  U" U (       a  U O[        R                  R                  5      n U(       d  0 n0 n[        R                  U4 H`  nU(       d  M  UR                  UR                  5        VVs0 s H'  u  pxUS;  d  M  UR                  S5      (       a  M%  Xx_M)     snn5        Mb     U" U 40 UD6n	[        R                  (       a4  [        R                  R                  (       a  [        R!                  S5        UR#                  SS	5      n
U
S:X  a   U(       a  S
U	R$                  l        OS
U	l        SSKJn  UR-                  U	R                  XU
5        UR#                  SS
5      nU(       a  [        R/                  X5        [1        U	R2                  [2        R4                  5      (       a4  SU;  a.  SU;  a(  SU;  a"  SU	R2                  l        SU	R2                  l        U	$ s  snnf )Nr   )create_async_engine)create_engine)make_url)rB   
use_reapersqlite_r>   rB   r?   Tr   rd   r   r   pool_timeoutmax_overflow)sqlalchemy.ext.asyncior   
sqlalchemyr   sqlalchemy.engine.urlr   r	   r   ri   db_optsupdateitems
startswithr   r   r   rw   getrn   _has_eventsrg   re   post_configure_testing_enginerC   
isinstancer   	QueuePool_timeout_max_overflow)ri   r   r   r   r   use_optionsopt_dictoptvaluerA   rB   re   r   s                r#   r   r   >  s    	
 	-.
#3699==
1CK^^W- #+.."2"2JC55  y1 
"2	
 . 3.+.F~~&..88 	//9KK,E-1F*   ++FJJO
 \40J!!&0 	6;;//'!')') $%!MYs   G?G?3G?c                   ^^ SSK Jn  U (       d  [        R                  R                  n / mU4S jnU4S jnU4S jnU" U S-   U5      m[        TS5      (       a   eTTl        UTl        UTl        T$ )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_enginec                (   > TR                  U 5        g r   )r   )sqlar   buffers      r#   executormock_engine.<locals>.executor  s    cr&   c           
        > T Vs/ s H$  n[         R                  " SS[        U5      5      PM&     nnX :X  d   U5       eg s  snf )Nz[\n\t]rg   )resubstr)stmtssrecvr  s      r#   
assert_sqlmock_engine.<locals>.assert_sql  s<    7=>v!y"c!f-v>}"d"} ?s   +A c                 h   >^  TR                   m SR                  U 4S jTR                   5       5      $ )N
c              3  T   >#    U  H  n[        UR                  TS 95      v   M     g7f))r   N)r  compile).0r
  r   s     r#   	<genexpr>1mock_engine.<locals>.print_sql.<locals>.<genexpr>  s$     HKqQYYqY122Ks   %()r   joinmock)r   rA   s   @r#   	print_sqlmock_engine.<locals>.print_sql  s%    NNyyHFKKHHHr&   z://r  )	r   r   r	   r   r   rp   r  r  r  )dialect_namer   r  r  r  r  rA   s        @@r#   mock_enginer    so     .yy~~F#I  u 4h?Fvv&&&&FK"F FMr&   c                  :    \ rS rSrSrS rS
S jrS rS rS r	S	r
g)DBAPIProxyCursori  ziProxy a DBAPI cursor.

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

c                J    Xl         X l        UR                  " U0 UD6U l        g r   )rA   rj   r   )r"   rA   r   r   r   s        r#   r$   DBAPIProxyCursor.__init__  s!    kk4262r&   Nc                    U(       a  U R                   R                  " X40 UD6$ U R                   R                  " U40 UD6$ r   )r   r   )r"   stmt
parametersr   s       r#   r   DBAPIProxyCursor.execute  s9    ;;&&t>2>>;;&&t2r22r&   c                <    U R                   R                  " X40 UD6$ r   )r   executemany)r"   r   paramsr   s       r#   r$  DBAPIProxyCursor.executemany  s    {{&&t:r::r&   c                ,    [        U R                  5      $ r   )iterr   r!   s    r#   __iter__DBAPIProxyCursor.__iter__  s    DKK  r&   c                .    [        U R                  U5      $ r   )r   r   r   s     r#   r   DBAPIProxyCursor.__getattr__  s    t{{C((r&   )rj   r   rA   r   )r   r   r   r   __doc__r$   r   r$  r)  r   r   r   r&   r#   r  r    s     3
3;!)r&   r  c                  0    \ rS rSrSrS rS rS rS rSr	g)	DBAPIProxyConnectioni  zqProxy a DBAPI connection.

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

c                (    X l         Xl        X0l        g r   )r   rA   
cursor_cls)r"   rA   r   r1  s       r#   r$   DBAPIProxyConnection.__init__  s    	$r&   c                X    U R                   " U R                  U R                  /UQ70 UD6$ r   )r1  rA   r   )r"   r   r   s      r#   r   DBAPIProxyConnection.cursor  s%    t{{DIIGGGGr&   c                8    U R                   R                  5         g r   )r   r*   r!   s    r#   r*   DBAPIProxyConnection.close  s    		r&   c                .    [        U R                  U5      $ r   )r   r   r   s     r#   r    DBAPIProxyConnection.__getattr__  s    tyy#&&r&   )r   r1  rA   N)
r   r   r   r   r-  r$   r   r*   r   r   r   r&   r#   r/  r/    s    %
H'r&   r/  r   )NN)..)ri   Optional[URL]r   Optional[Dict[str, Any]]r   zLiteral[False]returnr   )ri   r9  r   r:  r   zLiteral[True]r;  r   )ri   r9  r   r:  r   boolr;  zUnion[Engine, AsyncEngine])*
__future__r   r   r  typingr   r   r   r   rH   r   rg   r	   utilr
   r   r   r   r   util.typingr   TYPE_CHECKINGrA   r   
engine.urlr   ext.asyncior   r   r   r   r   r   r   r   r   r   overloadr   r  r  r/  r   r&   r#   <module>rE     s   #  	              ! 
 )P Pf "# + + & &   % %(  ( V( (+	% 	
   (+	% 	
   (,F 	F	F%F 	F
  FR#L) ):' 'r&   