
    bh-e                       % 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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Jr  SSKJr   SSKrSSKrSrS
SKJrJrJ r J!r!J"r"  S
SK#J$r$J%r%J&r&  SSK'J(r(  \(       a  SSK)J*r*  \RV                  " 5       r,Sr-Sr.\R^                  " S5      r0\(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)#z5Implementing pooling of connections to MySQL servers.    )annotationsN)TracebackType)TYPE_CHECKINGAnyDictNoReturnOptionalTupleTypeUnion)UUIDuuid4)CNX_POOL_ARGSTF   )ErrorInterfaceErrorNotSupportedError	PoolErrorProgrammingError)DEFAULT_CONFIGURATIONgenerate_pool_nameread_option_files   )MySQLConnection)MySQLConnectionAbstract    @   z[^a-zA-Z0-9._:\-*$#]zUnion[type, Tuple[type, ...]]MYSQL_CNX_CLASSzDict[str, MySQLConnectionPool]_CONNECTION_POOLSPooledMySQLConnectionc                 4  #    SU ;   a  U S   O
[        S0 U D6nU[        ;  aL  [        S0 U D6nUR                  5       I Sh  vN   [         ISh  vN   U[        U'   SSS5      ISh  vN   OI[        [        U   [        5      (       a-  [        U   R                  nSU ;   a  U S   U:w  a  [        S5      e [        U   R                  5       I Sh  vN $  N N Nr! , ISh  vN  (       d  f       N== f N$! [         a    [        SU S35      Sef = f7f)z!Return a pooled MySQL connection.	pool_nameN	pool_sizez)Size can not be changed for active pools.z%Failed getting connection from pool '' )r   r   MySQLConnectionPoolinitialize_poolCONNECTION_POOL_LOCK
isinstancer#   r   get_connectionAttributeErrorr   )kwargsr"   pool
check_sizes       d/var/www/home/psychics-availability/venv/lib/python3.13/site-packages/mysql/connector/aio/pooling.py_get_pooled_connectionr0   L   s      +f4{:L:Vv:V 
 ))",V,""$$$''+/i( (''	%i02E	F	F&y1;;
& VK%8J%FGHH&y1@@BBB 	%'''' C 3I;a@
	s   ?DCDCD
CD)C*AD9C: C8C: DDDC5$C'%C51D8C: :DDc                   #    U R                  5       n US   nUS	 1 Sk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       H  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I Sh  vN s  s  $    M     [        S5      e! [         a    [        S5      Sef = f N3! [*         a     M  f = f7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>	   hostportuserdatabasepasswordpriorityr"   r#   unix_socketr   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hasattrgetr   r)   intr   sortedappendrangerandomrandintpopupdateconnectr   )r,   configr2   support_cnx_argspriority_countserverdiffarglstserver_directoryserver_priority_listr8   failover_list_lastindex
new_configs                    r/   _get_failover_connectionre   i   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,$2z222 + ) G
HHQ  E9:DEF 3 sY   IH$ C
I'DI<I 
H>I I$H;;I>I  
I
I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      I Sh  vN 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  [%        S0 TD6I Sh  vN $  ['        U4S j[(         5       5      (       a  [+        S0 TD6I Sh  vN $  ST;   a  TS   TS'   TR                  S5        ST;   a  [/        S0 TD6n[1        S0 UD6I Sh  vN $ ST;   a  TS	 [3        U 0 TD6nUR1                  5       I Sh  vN   U$  GNF! [        R                  R                   a    [        STS    S35      Sef = fs  snf  N N! [,         a     Nf = f N NY7f)a  Creates 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`.

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 a `PooledMySQLConnection` instance.

Raises:
    `mysql.connector.errors.NotSupportedError`: if pooled connection is not supported
    for the Python version and OS that are being used.

Examples:
    A connection with the MySQL server can be established using either the
    `mysql.connector.aio.connect()` method or a `MySQLConnectionAbstract` subclass:
    ```
    >>> from mysql.connector.aio import MySQLConnection
    >>>
    >>> cnx1 = await mysql.connector.aio.connect(user='joe', database='test')
    >>> cnx2 = MySQLConnection(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 documentationr9   z<Using Unix domain sockets with DNS SRV lookup is not allowedr4   z;Specifying a port number with DNS SRV lookup is not allowedr2   zASpecifying multiple hostnames with DNS SRV look up is not allowedr3   SRVNz Unable to locate any hosts for 'r$   T)omit_final_dot)r3   r4   r8   weightc                    U S   U S   * 4$ )Nr8   rj   r%   r>   s    r/   r@   connect.<locals>.<lambda>  s    Qz]Qx[L$ArB   )rC   )r3   r4   c              3  ,   >#    U  H	  oT;   v   M     g 7fNr%   ).0rC   r,   s     r/   	<genexpr>connect.<locals>.<genexpr>   s     6f}s   read_default_fileoption_filesuse_purer%   )rT   r)   boolr   HAVE_DNSPYTHONr   dnsasyncresolverquery	exceptionDNSExceptionrP   targetto_textr4   r8   rj   sortre   anyr   r0   	NameErrorr   rV   r   )argsr,   rg   srv_recordsr2   srvrd   cnxs    `      r/   rV   rV      s    H (1F':fjj#Ggt$$GHH~ 8 
 F" N  V M   S  26:F6N	 # 1 1 7 7v NNK COOJJ..d.CHH #!jj	  	ABBJ
BJ3[#f+6(
z
 V-77776666/9&999 7 f$!'(;!<~

&'&00
*z***V:
4
*6
*C
++-Ja O}})) 	 26&>2B!D	"
 8
 :  + s   BI"!&H HH A*I"6I
I"$I
%I"*,I II A I"I+I"I I"H 2I	I"I 
II"II" I"c                     [         R                  n [        R                  S:X  a-  U R                  S:X  a  U R
                  S::  a  [        S5      eggg)zSRaises error if the Python version and OS combination is not
supported for Pooling.nt   
   zSPooled connections are not supported for Python versions lower than 3.11 on WindowsN)sysversion_infoosnamemajorminorr   )py_version_infos    r/   _check_supportr   7  sR     &&O	ww$?00A5/:O:OSU:U)
 	
 ;V5rB   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    iB  ah  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                    [        5         [        U[        5      (       d  [        S5      e[        U[        5      (       d  [        S5      eXl        X l        g)zwConstructor.
Args:
    pool: A `MySQLConnectionPool` instance.
    cnx: A `MySQLConnectionAbstract` subclass instance.
z/pool must be an instance of MySQLConnectionPoolz,cnx should be an instance of MySQLConnectionN)r   r)   r&   r+   r   	_cnx_pool_cnx)selfr-   r   s      r/   __init__PooledMySQLConnection.__init__Q  sG     	$ 344 !RSS#// !OPP.2-0	rB   c                   #    U $ 7frn   r%   r   s    r/   
__aenter__ PooledMySQLConnection.__aenter__`  s
     s   c                @   #    U R                  5       I S h  vN   g  N7frn   )close)r   exc_type	exc_value	tracebacks       r/   	__aexit__PooledMySQLConnection.__aexit__c  s      jjls   c                .    [        U R                  U5      $ )z0Calls attributes of the MySQLConnection instance)getattrr   )r   attrs     r/   __getattr__!PooledMySQLConnection.__getattr__k  s    tyy$''rB   c                  #    U R                   n U R                  R                  (       a5  UR                  5       I Sh  vN (       a  UR	                  5       I Sh  vN   U R                  R                  U5      I Sh  vN   SU l         g NL N1 N! U R                  R                  U5      I Sh  vN    SU l         f = f7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   can_reset_sessionis_connectedreset_sessionadd_connectionr   r   s     r/   r   PooledMySQLConnection.closeo  s      ii	~~//#:J:J:L4L4L'')))..//444DI	 5M)4$..//444DIs\   C.B BB BB  C>B?CB B CB>0B31B>>C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    r/   rW   PooledMySQLConnection.config  s     
 	
rB   c                .    U R                   R                  $ )zHReturns the name of the connection pool to which the connection belongs.)r   r"   r   s    r/   r"   PooledMySQLConnection.pool_name  s     ~~'''rB   )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   str)__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   staticmethodrW   propertyr"   __static_attributes__r%   rB   r/   r    r    B  sn    1% ! !	
 
(  	
 	
 ( (rB   c                      \ rS rSrSr   S         SS jjrSS 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S jrSrg)r&   i  z*Class defining a pool of MySQL connectionsNc                   [        5         SU l        SU l        X0l        U R	                  U5        U(       a  U R                  U5        X@l        [        R                  " U R                  5      U l	        [        5       U l        g)a  Constructor.

Initialize a MySQL connection pool with a maximum number of
connections set to `pool_size`.

NOTE: The coroutine `await cnxpool.initialize_pool(**dbconfig)` must be called
after initializing this class to open up the pool of required number of database
connections and making the instance of MySQLConnectionPool ready-to-use.
Contents of `dbconfig` is described in [1].

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.

Examples:
    ```
    >>> dbconfig = {
    >>>     "database": "test",
    >>>     "user":     "joe",
    >>> }
    >>> # initialize the MySQLConnectionPool instance
    >>> cnxpool = mysql.connector.aio.pooling.MySQLConnectionPool(
    >>>             pool_name = "mypool",
    >>>             pool_size = 3,
    >>> )
    >>> # Open up the pool of connections
    >>> await cnxpool.initialize_pool(**dbconfig)
    >>> # cnxpool is ready to be used ...
    ```
References:
    [1]: https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html
N)r   
_pool_size
_pool_name_reset_session_set_pool_size_set_pool_name_cnx_configasyncioQueue
_cnx_queuer   _config_version)r   r#   r"   pool_reset_sessionr,   s        r/   r   MySQLConnectionPool.__init__  sh    X 	)-)-$6I&	*+1BI--OOC
 &+WrB   c                  #    U R                   (       dC  [         ISh  vN   U R                  [        S0 U R                  D65        SSS5      ISh  vN   U R                  (       ae  U R
                  " S0 U R                  D6I Sh  vN   SnXR                  :  a/  U R                  5       I Sh  vN   US-  nXR                  :  a  M.  ggg N N}! , ISh  vN  (       d  f       N= f Nd N=7f)a  Opens the connection pool and fill with MySQL database connections.

This coroutine must be called after initializing an instance of MySQLConnectionPool
to make the build the pool of connections and make the instance ready to be used.

Args:
    **kwargs: Connection arguments, as described in [1].

References:
    [1]: https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html
Nr   r   r%   )r   r(   r   r   r   
set_configr   r   )r   cnts     r/   r'   #MySQLConnectionPool.initialize_pool  s      ++##$6$J9I9I$JK ,+//5D$4$4555C'))+++q '  ,+++ 6 ,sh   C0CC0%CC0C4C0C,(C00C.1C0C0C0C)CC)%C0.C0c                    U R                   $ )z(Returns the name of the connection pool.)r   r   s    r/   r"   MySQLConnectionPool.pool_name       rB   c                    U R                   $ )z2Returns number of connections managed by the pool.)r   r   s    r/   r#   MySQLConnectionPool.pool_size  r   rB   c                    U R                   $ )z!Returns whether to reset session.)r   r   s    r/   r   %MySQLConnectionPool.can_reset_session  s     """rB   c                b  #    U(       d  g [        S0 UD6I Sh  vN nUR                  5       I Sh  vN   [         ISh  vN   Xl        [	        5       U l        SSS5      ISh  vN   g NQ N; N. N! , ISh  vN  (       d  f       g= f! [         a  n[        SU 35      UeSnAff = f7f)aP  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%   )rV   
disconnectr(   r   r   r   	Exceptionr   )r   r,   r   errs       r/   r   MySQLConnectionPool.set_config  s      	S)&))C.."""++#) ',w$ ,++ *"++++  	SB3%HIsR	Ss   	B/B A,B A.B A0B A4B &A2'B +B/,B .B 0B 2B 4B:A=;BB 
B/B 
B,B''B,,B/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#$&  $rB   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+   rJ   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#rB   c                    [        U[        5      (       d  [        S5      e U R                  R	                  U5        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 MySQLConnectionAbstract'Failed adding connection; queue is fullN)r)   r   r   r   
put_nowaitr   	QueueFullr   r   r   s      r/   _queue_connection%MySQLConnectionPool._queue_connection'  s_     #//M 	POO&&s+   	PEFCO	Ps   > A#AA#c                  #    U R                   (       d  [        S5      eU R                  R                  5       (       a  [        S5      eU(       dt  [	        S0 U R                   D6I Sh  vN 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        g N! [         a     NRf = f7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   Ncompress)      r   z^Pool reset session is not supported with compression for MySQL server version 5.7.2 or earlierr   r%   )r   r   r   fullrV   r   get_server_versionr   rF   r   pool_config_versionr)   r   r   r   s     r/   r   "MySQLConnectionPool.add_connection8  s     $ DEE??!!EFF3$"2"233C''((4..09<+%  '+&:&:C#c?33Q  	s#- 4  s8   A&D(C6)D.AC8 2AD8
DDDDc                  #     U R                   R                  5       nUR                  5       I Sh  vN (       a  U R                  UR                  :w  aF   UR                  " S0 U R                  D6  UR                  5       I Sh  vN   U R                  Ul        [        X5      $ ! [        R                   a  n[	        S5      UeSnAff = f N NJ! [         a    U R                  U5        e f = f7f)aJ  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.
z)Failed getting connection; pool exhaustedNr%   )r   
get_nowaitr   
QueueEmptyr   r   r   r   _set_connection_optionsr   	reconnectr   r   r    r   s      r/   r*   "MySQLConnectionPool.get_connectioni  s     	R//,,.C
 &&(((##s'>'>>++?d.>.>?mmo%% '+&:&:C#$T// !! 	RGHcQ	R )
 &! &&s+s[   C2B& C2C#C2/C CC 
C2&C:CCC2C C//C2c                D  #    SnU R                   nUR                  5       (       aE   UR                  5       nUR                  5       I Sh  vN   US-  nUR                  5       (       a  ME  U$  N"! [        R
                   a    Us $ [         a    e [         a     NHf = f7f)a  Close all connections
This method closes all connections and returns the number of connections it closed.
This method should be used internally while cleaning-up the connection pool by closing each
and every active connection objects currently residing in the pool.

Returns:
    An integer defining the number of open connections closed during clean-up.
Raises:
    PoolError: On errors while fetching connections from the pool or while disconnecting
    an open connection.
r   Nr   )r   qsizer   r   r   r   r   r   )r   r   cnxqr   s       r/   _remove_connections'MySQLConnectionPool._remove_connections  s      jjll
oo'nn&&&q	 jjll 
 '%% 
  sL   $B #A/ 
A-	A/ B +B -A/ /BB BB BB c                >   #    U R                  5       I Sh  vN $  N7f)a  Cleans up the connection pool
This public method gracefully shuts down the connection pool by disconnecting all of the
open connections currently active in the pool.

Returns:
    An integer defining the number of open connections closed while shutting down the pool.
Raises:
    PoolError: On errors while fetching connections from the pool or while disconnecting
    an open connection.
N)r  r   s    r/   
close_poolMySQLConnectionPool.close_pool  s      --////s   )r   r   r   r   r   r   )r   NT)
r#   rN   r"   zOptional[str]r   ru   r,   r   r   r   r   r   )r   rN   )r   ru   )r,   r   r   r   )r#   rN   r   r   )r"   r   r   r   )r   r   r   r   rn   )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  r   r%   rB   r/   r&   r&     s    4 #'#'	8-8- !8- !	8-
 8- 
8-t,     # #S6$
$P$ 8</$4/$	/$b0>:0rB   r&   )r,   r   r   r    )r,   r   r   5Union[PooledMySQLConnection, MySQLConnectionAbstract])r   r   r,   r   r   r  r   ):r   
__future__r   r   r   rR   rer   typesr   typingr   r   r   r   r	   r
   r   r   uuidr   r   mysql.connector.constantsr   dns.asyncresolverrw   dns.exceptionrv   ImportErrorerrorsr   r   r   r   r   poolingr   r   r   
connectionr   	abstractsr   Lockr(   r   r   compiler   r   __annotations__r   r0   re   rV   r   r    r&   r%   rB   r/   <module>r     s  : < "  	  	 
  S S S  3 N  S R '2 ||~   ZZ 78 2A1C. C46 1 6:XIXI:XIvppp:pf
L( L(^_0 _0C  Ns   C% %C0/C0