
    9?hT                       % S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
JrJrJrJrJrJr  SSKJr   SSKrSSKrSr S	S
KJr  S	SKJr  S	SKJrJr  S	SKJ r J!r!J"r"J#r#J$r$  S	SK%J&r&  \RN                  " 5       r(Sr)Sr*\RV                  " S5      r,Sr-\c  \O\\4r.S\/S'   0 r0S\/S'   SS jr1    S S jr2      S!S jr3S"S jr4 " S S5      r5 " S S5      r6g! \ a    Sr Nf = f! \ a    Sr Nf = f)#z5Implementing pooling of connections to MySQL servers.    )annotationsN)TracebackType)AnyDictNoReturnOptionalTupleTypeUnion)uuid4TF   )CMySQLConnection)MySQLConnection)CNX_POOL_ARGSDEFAULT_CONFIGURATION)ErrorInterfaceErrorNotSupportedError	PoolErrorProgrammingError)read_option_files    @   z[^a-zA-Z0-9._:\-*$#]z0MySQL Connector/Python C Extension not availablezUnion[type, Tuple[type, ...]]MYSQL_CNX_CLASSzDict[str, MySQLConnectionPool]_CONNECTION_POOLSPooledMySQLConnectionc                    SU ;   a  U S   O
[        S	0 U D6nU R                  S5      SL a  [        c  [        [        5      e[
           U[        ;  a  [        S	0 U D6[        U'   OI[        [        U   [        5      (       a-  [        U   R                  nSU ;   a  U S   U:w  a  [        S5      eSSS5         [        U   R                  5       $ ! , (       d  f       N&= f! [         a    [        SU S35      Sef = f)
z!Return a pooled MySQL connection.	pool_nameuse_pureFN	pool_sizez)Size can not be changed for active pools.z%Failed getting connection from pool '' )generate_pool_namegetr   ImportErrorERROR_NO_CEXTCONNECTION_POOL_LOCKr   MySQLConnectionPool
isinstancer    r   get_connectionAttributeErrorr   )kwargsr   
check_sizes      _/var/www/ev-aguas/ev-aguas-proceso/venv/lib/python3.13/site-packages/mysql/connector/pooling.py_get_pooled_connectionr/   M   s      +f4{:L:Vv:V  zz*&+;+C-(( 
--+>+H+Hi())46IJJ*95??Jf$)<
)J KLL 
 +::<< 
	  3I;a@
	s   A'C7C 
CC:c                    U R                  5       n US   nUS	 [        / SQ5      nSnU H  n[        UR	                  5       5      U-
  nU(       a5  [        U5      S:  a  SOSnS	R                  U5      n[        S
U SU 35      e[        US5      (       a  US-  nUR                  SS5      US'   US   S:  d	  US   S:  a  [        SUS    35      e[        US   [        5      (       a  M  [        SUS    35      e   SUs=:  a  [        U5      :  a  O  O[        S5      e0 n	/ n
[        US SS9 H@  nUS   U	;  a  U/XS   '   U
R                  US   5        M*  XS      R                  U5        MB     U
 H  nX   n[        [        U5      5       Hz  n[        U5      S-
  n[         R"                  " SU5      nUR%                  U5      nUR                  5       nUR'                  U5        UR%                  SS5         [)        S0 UD6s  s  $    M     [        S5      e! [         a    [        S5      Sef = f! [*         a     M  f = f)a  Return a MySQL connection and try to failover if needed.

An InterfaceError is raise when no MySQL is available. ValueError is
raised when the failover server configuration contains an illegal
connection argument. Supported arguments are user, password, host, port,
unix_socket and database. ValueError is also raised when the failover
argument was not provided.

Returns MySQLConnection instance.
failoverzfailover argument not providedN)	userpasswordhostportunix_socketdatabaser   r    priorityr   r   s z, z Unsupported connection argument z in failover: r8   d   z9Priority value should be in the range of 0 to 100, got : zDPriority value should be an integer in the range of 0 to 100, got : z\You must either assign no priority to any of the routers or give a priority for every routerc                    U S   $ )Nr8   r"   xs    r.   <lambda>*_get_failover_connection.<locals>.<lambda>   s    :    T)keyreversez,Unable to connect to any of the target hostsr"   )copyKeyError
ValueErrorsetkeyslenjoinhasattrr$   r   r)   intr   sortedappendrangerandomrandintpopupdateconnectr   )r,   configr1   support_cnx_argspriority_countserverdiffarglstserver_directoryserver_priority_listr8   failover_list_lastindex
new_configs                    r.   _get_failover_connectionrc   j   s    [[]FE*% 	z
	
 N6;;=!$44TQ#BC))D/C23%~cUK  6:&&aN#ZZ
C8z*!VJ%7#%= 
+,.  &,c22 $Z013 % . 	>)CM)
 	
 '>M*%554:8J/0 ''z(:;J/077? N )(2s=)*A}%)DNN1d+E"&&u-FJf%NN:t,,,, + ) G
HHU  E9:DEL  s   H# 
H=#H:=
I
Ic                   ^ ST;   a  TR                  S5      OSn[        U[        5      (       d  [        S5      eU(       Ga  [        (       d  [        S5      eST;   a  [        S5      eST;   a  [        S5      eS	T;   a  [        S
5      eST;  a  [
        S   TS'    [        R                  R                  TS   S5      n/ nU HN  nUR                  UR                  R                  SS9UR                  UR                  UR                   S.5        MP     UR#                  S S9  U Vs/ sH  oUS   US   S.PM     snTS	'   ST;   a  TS   TS'   TR                  S5        ST;   a  [%        S0 TD6n['        S0 UD6$ S	T;   a  [)        S0 TD6$  [+        U4S j[,         5       5      (       a  [/        S0 TD6$  TR3                  SS5      nST;   a   TS	 U(       d  [4        c  [7        [8        5      e[4        (       a  U(       d  [5        U 0 TD6$ [;        U 0 TD6$ ! [        R                  R                   a    [        STS    S35      Sef = fs  snf ! [0         a     Nf = f)as  Create or get a MySQL connection object.

In its simpliest form, connect() will open a connection to a
MySQL server and return a MySQLConnection object.

When any connection pooling arguments are given, for example pool_name
or pool_size, a pool is created or a previously one is used to return
a PooledMySQLConnection.

Returns MySQLConnection or PooledMySQLConnection.
dns_srvFz(The value of 'dns-srv' must be a booleanztMySQL host configuration requested DNS SRV. This requires the Python dnspython module. Please refer to documentationr6   z<Using Unix domain sockets with DNS SRV lookup is not allowedr5   z;Specifying a port number with DNS SRV lookup is not allowedr1   zASpecifying multiple hostnames with DNS SRV look up is not allowedr4   SRVz Unable to locate any hosts for 'r!   NT)omit_final_dot)r4   r5   r8   weightc                    U S   U S   * 4$ )Nr8   rh   r"   r=   s    r.   r?   connect.<locals>.<lambda>  s    Qz]Qx[L$ArA   )rB   )r4   r5   read_default_fileoption_filesc              3  *   >#    U H	  oT;   v   M     g 7fNr"   ).0rB   r,   s     r.   	<genexpr>connect.<locals>.<genexpr>  s     6f}s   r   r"   )rR   r)   boolr   HAVE_DNSPYTHONr   dnsresolverquery	exceptionDNSExceptionrN   targetto_textr5   r8   rh   sortr   rT   rc   anyr   r/   	NameErrorr$   r   r%   r&   r   )argsr,   re   srv_recordsr1   srvrb   r   s    `      r.   rT   rT      s    (1F':fjj#Ggt$$GHH~ 8 
 F" N  V M   S  26:F6N	,,,,VF^UCK COOJJ..d.CHH #!jj	  	ABBJ
BJ3[#f+6(
z
 f$!'(;!<~

&'&00
$$$ V'1&116666)3F33 7 zz*e,HV:,4m,,000D+F++g }})) 	 26&>2B!D	"
*  s$   #H ,I(I 2I
I#"I#c                     / nS H   n UR                  [        X   5      5        M"     U(       d  [        S5      eSR	                  U5      $ ! [         a     MT  f = f)zGenerate a pool name

This function takes keyword arguments, usually the connection
arguments for MySQLConnection, and tries to generate a name for
a pool.

Raises PoolError when no name can be generated.

Returns a string.
)r4   r5   r2   r7   z.Failed generating pool name; specify pool_namer_   )rN   strrE   r   rJ   )r,   partsrB   s      r.   r#   r#   )  s^     E3	LLV[)* 4 HII88E?  		s   A
AAc                      \ rS rSrSr      SS jrSS jr        SS jrSS jrSS jr	\
SS j5       r\SS	 j5       rS
rg)r   iA  a  Class holding a MySQL Connection in a pool

PooledMySQLConnection is used by MySQLConnectionPool to return an
instance holding a MySQL connection. It works like a MySQLConnection
except for methods like close() and config().

The close()-method will add the connection back to the pool rather
than disconnecting from the MySQL server.

Configuring the connection have to be done through the MySQLConnectionPool
method set_config(). Using config() on pooled connection will raise a
PoolError.
c                    [        U[        5      (       d  [        S5      e[        U[        5      (       d  [        S5      eXl        X l        g)zqInitialize

The pool argument must be an instance of MySQLConnectionPoll. cnx
if an instance of MySQLConnection.
z$pool should be a MySQLConnectionPoolzcnx should be a MySQLConnectionN)r)   r(   r+   r   	_cnx_pool_cnx)selfpoolcnxs      r.   __init__PooledMySQLConnection.__init__P  sA     $ 344 !GHH#// !BCC.2>A	rA   c                    U $ rn   r"   r   s    r.   	__enter__PooledMySQLConnection.__enter___  s    rA   c                $    U R                  5         g rn   )close)r   exc_type	exc_value	tracebacks       r.   __exit__PooledMySQLConnection.__exit__b  s     	

rA   c                .    [        U R                  U5      $ )z0Calls attributes of the MySQLConnection instance)getattrr   )r   attrs     r.   __getattr__!PooledMySQLConnection.__getattr__j  s    tyy$''rA   c                    U R                   nU R                  R                  (       a  UR                  5         U R                  R                  U5        SU l         g! U R                  R                  W5        SU l         f = f)a)  Do not close, but add connection back to pool

The close() method does not close the connection with the
MySQL server. The connection is added back to the pool so it
can be reused.

When the pool is configured to reset the session, the session
state will be cleared by re-authenticating the user.
N)r   r   reset_sessionadd_connectionr   r   s     r.   r   PooledMySQLConnection.closen  s_    	))C~~++!!#NN))#.DI NN))#.DIs   7A $B c                     [        S5      e)z&Configuration is done through the poolzKConfiguration for pooled connections should be done through the pool itself)r   )r,   s    r.   rU   PooledMySQLConnection.config  s     
 	
rA   c                .    U R                   R                  $ z&Return the name of the connection pool)r   r   r   s    r.   r   PooledMySQLConnection.pool_name  s     ~~'''rA   )r   r   N)r   r(   r   (Union[MySQLConnection, CMySQLConnection]returnNoner   r   )r   zType[BaseException]r   BaseExceptionr   r   r   r   )r   r   r   r   )r   r   )r,   r   r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   staticmethodrU   propertyr   __static_attributes__r"   rA   r.   r   r   A  s    B'B.VB	B% ! !	
 
($ 
 
 ( (rA   c                      \ rS rSrSr   S         SS jjr\SS j5       r\SS j5       r\SS j5       r	SS jr
SS	 jrSS
 jrSS jr S   SS jjrSS jrSS jrSrg)r(   i  z*Class defining a pool of MySQL connectionsNc                   SU l         SU l        X0l        U R                  U5        U R	                  U=(       d    [        S0 UD65        0 U l        [        R                  " U R                   5      U l	        [        5       U l        U(       aK  U R                  " S0 UD6  SnXPR                   :  a'  U R                  5         US-  nXPR                   :  a  M&  ggg)zInitialize

Initialize a MySQL connection pool with a maximum number of
connections set to pool_size. The rest of the keywords
arguments, kwargs, are configuration arguments for MySQLConnection
instances.
Nr   r   r"   )
_pool_size
_pool_name_reset_session_set_pool_size_set_pool_namer#   _cnx_configqueueQueue
_cnx_queuer   _config_version
set_configr   )r   r    r   pool_reset_sessionr,   cnts         r.   r   MySQLConnectionPool.__init__  s     *.)-0I&IE);)Ef)EF+- KK( 	  %wOO%f%C'##%q ' rA   c                    U R                   $ r   )r   r   s    r.   r   MySQLConnectionPool.pool_name       rA   c                    U R                   $ )z0Return number of connections managed by the pool)r   r   s    r.   r    MySQLConnectionPool.pool_size  r   rA   c                    U R                   $ )zReturn whether to reset session)r   r   s    r.   r   !MySQLConnectionPool.reset_session  s     """rA   c                    U(       d  g[             [        5       nUR                  " S0 UD6  Xl        [	        5       U l         SSS5        g! [         a  n[        SU 35      UeSnAff = f! , (       d  f       g= f)a,  Set the connection configuration for MySQLConnection instances

This method sets the configuration used for creating MySQLConnection
instances. See MySQLConnection for valid connection arguments.

Raises PoolError when a connection argument is not valid, missing
or not supported by MySQLConnection.
Nz$Connection configuration not valid: r"   )r'   rT   rU   r   r   r   r+   r   )r   r,   test_cnxerrs       r.   r   MySQLConnectionPool.set_config  st     !W"9)&)#) ',w$ "! " W"Fse LMSVVW "!s(   A-1A
A*A%%A**A--
A;c                T    US::  d
  U[         :  a  [        S[          35      eXl        g)zSet the size of the pool

This method sets the size of the pool but it will not resize the pool.

Raises an AttributeError when the pool_size is not valid. Invalid size
is 0, negative or higher than pooling.CNX_POOL_MAXSIZE.
r   z8Pool size should be higher than 0 and lower or equal to N)CNX_POOL_MAXSIZEr+   r   )r   r    s     r.   r   "MySQLConnectionPool._set_pool_size  s5     >Y)99 J#$&  $rA   c                    [         R                  U5      (       a  [        SU S35      e[        U5      [        :  a  [        SU S35      eXl        g)zSet the name of the pool.

This method checks the validity and sets the name of the pool.

Raises an AttributeError when pool_name contains illegal characters
([^a-zA-Z0-9._\-*$#]) or is longer than pooling.CNX_POOL_MAXNAMESIZE.
zPool name 'z' contains illegal charactersz' is too longN)CNX_POOL_NAMEREGEXsearchr+   rI   CNX_POOL_MAXNAMESIZEr   )r   r   s     r.   r   "MySQLConnectionPool._set_pool_name  sP     $$Y// ;yk9V!WXXy>00 ;yk!GHH#rA   c                    [        U[        5      (       d  [        S5      e U R                  R	                  USS9  g! [
        R                   a  n[        S5      UeSnAff = f)zPut connection back in the queue

This method is putting a connection back in the queue. It will not
acquire a lock as the methods using _queue_connection() will have it
set.

Raises PoolError on errors.
3Connection instance not subclass of MySQLConnectionFblock'Failed adding connection; queue is fullN)r)   r   r   r   putr   Fullr   r   r   s      r.   _queue_connection%MySQLConnectionPool._queue_connection  s^     #//QRR	POO51zz 	PEFCO	Ps   = A"AA"c                8   [            U R                  (       d  [        S5      eU R                  R	                  5       (       a  [        S5      eU(       dl  [        S0 U R                  D6n U R                  (       a3  U R                  S   (       a  UR                  5       S:  a  [        S5      eU R                  Ul        O [        U[        5      (       d  [        S5      eU R                  U5        SSS5        g! [         a     NXf = f! , (       d  f       g= f)	a  Add a connection to the pool

This method instantiates a MySQLConnection using the configuration
passed when initializing the MySQLConnectionPool instance or using
the set_config() method.
If cnx is a MySQLConnection instance, it will be added to the
queue.

Raises PoolError when no configuration is set, when no more
connection can be added (maximum reached) or when the connection
can not be instantiated.
z&Connection configuration not availabler   compress)         z^Pool reset session is not supported with compression for MySQL server version 5.7.2 or earlierr   Nr"   )r'   r   r   r   fullrT   r   get_server_versionr   rE   r   pool_config_versionr)   r   r   r   s     r.   r   "MySQLConnectionPool.add_connection  s     "## HII##%% IJJ1 0 01++ ,,Z8224y@/)  +/*>*>'!#77#M  ""3'= "!(   ) "!s2   A#D+AC;/AD;
DDDD
Dc                   [             U R                  R                  SS9nUR                  5       (       a  U R                  UR                  :w  a>  UR                  " S0 U R                  D6   UR                  5         U R                  Ul        [        X5      sSSS5        $ ! [        R                   a  n[        S5      UeSnAff = f! [         a    U R                  U5        e f = f! , (       d  f       g= f)a?  Get a connection from the pool

This method returns an PooledMySQLConnection instance which
has a reference to the pool that created it, and the next available
MySQL connection.

When the MySQL connection is not connect, a reconnect is attempted.

Raises PoolError on errors.

Returns a PooledMySQLConnection instance.
Fr   z)Failed getting connection; pool exhaustedNr"   )r'   r   r$   r   Emptyr   is_connectedr   r   rU   r   	reconnectr   r   r   r   s      r.   r*   "MySQLConnectionPool.get_connection2  s     "Voo)))6
 $$&&''3+B+BB

.T--.MMO
 +/*>*>'(3' "! ;; V KLRUUV & **3/ "!sF   C+B#AC+.C>C+#C7CCC+C((C++
C9c                z   [            SnU R                  nUR                  5       (       a<   UR                  SS9nUR	                  5         US-  nUR                  5       (       a  M<  UsSSS5        $ ! [
        R                   a    Us sSSS5        $ [         a    e [         a     NXf = f! , (       d  f       g= f)zClose all connections

This method closes all connections. It returns the number
of connections it closed.

Used mostly for tests.

Returns int.
r   Fr   r   N)	r'   r   qsizer$   
disconnectr   r   r   r   )r   r   cnxqr   s       r.   _remove_connections'MySQLConnectionPool._remove_connectionsT  s     "C??D**,,
(((/CNN$1HC	 **,, ! "! {{ J "! !   "!s@   $B,$A2B,'B,2B)B,B)&B,(B))B,,
B:)r   r   r   r   r   r   )r   NT)
r    rL   r   zOptional[str]r   rr   r,   r   r   r   r   )r   rL   )r   rr   )r,   r   r   r   )r    rL   r   r   )r   r   r   r   )r   r   r   r   rn   )r   z2Optional[Union[MySQLConnection, CMySQLConnection]]r   r   r   )r   r   r   r   r   r   r   r   r    r   r   r   r   r   r   r*   r   r   r"   rA   r.   r(   r(     s    4 #'#'	 ! !	
  
@     # #W*$$P$ IM-(E-(	-(^ 4DrA   r(   )r,   r   r   r   )r,   r   r   ?Union[PooledMySQLConnection, MySQLConnection, CMySQLConnection])r~   r   r,   r   r   r   )r,   r   r   r   )7r   
__future__r   r   rP   re	threadingtypesr   typingr   r   r   r   r	   r
   r   uuidr   dns.exceptionrt   dns.resolverrs   r%   connection_cextr   
connectionr   	constantsr   r   errorsr   r   r   r   r   optionfilesr   RLockr'   r   r   compiler   r&   r   __annotations__r   r/   rc   rT   r#   r   r(   r"   rA   r.   <module>r     s@  : < "   	   D D D  N1 ( ;  + (   ZZ 78 B'/OoGW5X .  57 1 6:ZIZIDZIz_,_,_,D_,D0J( J(Z` `E  N  s#   C C+ C('C(+C65C6