
    *hb                       % 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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'  \
(       a  S	SK(J)r)  \RT                  " 5       r+Sr,Sr-\R\                  " S5      r/Sr0\c  \O\\4r1S\2S'   0 r3S\2S'   S S jr4    S!S jr5      S"S jr6S#S jr7 " S S5      r8 " S S5      r9g! \ a    Sr Nf = f! \ a    Sr Nf = f)$z5Implementing pooling of connections to MySQL servers.    )annotationsN)TracebackType)TYPE_CHECKINGAnyDictNoReturnOptionalTupleTypeUnion)uuid4TF   )CMySQLConnection)MySQLConnection)CNX_POOL_ARGSDEFAULT_CONFIGURATION)ErrorInterfaceErrorNotSupportedError	PoolErrorProgrammingError)read_option_files)MySQLConnectionAbstract    @   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      O/var/www/auris/envauris/lib/python3.13/site-packages/mysql/connector/pooling.py_get_pooled_connectionr1   P   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: r:   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   $ )Nr:   r$   xs    r0   <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.   configr3   support_cnx_argspriority_countserverdiffarglstserver_directoryserver_priority_listr:   failover_list_lastindex
new_configs                    r0   _get_failover_connectionre   m   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)ai  Creates or gets a MySQL connection object.

In its simpliest form, `connect()` will open a connection to a
MySQL server and return a `MySQLConnectionAbstract` subclass
object such as `MySQLConnection` or `CMySQLConnection`.

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`.

Args:
    *args: N/A.
    **kwargs: For a complete list of possible arguments, see [1]. If no arguments
              are given, it uses the already configured or default values.

Returns:
    A `MySQLConnectionAbstract` subclass instance (such as `MySQLConnection` or
    `CMySQLConnection`) or a `PooledMySQLConnection` instance.

Examples:
    A connection with the MySQL server can be established using either the
    `mysql.connector.connect()` method or a `MySQLConnectionAbstract` subclass:
    ```
    >>> from mysql.connector import MySQLConnection, HAVE_CEXT
    >>>
    >>> cnx1 = mysql.connector.connect(user='joe', database='test')
    >>> cnx2 = MySQLConnection(user='joe', database='test')
    >>>
    >>> cnx3 = None
    >>> if HAVE_CEXT:
    >>>     from mysql.connector import CMySQLConnection
    >>>     cnx3 = CMySQLConnection(user='joe', database='test')
    ```

References:
    [1]: https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html
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 documentationr8   z<Using Unix domain sockets with DNS SRV lookup is not allowedr7   z;Specifying a port number with DNS SRV lookup is not allowedr3   zASpecifying multiple hostnames with DNS SRV look up is not allowedr6   SRVz Unable to locate any hosts for 'r#   NT)omit_final_dot)r6   r7   r:   weightc                    U S   U S   * 4$ )Nr:   rj   r$   r?   s    r0   rA   connect.<locals>.<lambda>   s    Qz]Qx[L$ArC   )rD   )r6   r7   read_default_fileoption_filesc              3  ,   >#    U  H	  oT;   v   M     g 7fNr$   ).0rD   r.   s     r0   	<genexpr>connect.<locals>.<genexpr>4  s     6f}s   r!   r$   )rT   r+   boolr   HAVE_DNSPYTHONr   dnsresolverquery	exceptionDNSExceptionrP   targetto_textr7   r:   rj   sortr   rV   re   anyr   r1   	NameErrorr&   r   r'   r(   r   )argsr.   rg   srv_recordsr3   srvrd   r!   s    `      r0   rV   rV      s   R (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.
)r6   r7   r4   r9   z.Failed generating pool name; specify pool_namera   )rP   strrG   r   rL   )r.   partsrD   s      r0   r%   r%   F  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   i^  al  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.

Attributes:
    pool_name (str): Returns the name of the connection pool to which the
                     connection belongs.
c                    [        U[        5      (       d  [        S5      e[        U[        5      (       d  [        S5      eXl        X l        g)zxConstructor.

Args:
    pool: A `MySQLConnectionPool` instance.
    cnx: A `MySQLConnectionAbstract` subclass instance.
z$pool should be a MySQLConnectionPoolzcnx should be a MySQLConnectionN)r+   r*   r-   r   	_cnx_pool_cnx)selfpoolcnxs      r0   __init__PooledMySQLConnection.__init__q  sA     $ 344 !GHH#// !BCC.2-0	rC   c                    U $ rp   r$   r   s    r0   	__enter__PooledMySQLConnection.__enter__  s    rC   c                $    U R                  5         g rp   )close)r   exc_type	exc_value	tracebacks       r0   __exit__PooledMySQLConnection.__exit__  s     	

rC   c                .    [        U R                  U5      $ )z0Calls attributes of the MySQLConnection instance)getattrr   )r   attrs     r0   __getattr__!PooledMySQLConnection.__getattr__  s    tyy$''rC   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 adds connection back to pool.

For a pooled connection, close() does not actually close it but returns it
to the pool and makes it available for subsequent connection requests. If the
pool configuration parameters are changed, a returned connection is closed
and reopened with the new configuration before being returned from the pool
again in response to a connection request.
N)r   r   reset_sessionadd_connectionr   r   s     r0   r   PooledMySQLConnection.close  s_    	))C~~++!!#NN))#.DI NN))#.DIs   7A $B c                     [        S5      e)zConfiguration is done through the pool.

For pooled connections, the `config()` method raises a `PoolError`
exception. Configuration for pooled connections should be done
using the pool object.
zKConfiguration for pooled connections should be done through the pool itself)r   )r.   s    r0   rW   PooledMySQLConnection.config  s     
 	
