
    ,hn9                    v   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  SSKJr  \R                   " \5      rSr " S S5      rS rS rS rS rS r\R4                  S 5       rS r\R4                  S 5       r\R4                  S 5       rS rS r S r!\R4                  S 5       r"\R4                  S 5       r#S r$\RK                  \$5      S 5       r&\R4                  S 5       r'\R4                  S  5       r(\R4                  S! 5       r)\R4                  S" 5       r*S# r+\R4                  S$ 5       r,\R4                  S% 5       r-\R4                  S& 5       r.\R4                  S' 5       r/\R4                  S( 5       r0\R4                  SS)S*.S+ j5       r1\R4                  S, 5       r2g)-    )annotationsN   )config)engines)util   )exc)inspect)url)ddlschemac                  J    \ rS rSrS	S jr\S 5       r\S 5       rS rS r	Sr
g)
register   Nc                    0 U l         Xl        g N)fns	decorator)selfr   s     T/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/testing/provision.py__init__register.__init__   s    "    c                @    [        5       R                  S5      " U5      $ N*r   for_db)clsfns     r   initregister.init"   s    z  %b))r   c                6    [        U5      R                  S5      $ r   r   )r    r   s     r   init_decoratorregister.init_decorator&   s    	"))#..r   c                   ^ ^ UU 4S jnU$ )Nc                |   > TR                   (       a  TR                  U 5      n T H  nU TR                  U'   M     T$ r   r   r   )r!   dbnamedbnamesr   s     r   decorate!register.for_db.<locals>.decorate+   s5    ~~^^B'!#%  "Kr    )r   r+   r,   s   `` r   r   register.for_db*   s    	 r   c                l   [        U[        5      (       a  [        R                  " U5      nO8[        U[        R                  5      (       a  UnOUR
                  R                  nUR                  5       nXPR                  ;   a  U R                  U   " U/UQ70 UD6$ U R                  S   " U/UQ70 UD6$ r   )	
