XylotrechusZ
�
���g]0 � �� � d Z ddlZddlmZ ddlZddlZddlm Z ddl
mZ ej � Z
dZdZ ej d � Zd
� Z G d� de� Z G d
� de� Zy# e$ r ddlZY �\w xY w)z6Implementing pooling of connections to MySQL servers.
� N)�uuid4� )�errors)�MySQLConnection� �@ z[^a-zA-Z0-9._:\-*$#]c � � g }dD ] } |j t | | � � �" |st j d� �dj |� S # t $ r Y �Vw xY w)z�Generate 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.
)�host�port�user�databasez.Failed generating pool name; specify pool_name�_)�append�str�KeyErrorr � PoolError�join)�kwargs�parts�keys �n/opt/hc_python/lib64/python3.12/site-packages/../../../lib/python3.12/site-packages/mysql/connector/pooling.py�generate_pool_namer / sl � �
�E�3�� ��L�L��V�C�[�)�*� 4� ����<�>� >� �8�8�E�?��� � �� �s �A� A�Ac �8 � e Zd ZdZd� Zd� Zd� Zd� Zed� � Z y)�PooledMySQLConnectiona 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 � � t |t � st d� �t |t � st d� �|| _ || _ y)z�Initialize
The pool argument must be an instance of MySQLConnectionPoll. cnx
if an instance of MySQLConnection.
z$pool should be a MySQLConnectionPoolzcnx should be a MySQLConnectionN)�
isinstance�MySQLConnectionPool�AttributeErrorr � _cnx_pool�_cnx)�self�pool�cnxs r �__init__zPooledMySQLConnection.__init__V sG � � �$� 3�4� �6�8�
8��#��/� �1�3�
3������ � c �. � t | j |� S )z0Calls attributes of the MySQLConnection instance)�getattrr )r! �attrs r �__getattr__z!PooledMySQLConnection.__getattr__e s � ��t�y�y�$�'�'r% c � � | j }| j j r|j � | j j |� d| _ y)aY 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 �closezPooledMySQLConnection.closei s? � � �i�i���>�>�'�'��������%�%�c�*��� r% c �, � t j d� �)z&Configuration is done through the poolzLConfiguration for pooled connections should be done through the pool itself.)r r )r! r s r �configzPooledMySQLConnection.configz s � ����
/�
�
r% c �. � | j j S �z&Return the name of the connection pool)r � pool_name�r! s r r3 zPooledMySQLConnection.pool_name� s � � �~�~�'�'�'r% N)
�__name__�
__module__�__qualname__�__doc__r$ r) r. r0 �propertyr3 � r% r r r H s/ � ��
�(��"
� �(� �(r% r c �t � e Zd ZdZdd�Zed� � Zed� � Zed� � Zd� Z d� Z
d � Zd
� Zdd�Z
d� Zd
� Zy)r z*Class defining a pool of MySQL connectionsNc � � d| _ d| _ || _ | j |� | j |xs t di |��� i | _ t j | j � | _ t � | _ |rJ | j di |�� d}|| j k r&| j � |dz
}|| j k r�%yyy)z�Initialize
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! � pool_sizer3 �pool_reset_sessionr �cnts r r$ zMySQLConnectionPool.__init__� s� � � ������0������I�&����I�E�);�)E�f�)E�F�����+�+�d�o�o�6���$�w�����D�O�O�%�f�%��C�����'��#�#�%��q��� ����'� r% c � � | j S r2 )r>