rC   c                .    U R                   R                  $ )zHReturns the name of the connection pool to which the connection belongs.)r   r    r   s    r0   r    PooledMySQLConnection.pool_name  s     ~~'''rC   )r   r   N)r   r*   r   r   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   staticmethodrW   propertyr    __static_attributes__r$   rC   r0   r   r   ^  sn    $1% ! !	
 
(" 

 

 ( (rC   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)a  Constructor.

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.

Args:
    pool_name: The pool name. If this argument is not given, Connector/Python
               automatically generates the name, composed from whichever of
               the host, port, user, and database connection arguments are
               given in kwargs, in that order.
    pool_size:  The pool size. If this argument is not given, the default is 5.
    pool_reset_session: Whether to reset session variables when the connection
                        is returned to the pool.
    **kwargs: Optional additional connection arguments, as described in [1].

Examples:
    ```
    >>> dbconfig = {
    >>>     "database": "test",
    >>>     "user":     "joe",
    >>> }
    >>> cnxpool = mysql.connector.pooling.MySQLConnectionPool(pool_name = "mypool",
    >>>                                                       pool_size = 3,
    >>>                                                       **dbconfig)
    ```

References:
    [1]: https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html
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         r0   r   MySQLConnectionPool.__init__  s    L *.)-0I&IE);)Ef)EF+-@EOOA
  %wOO%f%C'##%q ' rC   c                    U R                   $ )z(Returns the name of the connection pool.)r   r   s    r0   r    MySQLConnectionPool.pool_name       rC   c                    U R                   $ )z2Returns number of connections managed by the pool.)r   r   s    r0   r"   MySQLConnectionPool.pool_size  r   rC   c                    U R                   $ )z!Returns whether to reset session.)r   r   s    r0   r   !MySQLConnectionPool.reset_session  s     """rC   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)aT  Set the connection configuration for `MySQLConnectionAbstract` subclass instances.

This method sets the configuration used for creating `MySQLConnectionAbstract`
subclass instances such as `MySQLConnection`. See [1] for valid
connection arguments.

Args:
    **kwargs: Connection arguments - for a complete list of possible
              arguments, see [1].

Raises:
    PoolError: When a connection argument is not valid, missing
               or not supported by `MySQLConnectionAbstract`.

References:
    [1]: https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html
Nz$Connection configuration not valid: r$   )r)   rV   rW   r   r   r   r-   r   )r   r.   test_cnxerrs       r0   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     r0   r   "MySQLConnectionPool._set_pool_size  s5     >Y)99 J#$&  $rC   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-   rK   CNX_POOL_MAXNAMESIZEr   )r   r    s     r0   r   "MySQLConnectionPool._set_pool_name)  sP     $$Y// ;yk9V!WXXy>00 ;yk!GHH#rC   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.
;Connection instance not subclass of MySQLConnectionAbstractFblock'Failed adding connection; queue is fullN)r+   r   r   r   putr   Fullr   r   r   s      r0   _queue_connection%MySQLConnectionPool._queue_connection7  sb     #//M 	POO51zz 	PEFCO	Ps   = A"AA"c                0   [            U R                  (       d  [        S5      eU R                  R	                  5       (       a  [        S5      eU(       dh  [        S0 U R                  D6n U R                  (       a/  U R                  S   (       a  UR                  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  Adds 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.

Args:
    cnx: The `MySQLConnectionAbstract` subclass object to be added to
         the pool. If this argument is missing (aka `None`), the pool
         creates a new connection and adds it.

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   fullrV   r   server_versionr   rG   r   pool_config_versionr+   r   r   r   s     r0   r   "MySQLConnectionPool.add_connectionJ  s    & "## HII##%% IJJ1 0 01++ ,,Z8..:/)  +/*>*>'!#77#U  ""3'= "!(   ) "!s2   A#D+A C7+AD7
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)aN  Gets 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.

Returns:
    A `PooledMySQLConnection` instance.

Raises:
    PoolError: On errors.
Fr   z)Failed getting connection; pool exhaustedNr$   )r)   r   r&   r   Emptyr   is_connectedr   r   rW   r   	reconnectr   r   r   r   s      r0   r,   "MySQLConnectionPool.get_connection}  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       r0   _remove_connections'MySQLConnectionPool._remove_connections  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"   rN   r    zOptional[str]r   rt   r.   r   r   r   r   )r   rN   )r   rt   )r.   r   r   r   )r"   rN   r   r   )r    r   r   r   )r   r   r   r   rp   )r   z!Optional[MySQLConnectionAbstract]r   r   r   )r   r   r   r   r   r   r   r    r"   r   r   r   r   r   r   r,   r   r   r$   rC   r0   r*   r*     s    4 #'#'	66 !6 !	6
 6 
6p     # #W<$$P&1(f"4HrC   r*   )r.   r   r   r   )r.   r   r   5Union[PooledMySQLConnection, MySQLConnectionAbstract])r   r   r.   r   r   r   )r.   r   r   r   ):r   
__future__r   r   rR   re	threadingtypesr   typingr   r   r   r   r	   r
   r   r   uuidr   dns.exceptionrv   dns.resolverru   r'   connection_cextr   
connectionr   	constantsr   r   errorsr   r   r   r   r   optionfilesr   	abstractsr   RLockr)   r   r   compiler   r(   r   __annotations__r   r1   re   rV   r%   r   r*   r$   rC   r0   <module>r     sF  : < "   	   S S S  N1 ( ;  +2 (   ZZ 78 B'/OoGW5X .  57 1 6:ZIZI:ZIzy,y,y,:y,x0Q( Q(hI IM  N  s#   C, C: ,C76C7:DD