isinstancestrsa_urlmake_urlURLdbr   get_backend_namer   )r   cfgargkwr   backends         r   __call__register.__call__4   s    c3//#&CVZZ((C&&**C&&(hh88G$S535"5588C=1s1b11r   r)   r   )__name__
__module____qualname____firstlineno__r   classmethodr"   r%   r   r<   __static_attributes__r.   r   r   r   r      s9    # * * / /2r   r   c                    [        5        HC  n[        R                  SXR                  R                  5        [        XR                  U 5        ME     g )NzCREATE database %s, URI %r)_configs_for_db_operationloginfor6   r   	create_dbfollower_identr8   s     r   create_follower_dbrK   B   s4    (*-~vvzzJ#vv~. +r   c                   [         R                  " U 5      R                  5       nUR                  5         U(       a  [	        X5      n 0 n[        XU5        SUS'   [        R                  " X5      n[        XU5        UR                  5       R                  5         [        R                  R                  XeX5      nU(       a  U[        l        U(       a  [        Xs5        U$ )Nglobalscope)r3   r4   get_dialectload_provisioningfollower_url_from_mainupdate_db_optsr   testing_enginepost_configure_engineconnectcloser   Configr   identconfigure_follower)db_urloptionsfile_configrJ   dialectdb_optsengr8   s           r   setup_configr`   H   s     oof%113G'?G6G,GG

 
 
1C&~6KKM
--
 
 w
DC %3/Jr   c                    [        5        HC  n[        R                  SXR                  R                  5        [        XR                  U 5        ME     g )NzDROP database %s, URI %r)rE   rF   rG   r6   r   drop_dbrI   s     r   drop_follower_dbrc   e   s4    (*+^VVZZHVV^, +r   c              #  f  #    [        5       n[        R                  " [         5      nU  Vs/ s H  n[        R                  " U5      PM     sn Vs/ s H  nXUR                  5       4PM     nnU H2  u  pWUR                  5       nX7R                     R                  U5        M4     0 n	U Hy  u  pWUR                  n
UR                  5         X;  a!  [        U5      R                  X:   5      =X'   nOX   n[        X[5       H  nX;   a  M
  UR                  U5        Uv   M!     M{     gs  snf s  snf 7f)a  Generate a set of URLs to test given configured URLs plus additional
driver names.

Given:

.. sourcecode:: text

    --dburi postgresql://db1          --dburi postgresql://db2          --dburi postgresql://db2          --dbdriver=psycopg2 --dbdriver=asyncpg?async_fallback=true

Noting that the default postgresql driver is psycopg2,  the output
would be:

.. sourcecode:: text

    postgresql+psycopg2://db1
    postgresql+asyncpg://db1
    postgresql+psycopg2://db2
    postgresql+psycopg2://db3

That is, for the driver in a --dburi, we want to keep that and use that
driver for each URL it's part of .   For a driver that is only
in --dbdrivers, we want to use it just once for one of the URLs.
for a driver that is both coming from --dburi as well as --dbdrivers,
we want to keep it in that dburi.

Driver specific query options can be specified by added them to the
driver name. For example, to enable the async fallback option for
asyncpg::

.. sourcecode:: text

    --dburi postgresql://db1          --dbdriver=asyncpg?async_fallback=true

N)setcollectionsdefaultdictr3   r4   rO   get_driver_namenameaddrP   
difference_generate_driver_urls)db_urlsextra_driversurls!backend_to_driver_we_already_haverZ   url_objurls_plus_dialectsr]   driver_namebackend_to_driver_we_needr;   extra_per_backend
driver_urls                r   generate_db_urlsrw   k   s5    N 5D(3(?(?(D% ?FFgF/gFFG 
%%'(F  
 / --/),,7;;KH	 / !#.,,!!#3EHFj:CDE%.1B !: B/KJ!HHZ 	 L / Gs   )D1 D'D1D,+CD1c              #  $  #    U R                  5       nUR                  U5        [        XS5      n U v   [        U5       HL  nSU;   a  UR	                  SS5      u  pEOUnS n[        XU5      nU(       d  M7  UR                  U5        Uv   MN     g 7f)N ?r   )rh   discardgenerate_driver_urllistsplitremove)r   rn   main_driverdrvdriver_only	query_strnew_urls          r   rl   rl      s     %%'K+&
c
3C
IM"#:%(YYsA%6"K KI%c	B7  %M #s   A0B6Bc                    U R                  5       nU R                  U< SU< 3S9nU(       a  UR                  U5      n UR                  5         U$ ! [        R
                   a     g f = f)N+)
drivername)r7   re   update_query_stringrO   r	   NoSuchModuleError)r   driverr   r;   r   s        r   r|   r|      sr    ""$Ggg%v.  G --i8     s    A A)(A)c               #  0  #    [        5       n [        R                  R                  5        H  nUR                  R                  5         M     [        R                  R                  5        Hh  nUR                  R                  nUR                  5       nX2R                  UR                  UR                  4nX@;  d  MS  Uv   U R                  U5        Mj     [        R                  R                  5        H  nUR                  R                  5         M     g 7fr   )re   r   rW   all_configsr6   disposer   r7   usernamehostdatabaserj   )hostsr8   r   r;   	host_confs        r   rE   rE      s     EE}}((* + }}((*ffjj&&(llCHHcllC	!IIIi  + }}((* +s   B7D=ADc                    g r   r.   r8   r_   s     r   "drop_all_schema_objects_pre_tablesr          r   c                    g r   r.   r   s     r   #drop_all_schema_objects_post_tablesr      r   r   c                
   [        X5        [        X5        [        R                  R                  R
                  (       a  [        X5        [        U5      nSn[        R                  R                  R                  U 5      (       a  X0R                  U R                  4-  n[        R                  " XUS9  [        X5        [        R                  R                  R                  U 5      (       Ga  UR!                  5        nUR#                  5        H<  nUR%                  [&        R(                  " [*        R,                  " U5      5      5        M>     [        R                  R                  R                  U 5      (       al  U R                  U R                  4 HP  nUR#                  US9 H:  nUR%                  [&        R(                  " [*        R,                  " XVS95      5        M<     MR     S S S 5        g g ! , (       d  f       g = f)Nr   )consider_schemasr   )r   
drop_viewsr   requirementsmaterialized_viewsenableddrop_materialized_viewsr
   schemasenabled_for_configtest_schematest_schema_2r   drop_all_tablesr   	sequencesbeginget_sequence_namesexecuter   DropSequencer   Sequence)r8   r_   	inspectorr   connseqschema_names          r   drop_all_schema_objectsr      su   &s0s--55)I""55c::__c.?.?@@:JK'1$$77<<YY[D 335S--fooc.BCD 6""**==cBB$'OOS5F5F#GK(;;*  <   ,, & H  $H	 [ =[s   ?C+G44
Hc                    [        U5      n UR                  5       nUR                  5        nU HP  nUR                  [        R
                  " [        R                  " U[        R                  " 5       5      5      5        MR     S S S 5        [        R                  R                  R                  U 5      (       a   UR                  U R                  S9nUR                  5        nU HY  nUR                  [        R
                  " [        R                  " U[        R                  " 5       U R                  S95      5        M[     S S S 5        g g ! , (       d  f       N= f! [         a     Nf = f! , (       d  f       g = f! [         a     g f = f)Nr   )r
   get_view_namesr   r   r   	_DropViewr   TableMetaDataNotImplementedErrorr   r   r   r   r   )r8   r_   r   
view_namesr   vnames         r   r   r     s0   I	--/
 YY[D#MM&,,ufoo6G"HI $  ""55c::	"111IJ 'ELL"LL % & 1'* (  ; [    # 		s<   E AE;F  $A E/
E
E,+E,/
E= 
FFc                    [        U5      nUR                  5       nUR                  5        nU H  nUR                  SU 35        M     S S S 5        [        R
                  R                  R                  U 5      (       a]  UR                  U R                  S9nUR                  5        nU H$  nUR                  SU R                   SU 35        M&     S S S 5        g g ! , (       d  f       N= f! , (       d  f       g = f)NzDROP MATERIALIZED VIEW r   .)	r
   get_materialized_view_namesr   exec_driver_sqlr   r   r   r   r   )r8   r_   r   mview_namesr   r   s         r   r   r   <  s    I779K	 E  #:5'!BC ! 
 ""55c::;;?? < 
 YY[D$$$-coo->awG % [	 ;	 
 [s   C)+C/
C,/
C=c                4    [        SUR                  < 35      e)zDynamically create a database for testing.

Used when a test run will employ multiple processes, e.g., when run
via `tox` or `pytest -n4`.
z no DB creation routine for cfg: r   r   r8   r_   rX   s      r   rH   rH   P  s     039 r   c                4    [        SUR                  < 35      e)z8Drop a database that we dynamically created for testing.zno DB drop routine for cfg: r   r   s      r   rb   rb   \  s     #''K
LLr   c                r   ^  [         R                  " T 5      n[        UR                  5      S:X  a  T $ U 4S j$ )N   c                   > T" X5      $ r   r.   )rZ   r^   _optionsr!   s      r   <lambda>'_adapt_update_db_opts.<locals>.<lambda>g  s
    F1Dr   )r   inspect_getfullargspeclenargs)r!   insps   ` r   _adapt_update_db_optsr   b  s.    &&r*D
499~	DDr   c                    g)zCSet database options (db_opts) for a test database that we created.Nr.   )rZ   r^   r[   s      r   rR   rR   j      r   c                    g)zPerform extra steps after configuring an engine for testing.

(For the internal dialects, currently only used by sqlite, oracle, mssql)
Nr.   )r   enginerJ   s      r   rT   rT   o  r   r   c                L    [         R                  " U 5      n U R                  US9$ )zCreate a connection URL for a dynamically-created test database.

:param url: the connection URL specified when the test run was invoked
:param ident: the pytest-xdist "worker identifier" to be used as the
              database name
)r   )r3   r4   re   r   rX   s     r   rQ   rQ   w  s#     //#
C77E7""r   c                    g)z@Create dialect-specific config settings for a follower database.Nr.   )r8   rX   s     r   rY   rY     s     	r   c                    g)aC  Remove databases that were created during the test process, after the
process has ended.

This is an optional step that is invoked for certain backends that do not
reliably release locks on the database as long as a process is still in
use. For the internal dialects, this is currently only necessary for
mssql and oracle.
Nr.   r   s     r   run_reap_dbsr     r   r   c                   [         R                  S5        [        R                  " [        5      n[        R                  " [        5      n0 n[        U 5       nU H  nUR                  5       nUR                  S5      u  pg[        R                  " U5      nXc;  a$  UR                  5       X6'   X6   R                  5         UR                  5       UR                  4n	X   R                  U5        X)   R                  U5        M     S S S 5        U H"  n	[        X   5      S   n
X)   n[!        X5        M$     g ! , (       d  f       N7= f)NzReaping databases... r   )rF   rG   rf   rg   re   openstripr~   r3   r4   rO   rP   r7   r   rj   r}   r   )idents_filero   identsdialectsfile_linedb_namerZ   rq   url_keyr   rX   s               r   reap_dbsr     s   HH#$""3'D$$S)FH	k	eD::<D"jjoOGoof-G&$+$7$7$9!!335//17<<@GMf%O(  
 4=!!$S   
	s   B.D66
Ec                4    [        SUR                  < 35      e)a;  Specify keyword arguments for creating a temporary Table.

Dialect-specific implementations of this method will return the
kwargs that are passed to the Table method when creating a temporary
table for testing, e.g., in the define_temp_tables method of the
ComponentReflectionTest class in suite/test_reflection.py
z,no temp table keyword args routine for cfg: r   r   s     r   temp_table_keyword_argsr     s     <?GGE r   c                    g r   r.   )r   
connections     r   prepare_for_drop_tablesr     r   r   c                    g r   r.   )r   r6   testclss      r    stop_test_class_outside_fixturesr     r   r   c                    U$ )a  Specify table name for creating a temporary Table.

Dialect-specific implementations of this method will return the
name to use when creating a temporary table for testing,
e.g., in the define_temp_tables method of the
ComponentReflectionTest class in suite/test_reflection.py

Default to just the base name since that's what most dialects will
use. The mssql dialect's implementation will need a "#" prepended.
r.   )r8   r_   	base_names      r   get_temp_table_namer     s
     r   c                H    [        SU R                  R                  < 35      e)Nz7backend does not implement a schema name set function: r   r6   r   )r8   dbapi_connectionr   s      r    set_default_schema_on_connectionr     s    
66::	 r   F)
set_lambdasort_by_parameter_orderc               F    [        SU R                  R                   35      e)a  return the backends insert..on conflict / on dupe etc. construct.

while we should add a backend-neutral upsert construct as well, such as
insert().upsert(), it's important that we continue to test the
backend-specific insert() constructs since if we do implement
insert().upsert(), that would be using a different codepath for the things
we need to test like insertmanyvalues, etc.

z3backend does not include an upsert implementation: r   )r8   table	returningr   r   s        r   upsertr     s#     
=cffjj\J r   c                    U$ )zwNormalize sequence parameters for dialect that don't start with 1
by default.

The default implementation does nothing
r.   )r8   sequences     r   normalize_sequencer     s	     Or   )3
__future__r   rf   loggingry   r   r   r   r	   r
   r   r   r3   sqlr   r   	getLoggerr>   rF   FOLLOWER_IDENTr   rK   r`   rc   rw   rl   r"   r|   rE   r   r   r   r   r   rH   rb   r   r%   rR   rT   rQ   rY   r   r   r   r   r   r   r   r   r   r.   r   r   <module>r      s/   #        "   !"2 "2J/:-GT, 
 "& 
	 	 
	 	BB( 
  
M M
E 
./N 0N 
  
# # 
	 	
 
 !2 

 
 
	 	 
	 	 
  
  
)-u " 
 r   