HEX
Server: Microsoft-IIS/10.0
System: Windows NT ITPWINWEBSVR22 10.0 build 20348 (Windows Server 2022) AMD64
User: www.conferencesearch.co.uk (0)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: D:/Python311/Lib/site-packages/mysqlx/__pycache__/connection.cpython-311.pyc
�

�nc
��	�n�dZ	ddlZdZejejejd�Zeed��rejnej	ed<eed��oej
Zn#e$r	dZdZiZYnwxYwddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZ	ddlZddlZdZn
#e$rdZYnwxYwdd	lmZmZdd
lm Z ddl!m"Z"ddl#m$Z$m%Z%m&Z&d
dl'm(Z(m)Z)m*Z*d
dl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3d
dl4m5Z5d
dl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<d
dl=m>Z>m?Z?m@Z@d
dlAmBZBd
dlCmDZDmEZEmFZFmGZGmHZHd
dlImJZJmKZKmLZLmMZMmNZNd
dlOmPZPmQZQmRZRejS�Td��ddlUmVZVmWZWmXZXmYZYddlZm[Z[ddl\m]Z]m^Z^dddd�Z_dZ`d Zad!Zbd"Zcd#Zdd$Zed%Zfejgd&��Zhd'Zid'Zjd(Zkd)Zld*Zmd*Znd+Zod)Zpelelekekenememeod,�Zqd-epiZrejgd.��Zsejgd/ejt��Zuejgd0ejt��Zvejgd1��Zwgd2�Zxexgd3�zZyejzd4��Z{d5�Z|d6�Z}Gd7�d8��Z~d9�ZGd:�d;e���Z�Gd<�d=��Z�Gd>�d?��Z�Gd@�dAe���Z�GdB�dCej���Z�GdD�dE��Z�GdF�dG��Z�GdH�dI��Z�dJ�Z�dK�Z�dL�Z�dTdM�Z�dN�Z�dO�Z�dP�Z�dQ�Z�dR�Z�dS�Z�dS)Uz4Implementation of communication for MySQL X servers.�NT)�TLSv1�TLSv1.1�TLSv1.2�PROTOCOL_TLS�TLSv1.3�HAS_TLSv1_3F)�datetime�	timedelta��wraps)�JSONDecodeError)�	parse_qsl�unquote�urlparse�)�MySQL41AuthPlugin�PlainAuthPlugin�Sha256MemoryAuthPlugin)�COMPRESSION_ALGORITHMS�DEPRECATED_TLS_VERSIONS�OPENSSL_CS_NAMES�SUPPORTED_TLS_VERSIONS�TLS_CIPHER_SUITES�Auth�Compression�SSLMode��Schema)�InterfaceError�NotSupportedError�OperationalError�	PoolError�ProgrammingError�TimeoutError)�escape�get_item_or_attr�iani_to_openssl_cs_name)�Protobuf)�HAVE_LZ4�	HAVE_ZSTD�
MessageReader�
MessageWriter�Protocol)�
BaseResult�	DocResult�Result�	RowResult�	SqlResult)�AddStatement�SqlStatement�quote_identifier�..)�DUPLICATED_IN_LIST_ERROR�TLS_VER_NO_SUPPORTED�TLS_VERSION_DEPRECATED_ERROR�TLS_VERSION_ERROR)�linux_distribution)�LICENSE�VERSIONz�This session was closed because the connection has been idle for too long. Use 'mysqlx.getSession()' or 'mysqlx.getClient()' to create a new one.z<This session was closed because the server is shutting down.z�This session was closed because the connection has been killed in a different session. Use 'mysqlx.getSession()' or 'mysqlx.getClient()' to create a new one.)i�iai'zDROP DATABASE IF EXISTS {}z CREATE DATABASE IF NOT EXISTS {}zLSELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '{}'zSELECT @@version�c�xz[^a-zA-Z0-9._:\-*$#]i�� i@B�<ii�Q)z[WinError 10053]z
[Errno 32]z[WinError 10061]z[Errno 111]z[WinError 10060]z
[Errno 11001]z
[Errno -2]z
Access deniedr>z,(?![^\(\)]*\))z!^\(address=(.+),priority=(\d+)\)$z^\(address=(.+)[,]*\)$z"^([a-zA-Z][a-zA-Z0-9+\-.]+)://(.*))�ssl-cert�ssl-ca�ssl-key�ssl-crl�tls-versions�tls-ciphersuites)�user�password�schema�host�port�routers�socket�ssl-mode�auth�use-pure�connect-timeout�connection-attributes�compression�compression-algorithms�dns-srv�mysqlxc���g}dD];}	|�t||�����,#t$rY�8wxYw|std���d�|��S)abGenerate a pool name.

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

    Args:
        **kwargs: Arbitrary keyword arguments with the connection arguments.

    Raises:
        PoolError: If the name can't be generated.

    Returns:
        str: The generated pool name.
    )rKrLrH�database�	client_idz.Failed generating pool name; specify pool_name�_)�append�str�KeyErrorr"�join)�kwargs�parts�keys   �3D:\Python311\Lib\site-packages\mysqlx/connection.py�generate_pool_namerd�s���
�E�@����	��L�L��V�C�[�)�)�*�*�*�*���	�	�	��D�	�����J��H�I�I�I��8�8�E�?�?�s�(1�
>�>c�p�|r1t|t��rt�|��dSdSdS)z�Update the timeout penalties directory.

    Update the timeout penalties by error dictionary used to deactivate a pool.
    Args:
        penalty_dict (dict): The dictionary with the new timeouts.
    N)�
isinstance�dict�_TIMEOUT_PENALTIES_BY_ERR_NO�update)�penalty_dicts rc�!update_timeout_penalties_by_errorrk�sK���:�
�<��6�6�:�$�+�+�L�9�9�9�9�9�:�:�:�:�c�X�eZdZdZd�Zefd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zd
S)�SocketStreamzImplements a socket stream.c�>�d|_d|_d|_d|_dS)NF)�_socket�_is_ssl�
_is_socket�_host��selfs rc�__init__zSocketStream.__init__�s"�������������
�
�
rlc��|�|dz}	tj||��|_|d|_n�#t$r�	tjtj��|_|j�|��|j�|��d|_n#t$rtd��d�wxYwYnwxYw|j�d��dS)z�Connects to a TCP service.

        Args:
            params (tuple): The connection parameters.

        Raises:
            :class:`mysqlx.InterfaceError`: If Unix socket is not supported.
        N��rTzUnix socket unsupported)rN�create_connectionrprs�
ValueError�AF_UNIX�
settimeout�connectrr�AttributeErrorr)ru�params�connect_timeouts   rcr}zSocketStream.connect�s����	5�-��4�O�
	J�!�3�F�O�L�L�D�L����D�J�J���	J�	J�	J�
J�%�}�V�^�<�<�����'�'��8�8�8���$�$�V�,�,�,�"&�����!�
J�
J�
J�$�%>�?�?�T�I�
J���� ��	J����	
�����%�%�%�%�%s'�'1�
B<�AB�B<�B6�6B<�;B<c� �|j�td���g}|dkr\|j�|��}|dkrtd���|�|��|t|��z}|dk�\d�|��S)z�Receive data from the socket.

        Args:
            count (int): Buffer size.

        Returns:
            bytes: The data received.
        N�MySQLx Connection not availablerrlzUnexpected connection close)rpr!�recv�RuntimeErrorr\�lenr_)ru�count�buf�datas    rc�readzSocketStream.reads����<�	F�"�#D�E�E�E����a�i�	��<�$�$�U�+�+�D��s�{�
B�"�#@�A�A�A��J�J�t�����S��Y�Y��E��a�i�	��x�x��}�}�rlc��|j�td���	|j�|��dS#t$r}td|����|�d}~wwxYw)z_Send data to the socket.

        Args:
            data (bytes): The data to be sent.
        Nr�zUnexpected socket error: )rpr!�sendall�OSError)rur��errs   rcr�zSocketStream.sendall s|���<�	F�"�#D�E�E�E�	O��L� � ��&�&�&�&�&���	O�	O�	O�"�#D�s�#D�#D�E�E�3�N�����	O���s�4�
A�A�Ac���|jsdS	|j�tj��|j���n#t
$rYnwxYwd|_dS)zClose the socket.N)rp�shutdownrN�	SHUT_RDWR�closer�rts rcr�zSocketStream.close-ss���|�	��F�	��L�!�!�&�"2�3�3�3��L��� � � � ���	�	�	��D�	��������s�=A	�	
A�Ac�.�|���dS�N�r�rts rc�__del__zSocketStream.__del__9����
�
�����rlc��ts#|���td���|�|sLtj��}|t
jkrd|_|t
jkrtj	|_
n�|�d���|d}	ts!|	dkrt|��dkr|d}	t|	}
tj|
��}|	dkrZd	|vr|xjtjzc_d
|vr|xjtjzc_d|vr|xjtjzc_|rm	|�|��tj|_
nE#t,tjf$r,}|���t1d|����|�d}~wwxYw|rm	|�|��tj|_nE#t,tjf$r,}|���t1d
|����|�d}~wwxYw|r]	|�||��nE#t,tjf$r,}|���t1d|����|�d}~wwxYw|r<|�d�t=|d|������	|�|j |j!���|_ n(#tj"$r}t1|���|�d}~wwxYw|t
jk�rd|_g}tFj$dkr
|j!dvrddg}tKj&|j!��}
|�'|
dg|
dz��d}g}|D]p}	tj(|j �)��|��d}n>#tj"$r,}|�*tW|����Yd}~�id}~wwxYw|s9|���t1dd�|�������d|_,|j �-��}	|	dvr"d|	�d�}t]j/|t`��dSdS)axSet SSL parameters.

        Args:
            ssl_protos (list): SSL protocol to use.
            ssl_mode (str): SSL mode.
            ssl_ca (str): The certification authority certificate.
            ssl_crl (str): The certification revocation lists.
            ssl_cert (str): The certificate.
            ssl_key (str): The certificate key.
            ssl_ciphers (list): SSL ciphersuites to use.

        Raises:
            :class:`mysqlx.RuntimeError`: If Python installation has no SSL
                                          support.
            :class:`mysqlx.InterfaceError`: If the parameters are invalid.
        z&Python installation has no SSL supportNFT��reverserrrrrrzInvalid CA Certificate: z
Invalid CRL: zInvalid Certificate/Key: �:)�server_hostname�nt)�	localhost�	127.0.0.1r�r�z"Unable to verify server identity: �, )rrzThis connection is using zZ which is now deprecated and will be removed in a future release of MySQL Connector/Python)1�
SSL_AVAILABLEr�r��ssl�create_default_contextr�VERIFY_IDENTITY�check_hostname�REQUIRED�	CERT_NONE�verify_mode�sort�TLS_V1_3_SUPPORTEDr��TLS_VERSIONS�
SSLContext�options�
OP_NO_TLSv1_2�
OP_NO_TLSv1_1�OP_NO_TLSv1�load_verify_locations�
CERT_REQUIRED�IOError�SSLErrorr�VERIFY_CRL_CHECK_LEAF�verify_flags�load_cert_chain�set_ciphersr_r'�wrap_socketrprs�CertificateError�os�namerN�
gethostbyaddr�extend�match_hostname�getpeercertr\r]rq�version�warnings�warn�DeprecationWarning)ru�
ssl_protos�ssl_mode�ssl_ca�ssl_crl�ssl_cert�ssl_key�ssl_ciphers�context�tls_version�ssl_protocolr��	hostnames�aliases�match_found�errs�hostname�warn_msgs                  rc�set_sslzSocketStream.set_ssl<s"��4�	I��J�J�L�L�L��G�H�H�H��	7�Z�	7��0�2�2�G��7�2�2�
/�).��&��7�+�+�
4�&)�m��#���O�O�D�O�)�)�)�$�Q�-�K�&�
,��9�,�
,��
�O�O�a�'�
,�
)��m��'��4�L��n�\�2�2�G��i�'�
7��J�.�9��O�O�s�'8�8�O�O��J�.�9��O�O�s�'8�8�O�O��*�,�7��O�O�s��6�O�O��	P�
P��-�-�f�5�5�5�&)�&7��#�#���S�\�*�
P�
P�
P��
�
����$�%E��%E�%E�F�F�C�O�����
P�����	E�
E��-�-�g�6�6�6�'*�'@��$�$���S�\�*�
E�
E�
E��
�
����$�%:�S�%:�%:�;�;��D�����
E�����	Q�
Q��'�'��'�:�:�:�:���S�\�*�
Q�
Q�
Q��
�
����$�%F��%F�%F�G�G�S�P�����
Q�����	�������0��A���L�L�M�M�
�
�
�	4�"�.�.�t�|�T�Z�.�X�X�D�L�L���#�	4�	4�	4� �C��*�*��3�����	4�����w�.�.�	�%)�G�"��I��w�$��
7�4�:�1K�#K�
7�(�+�6�	��*�4�:�6�6�G����g�a�j�\�G�A�J�6�7�7�7��K��D�%�
�
���
�&�t�|�'?�'?�'A�'A�8�L�L�L�
#'�K��E��	�+�*�*�*��K�K��C���)�)�)�)�)�)�)�)�����*����
�
��
�
����$�J����4���J�J��������l�*�*�,�,���.�.�	8�)�K�)�)�)�
�

�M�(�$6�7�7�7�7�7�
	8�	8sx�&E,�,F.�'F)�)F.�4&G�H�1'H�H�#H:�:I<�'I7�7I<�>&K%�%L
�4L�L
�,N;�;O6�
"O1�1O6c��|jS)zpVerifies if SSL is being used.

        Returns:
            bool: Returns `True` if SSL is being used.
        )rqrts rc�is_sslzSocketStream.is_ssl�s���|�rlc��|jS)z�Verifies if socket connection is being used.

        Returns:
            bool: Returns `True` if socket connection is being used.
        )rrrts rc�	is_socketzSocketStream.is_socket�s����rlc��|jp|jS)zvVerifies if connection is secure.

        Returns:
            bool: Returns `True` if connection is secure.
        )rqrrrts rc�	is_securezSocketStream.is_secure�s���|�.�t��.rlc��|jduS)zrVerifies if connection is open.

        Returns:
            bool: Returns `True` if connection is open.
        N)rprts rc�is_openzSocketStream.is_open�s���|�4�'�'rlN)�__name__�
__module__�__qualname__�__doc__rv�_CONNECT_TIMEOUTr}r�r�r�r�r�r�r�r�r��rlrcrnrn�s�������%�%����/?�&�&�&�&�0���(O�O�O�
�
�
����~8�~8�~8�@������/�/�/�(�(�(�(�(rlrnc�<��t����fd���}|S)z�Decorator used to catch OSError or RuntimeError.

    Raises:
        :class:`mysqlx.InterfaceError`: If `OSError` or `RuntimeError`
                                        is raised.
    c���	t|ttf��r/|���rt	|������	|g|�Ri|��}t|t��r�|���}|D]m}|dtvr\t|d}d|d�d|��|df}t|ttf��r|�	|��n�n|S#ttttf$�rI}�	j
dk�r#|�r t|dt���r|d���}|r�|d}t|d}d|d�d|��|df}t|t��rS|j���|ddkr.t#���|jt	|���t|ttf��r|�	|��|���t	|�|�|����d}~wwxYw)	zWrapper function.�codezConnection close: �msgz: �get_column_metadatarr>N)rf�
Connection�PooledConnection�is_server_disconnectedr�get_disconnected_reasonr.�get_warnings�CONNECTION_CLOSED_ERROR�set_server_disconnectedr�r�r$r�r2�pool�remove_connections�PoolsManager�set_pool_unavailable�
disconnect)
ru�argsr`�result�warnsr��	error_msg�reasonr��funcs
         �rc�wrapperz(catch_network_exception.<locals>.wrapper�s����.	��4�*�.>�!?�@�@�
F��/�/�1�1�
F�%�d�&B�&B�&D�&D�E�E��T�$�0��0�0�0��0�0�F��&�*�-�-�
��+�+�-�-��!�	�	�D��F�|�'>�>��$;�D��L�$I�	�K��e��K�K�	�K�K� ��L�"��&�d�Z�9I�,J�K�K�A� �8�8��@�@�@�����M�����|�D�	�	�	��
�!6�6�
;��
;��t�A�w�	�2�2�
;�
�Q��,�,�.�.���;� ��8�D� 7��V�� E�I�G�T�%�[�G�G�I�G�G��V���F�"�$�(8�9�9���	�4�4�6�6�6���<�4�/��(�N�N�?�?� $�	�>�6�+B����"�$��5E�(F�G�G�=��4�4�V�<�<�<��O�O�%�%�%�(�&�1�s�:��O�O���������5	���s�C1C5�5I�EI�Ir)r�r�s` rc�catch_network_exceptionr��s6����4�[�[�0�0�0�0��[�0�d�Nrlc�4��eZdZdZ�fd�Zd�Zd�Zd�Z�xZS)�Routerz�Represents a set of connection parameters.

    Args:
       settings (dict): Dictionary with connection settings
    .. versionadded:: 8.0.20
    c���t�����|�|��|�dd��|d<dS)N�	availableT)�superrvri�get)ru�connection_params�	__class__s  �rcrvzRouter.__init__#sJ���
�����������%�&�&�&� �H�H�[�$�7�7��[���rlc��|dS)z�Verifies if the Router is available to open connections.

        Returns:
            bool: True if this Router is available else False.
        r�r�rts rcr�zRouter.available(s���K� � rlc��d|d<dS)z1Sets this Router unavailable to open connections.Fr�Nr�rts rc�set_unavailablezRouter.set_unavailable0s��!��[���rlc�:�d|vr|dS|d|dfS)z�Verifies if the Router is available to open connections.

        Returns:
            tuple: host and port or socket information tuple.
        rNrKrLr�rts rc�get_connection_paramszRouter.get_connection_params4s.���t��	"���>�!��V��d�6�l�+�+rl)	r�r�r�r�rvr�rr�
__classcell__�rs@rcr�r�so���������8�8�8�8�8�
!�!�!�"�"�"�,�,�,�,�,�,�,rlr�c�<�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	S)
�
RouterManagerz�Manages the connection parameters of all the routers.

    Args:
        Routers (list): A list of Router objects.
        settings (dict): Dictionary with connection settings.
    .. versionadded:: 8.0.20
    c��||_||_d|_d|_i|_g|_|���dS)NrT)�_routers�	_settings�_cur_priority_idx�
_can_failover�_routers_directory�routers_priority_list�_ensure_priorities)rurM�settingss   rcrvzRouterManager.__init__HsH����
�!���!"���!���"$���%'��"����!�!�!�!�!rlc�$�d}|jD];}|�dd��}|�|dz
}d|d<�%|dkrtdd����<d|cxkrt|j��krnntdd	���|j�d
�d���|jD]s}|d}||jvr3t
|��g|j|<|j�|���F|j|�t
|�����tdS)
zuEnsure priorities.

        Raises:
            :class:`mysqlx.ProgrammingError`: If priorities are invalid.
        r�priorityNr�dz(The priorities must be between 0 and 100��\You must either assign no priority to any of the routers or give a priority for every router�c��|dS)Nrr���xs rc�<lambda>z2RouterManager._ensure_priorities.<locals>.<lambda>js
���:��rlT)rbr�)	rrr#r�r�rr�rr\)ru�priority_count�routerrs    rcrz RouterManager._ensure_prioritiesRs������m�	Y�	Y�F��z�z�*�d�3�3�H��
Y��!�#��%(��z�"�"��C��
Y�&�'Q�SW�X�X�X�
Y�
�~�	�	�	�	��D�M� 2� 2�	�	�	�	�	�"���	��
�	
�
���6�6���E�E�E��m�	I�	I�F��j�)�H��t�6�6�
I�5;�F�^�^�4D��'��1��*�1�1�(�;�;�;�;��'��1�8�8�����H�H�H�H�
	I�	Irlc�8�|j|}d�|D��}|S)z�Get a list of the current available routers that shares the given priority.

        Returns:
            list: A list of the current available routers.
        c�:�g|]}|����|��Sr�)r�)�.0r!s  rc�
<listcomp>z8RouterManager._get_available_routers.<locals>.<listcomp>|s)��N�N�N�&�6�;K�;K�;M�;M�N�v�N�N�Nrl�r)rur�router_lists   rc�_get_available_routersz$RouterManager._get_available_routersus*���-�h�7��N�N�K�N�N�N���rlc���|�|��}|sdSt|��dkr|dSt|��dz
}tjd|��}||S)z{Get a random router from the group with the given priority.

        Returns:
            Router: A random router.
        Nrr)r(r��random�randint)rurr'�last�indexs     rc�_get_random_connection_paramsz+RouterManager._get_random_connection_paramssq���1�1�(�;�;���	��4��{���q� �	"��q�>�!��;���!�#����q�$�'�'���5�!�!rlc��|jS)z�Returns the next connection parameters.

        Returns:
            bool: True if there is more server to failover to else False.
        )rrts rc�can_failoverzRouterManager.can_failover�s
���!�!rlc�X�|jskd|_|j���}|j�dd��|d<|j�dd��|d<t|��S|j|j}t|j��}d}|r�|�	|��}|�|j|kr<|j|dz
kr-t|�
|����d	krd|_n/|xjdz
c_|j|kr|j|j}|��|S)
zvReturns the next connection parameters.

        Returns:
            Router: with the connection parameters.
        FrKr�rL�$�TNr�)rrr�copyrr�rrr�r.r()ru�router_settings�cur_priority�routers_priority_len�searchr!s      rc�get_next_routerzRouterManager.get_next_router�sY���}�	+�!&�D��"�n�1�1�3�3�O�&*�n�&8�&8���&M�&M�O�F�#�&*�n�&8�&8���&G�&G�O�F�#��/�*�*�*��1�$�2H�I��"�4�#=�>�>�����	R��7�7��E�E�F��
�T�%;�?S�%S�
��*�.B�Q�.F�F�/��D�7�7��E�E�F�F��J�/�*/�D�&��
�"�"�a�'�"�"��%�(<�<�
R�#�9�$�:P�Q���	R� �
rlc��|jS)z�Returns the directory containing all the routers managed.

        Returns:
            dict: Dictionary with priorities as connection settings.
        r&rts rc�get_routers_directoryz#RouterManager.get_routers_directory�s
���&�&rlN)r�r�r�r�rvrr(r.r0r9r;r�rlrcrr?s���������"�"�"�!I�!I�!I�F���"�"�"� "�"�"�!�!�!�F'�'�'�'�'rlrc��eZdZdZd�Zd�Zd�Zd�Zd�Zd$d�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zed���Zed���Zed���Zed���Zed���Zed$d���Zed���Zed���Zed���Zed���Zed���Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%dS)%r�zkConnection to a MySQL Server.

    Args:
        settings (dict): Dictionary with connection settings.
    c��||_t��|_d|_d|_|�d��|_|�d��|_|�d��|_d|_	|�dg��|_
d|vrL|drD|j
�|�d��|�dd��d���t|j
|��|_
|�dt��|_|jd	krd|_d	|_g|_d
|_d|_d|_dS)NrHrIrJrMrKrL�rKrLrRrTF)rrn�stream�protocol�	keep_openr�_user�	_password�_schema�_active_resultrr\r�router_managerr��_connect_timeout�
_stmt_counter�_prepared_stmt_ids�_prepared_stmt_supported�_server_disconnected�_server_disconnected_reason)rurs  rcrvzConnection.__init__�sK�� ��
�"�n�n�����
�����\�\�&�)�)��
�!���j�1�1����|�|�H�-�-���"��� ���Y��3�3��
��X��	�(�6�"2�	��M� � �$�L�L��0�0�$�L�L���6�6���
�
�
�,�D�M�8�D�D��� (���->�@P� Q� Q���� �A�%�	)�%)�D�!����"$���(,��%�$)��!�+/��(�(�(rlc�X�|j�"|j���d|_dSdS)zFetch active result.N)rE�	fetch_allrts rc�fetch_active_resultzConnection.fetch_active_result�s:����	'���)�)�+�+�+�"&�D����	'�	'rlc��||_dS)aSet active result.

        Args:
            `Result`: It can be :class:`mysqlx.Result`,
                      :class:`mysqlx.BufferingResult`,
                      :class:`mysqlx.RowResult`, :class:`mysqlx.SqlResult` or
                      :class:`mysqlx.DocResult`.
        N)rE�rur�s  rc�set_active_resultzConnection.set_active_result�s��%����rlc�<�d}|j����r�	|j���}|j�|���|j��t|j��}t|j��}t||��|_
|j
���j}|rd�|D��ni}|�
|��d|jvr(|jd}|j
�|���|j�dt"j��}|j�d��}	|t"jkrdn|�|||	��}
|���|j
�|
��dS#t.t0f$r }|}|���Yd}~nd}~wwxYw|j������|�bt5|t6j��rHt;|j��dkrt?d|j�d	����t?d
|j�d����t;|j��dkrtAd|�����tAd
d���)a
Attempt to connect to the MySQL server.

        Raises:
            :class:`mysqlx.InterfaceError`: If fails to connect to the MySQL
                                            server.
            :class:`mysqlx.TimeoutError`: If connect timeout was exceeded.
        Nc�T�i|]%}t|d�����|��&S�r�)r&�lower)r$�caps  rc�
<dictcomp>z&Connection.connect.<locals>.<dictcomp>s1��U�U�U�C�%�c�6�2�2�8�8�:�:�C�U�U�Url�
attributes��session_connect_attrsrTrUrz9Connection attempt to the server was aborted. Timeout of z ms was exceededz8All server connection attempts were aborted. Timeout of z) ms was exceeded for each selected serverzCannot connect to host: �,Unable to connect to any of the target hostsi�)!rFr0r9r?r}rrGr+r,r-r@�get_capabilites�capabilities�_set_tls_capabilitiesr�set_capabilitiesrr�	PREFERRED�DISABLED�_set_compression_capabilities�
_authenticate�set_compressionr�r�rrfrN�timeoutr�rr$r)ru�errorr!�reader�writer�	caps_data�caps�
conn_attrsrT�
algorithms�	algorithmr�s            rcr}zConnection.connect�s������!�.�.�0�0�(	)�'
)��,�<�<�>�>����#�#��0�0�2�2�D�4I����'�t�{�3�3��&�t�{�3�3�� (��� 8� 8��
� �M�9�9�;�;�H�	�!��U�U�9�U�U�U�U����*�*�4�0�0�0� �4�=�0�U�!%��|�!<�J��M�2�2��2�T�T�T�#�m�/�/�
�{�?T�U�U��!�]�.�.�/G�H�H�
�#�k�&:�:��D�D��;�;��k�:�����"�"�$�$�$��
�-�-�i�8�8�8�����\�*�
)�
)�
)����&�&�(�(�(�(�(�(�(�(�����
)����M�!�.�.�0�0�(	)�Z�
	��E�6�>�!B�!B�
	��4�=�!�!�Q�&�
�"�J�"&�"7�J�J�J�����"�"�3�"�"�"���
�
�t�}����"�	E� �!C�E�!C�!C�D�D�D��K�T�R�R�Rs�FF2�2G#�G�G#c��|j�d��tjkrdS|j���r6|j�d��rt�d��dSd|vr#|���td���d}tj��dkrIt��\}}}	d|vo|�
d	��d
dk}n#t$rd}YnwxYwtjdkr%|s#|���t#d
���|j�d���|j�|j�dd��|j�dtj��|j�d��|j�d��|j�d��|j�d��|j�d����d|jvr*|jd}|j�|���dSdS)a�Set the TLS capabilities.

        Args:
            caps (dict): Dictionary with the server capabilities.

        Raises:
            :class:`mysqlx.OperationalError`: If SSL is not enabled at the
                                             server.
            :class:`mysqlx.RuntimeError`: If support for SSL is not available
                                          in Python.

        .. versionadded:: 8.0.21
        rONz(SSL not required when using Unix socket.�tlszSSL not enabled at serverF�LinuxzOracle Linux�.r�7)r3��	z<The support for SSL is not available for this Python versionT)rprFrCrErBrDrGrYrZ)rrrrbr?r��_LOGGER�warning�close_connectionr!�platform�systemr;�split�
IndexError�sys�version_infor�r@r`r�r�)rurk�is_ol7�distnamer�r[rls       rcr_z Connection._set_tls_capabilitiesAsg���=���Z�(�(�G�,<�<�	��F��;� � �"�"�	��}� � ��,�,�
L���� J�K�K�K��F����	@��!�!�#�#�#�"�#>�?�?�?����?����'�	�#5�#7�#7� �H�g�q�
�'�8�3�T��
�
�c�8J�8J�1�8M�QT�8T�����
�
�
�����
������i�'�	��	��!�!�#�#�#��N���
�	
�
�&�&�4�&�0�0�0������M���n�d�3�3��M���j�'�*:�;�;��M���h�'�'��M���i�(�(��M���j�)�)��M���i�(�(��M���0�1�1�	
�	
�	
��4�=�(�	M���|�4�J��M�*�*��*�L�L�L�L�L�	M�	Ms�
#C1�1D�?DNc���|�d��}|�=d}|tjkrt|���t�|��dSi}t
|t��r?|dddD])}d�|dddD��||d	<�*n7|jj	j
D]%}d
�|jjjD��||j<�&|�dg���d}|rXd�|D��}	�fd
�|	D��}
|
rtj|
d��}n!|tjkrtd���dS|�trd�vrd}nt rd�vrd}nd}|�vr=d}|tjkrt|���t�|��dS|j�d|i���|S)aSet the compression capabilities.

        If compression is available, negociates client and server algorithms.
        By trying to find an algorithm from the requested compression
        algorithms list, which is supported by the server.

        If no compression algorithms list is provided, the following priority
        is used:

        1) zstd_stream
        2) lz4_message
        3) deflate_stream

        Args:
            caps (dict): Dictionary with the server capabilities.
            compression (str): The compression connection setting.
            algorithms (list): List of requested compression algorithms.

        Returns:
            str: The compression algorithm.

        .. versionadded:: 8.0.21
        .. versionchanged:: 8.0.22
        rTNz8Compression requested but the server does not support it�value�obj�fldc�\�g|])}|ddd�d����*S)�scalar�v_stringr��utf-8)�decode�r$r�s  rcr%z<Connection._set_compression_capabilities.<locals>.<listcomp>�sD��0�0�0���(�O�J�/��8�?�?��H�H�0�0�0rl�arrayrbc�V�g|]&}|jjj�d����'S)r�)r�r�r�r�r�s  rcr%z<Connection._set_compression_capabilities.<locals>.<listcomp>�s>��-�-�-���L�)�/�6�6�w�?�?�-�-�-rlrnc�:�g|]}|tv�t|��Sr�)r)r$�items  rcr%z<Connection._set_compression_capabilities.<locals>.<listcomp>�s9��!�!�!���1�1�!�&�t�,�!�!�!rlc���g|]}|�v�|��	Sr�r�)r$r��server_algorithmss  �rcr%z<Connection._set_compression_capabilities.<locals>.<listcomp>�s$���W�W�W��T�EV�=V�W�t�W�W�WrlrzmThe connection compression is set as required, but none of the provided compression algorithms are supported.�zstd_stream�lz4_message�deflate_streamzFCompression requested but the compression algorithm negotiation failed)rT)rrr�r rvrwrfrgr�r�r�r�rbrrr*r)r@r`)rurkrTrm�compression_datar��compression_dictr�rn�client_algorithms�matchedr�s           @rcrcz(Connection._set_compression_capabilitiesws����2 �8�8�M�2�2���	�L�C��k�2�2�
-�'��,�,�,��O�O�C� � � ��4����&��-�-�	�'��0��7��>�
�
��0�0�!$�W��g�!6�w�!?�0�0�0� ��U��,�,�
�(�-�1�5�
�
��-�-�!$���!6�-�-�-� ���)�)�
-�0�0��b�A�A���	��	�!�!�&�!�!�!��
X�W�W�W�(9�W�W�W�G��	
�2�6�w�q�z�B�B�	�	��� 4�4�
�$�<�����t��	-��
-�]�.?�?�
-�)�	�	��
-�m�/@�@�
-�)�	�	�,�	��-�-�	�%�
��k�2�2�
*�$�S�)�)�)��O�O�C� � � ��4��
�&�&�K��3K�&�L�L�L��rlc�F�|j�d��}|rt|tjkr|���dS|tjkr|���dS|tjkr|���dSdS|j	�
��r|���dS	|���dS#t$rYnwxYw	|���dS#t$r}td|����|�d}~wwxYw)z#Authenticate with the MySQL server.rPNzrAuthentication failed using MYSQL41 and SHA256_MEMORY, check username and password or try a secure connection err:)rrr�PLAIN�_authenticate_plain�
SHA256_MEMORY�_authenticate_sha256_memory�MYSQL41�_authenticate_mysql41r?r�r)rurPr�s   rcrdzConnection._authenticate�su���}� � ��(�(���	��t�z�!�
-��(�(�*�*�*�*�*���+�+�
-��0�0�2�2�2�2�2����%�
-��*�*�,�,�,�,�,�
-�
-�
�[�
"�
"�
$�
$�	��$�$�&�&�&�&�&�
��*�*�,�,�,����"�
�
�
���
����

��0�0�2�2�2�2�2��!�
�
�
�$�E�?B�E�E����	�����
���s*�C�
C$�#C$�(C>�>
D �D�D c�P�t|j|j��}|j�|�����|j���}|j�|�|����|j�	��dS)z=Authenticate with the MySQL server using `MySQL41AuthPlugin`.N)
rrBrCr@�send_auth_start�	auth_name�read_auth_continue�send_auth_continue�	auth_data�read_auth_ok�ru�plugin�
extra_datas   rcr�z Connection._authenticate_mysql41�s���"�4�:�t�~�>�>���
�%�%�f�&6�&6�&8�&8�9�9�9��]�5�5�7�7�
��
�(�(��)9�)9�*�)E�)E�F�F�F��
�"�"�$�$�$�$�$rlc�<�|j���std���t|j|j��}|j�|���|�	�����|j�
��dS)z;Authenticate with the MySQL server using `PlainAuthPlugin`.z>PLAIN authentication is not allowed via unencrypted connection)r�N)r?r�rrrBrCr@r�r�r�r�)rur�s  rcr�zConnection._authenticate_plain�s����{�$�$�&�&�	� �P���
�!���T�^�<�<���
�%�%�f�&6�&6�&8�&8�F�DT�DT�DV�DV�%�W�W�W��
�"�"�$�$�$�$�$rlc�P�t|j|j��}|j�|�����|j���}|j�|�|����|j�	��dS)zBAuthenticate with the MySQL server using `Sha256MemoryAuthPlugin`.N)
rrBrCr@r�r�r�r�r�r�r�s   rcr�z&Connection._authenticate_sha256_memorys���'��
�D�N�C�C���
�%�%�f�&6�&6�&8�&8�9�9�9��]�5�5�7�7�
��
�(�(��)9�)9�*�)E�)E�F�F�F��
�"�"�$�$�$�$�$rlc��|jrG|j�|j��|j�|j��d|_dSdS)zrDeallocates statement.

        Args:
            statement (Statement): A `Statement` based type object.
        FN)�preparedr@�send_prepare_deallocate�stmt_idrI�remove)ru�	statements  rc�_deallocate_statementz Connection._deallocate_statementsZ����	'��M�1�1�)�2C�D�D�D��#�*�*�9�+<�=�=�=�!&�I����	'�	'rlc���	|���|j�|||��n#t$rd|_YdSwxYw|j�|j��d|_dS)z�Prepares a statement.

        Args:
            msg_type (str): Message ID string.
            msg (mysqlx.protobuf.Message): MySQL X Protobuf Message.
            statement (Statement): A `Statement` based type object.
        FNT)	rOr@�send_prepare_preparer rJrIr\r�r��ru�msg_typer�r�s    rc�_prepare_statementzConnection._prepare_statements���	��$�$�&�&�&��M�.�.�x��i�H�H�H�H�� �	�	�	�,1�D�)��F�F�	����	
��&�&�y�'8�9�9�9�!�	���s�03�A�Ac�8�|js|j�|||��dS|jr�|�|��|�|||��|js|j�|||��dS|j�|||��d|_|����nO|jr%|j	s|j�|||���n#|j	rT|j
sM|�|��|j�|||��d|_	|���n�|j	sg|j
s`|js|�|||��|js|j�|||��dS|j�|||��nZ|j	rS|j
rL|�|��|j�|||��d|_	|���|���dS)z�Executes the prepared statement pipeline.

        Args:
            msg_type (str): Message ID string.
            msg (mysqlx.protobuf.Message): MySQL X Protobuf Message.
            statement (Statement): A `Statement` based type object.
        NF)rJr@�send_msg_without_ps�deallocate_prepare_executer�r��send_prepare_execute�reset_exec_counterr��changed�repeated�increment_exec_counterr�s    rc�_execute_prepared_pipelinez%Connection._execute_prepared_pipeline*sM���,�	��M�-�-�h��Y�G�G�G��F��/� 	+��&�&�y�1�1�1��#�#�H�c�9�=�=�=��0�
��
�1�1�(�C��K�K�K����M�.�.�x��i�H�H�H�38�I�0��(�(�*�*�*�*�
�
�	+�	�(9�	+��M�.�.�x��i�H�H�H�H�
�
�	+�y�'9�	+��&�&�y�1�1�1��M�-�-�h��Y�G�G�G� %�I���(�(�*�*�*�*��"�
	+�9�+=�
	+��%�
B��'�'��#�y�A�A�A��0�
��
�1�1�(�C��K�K�K����M�.�.�x��i�H�H�H�H�
�
�	+�9�#5�	+��&�&�y�1�1�1��M�-�-�h��Y�G�G�G� %�I���(�(�*�*�*��(�(�*�*�*�*�*rlc��|j}|j�td���t|t��std���|j�d|��\}}|j�|||��t|��S)z�Execute a SQL statement.

        Args:
            sql (str): The SQL statement.

        Raises:
            :class:`mysqlx.ProgrammingError`: If the SQL statement is not a
                                              valid string.
        Nr�z'The SQL statement is not a valid string�sql)	r�r@r!rfr]r#�build_execute_statementr�r2)rur�r�r�r�s     rc�send_sqlzConnection.send_sql\s����m���=�	F�"�#D�E�E�E��#�s�#�#�	N�"�#L�M�M�M��
�=�=�e�S�I�I�
��#��
�)�)�(�C��C�C�C�����rlc��|j�td���|j�|��\}}|j�||��d}t	|t
��r|j}t||��S)a
Send an insert statement.

        Args:
            statement (`Statement`): It can be :class:`mysqlx.InsertStatement`
                                     or :class:`mysqlx.AddStatement`.

        Returns:
            :class:`mysqlx.Result`: A result object.
        Nr�)r@r!�build_insert�send_msgrfr3�idsr0)rur�r�r�r�s     rc�send_insertzConnection.send_insertps}���=�	F�"�#D�E�E�E��
�2�2�9�=�=�
��#��
���x��-�-�-����i��.�.�	 ��-�C��d�C� � � rlc���|j�|��\}}|�|||��|���rt	|��nt|��S)aDSend an find statement.

        Args:
            statement (`Statement`): It can be :class:`mysqlx.SelectStatement`
                                     or :class:`mysqlx.FindStatement`.

        Returns:
            `Result`: It can be class:`mysqlx.DocResult` or
                      :class:`mysqlx.RowResult`.
        )r@�
build_findr��is_doc_basedr/r1�rur�r�r�s    rc�	send_findzConnection.send_find�s\���
�0�0��;�;�
��#��'�'��#�y�A�A�A�"+�"8�"8�":�":�O�y�����	�$���Orlc��|j�|��\}}|�|||��t|��S)aSend an delete statement.

        Args:
            statement (`Statement`): It can be :class:`mysqlx.RemoveStatement`
                                     or :class:`mysqlx.DeleteStatement`.

        Returns:
            :class:`mysqlx.Result`: The result object.
        )r@�build_deleter�r0r�s    rc�send_deletezConnection.send_delete��A���
�2�2�9�=�=�
��#��'�'��#�y�A�A�A��d�|�|�rlc��|j�|��\}}|�|||��t|��S)aSend an delete statement.

        Args:
            statement (`Statement`): It can be :class:`mysqlx.ModifyStatement`
                                     or :class:`mysqlx.UpdateStatement`.

        Returns:
            :class:`mysqlx.Result`: The result object.
        )r@�build_updater�r0r�s    rc�send_updatezConnection.send_update�r�rlc��	|j�|||��\}}|j�||��t|��S#t$r|r�YnwxYwdS)a�Execute a non query command.

        Args:
            namespace (str): The namespace.
            cmd (str): The command.
            raise_on_fail (bool): `True` to raise on fail.
            fields (Optional[dict]): The message fields.

        Raises:
            :class:`mysqlx.OperationalError`: On errors.

        Returns:
            :class:`mysqlx.Result`: The result object.
        N)r@r�r�r0r!)ru�	namespace�cmd�
raise_on_fail�fieldsr�r�s       rc�execute_nonqueryzConnection.execute_nonquery�s��� 	� �M�A�A��3����M�H�c�
�M�"�"�8�S�1�1�1��$�<�<����	�	�	��
��
�
�	�����ts�AA�
A�Ac�
�|j�d|��\}}|j�||��t|��}|���|jdkrt
d���|ddS)z�Execute a SQL scalar.

        Args:
            sql (str): The SQL statement.

        Raises:
            :class:`mysqlx.InterfaceError`: If no data found.

        Returns:
            :class:`mysqlx.Result`: The result.
        r�rz
No data found)r@r�r�r1rNr�r)rur�r�r�r�s     rc�execute_sql_scalarzConnection.execute_sql_scalar�s���
�=�=�e�S�I�I�
��#��
���x��-�-�-��4�����������<�1��	2� ��1�1�1��a�y��|�rlc��|j�d||��\}}|j�||��t|��S)z�Returns the row result.

        Args:
            cmd (str): The command.
            fields (dict): The message fields.

        Returns:
            :class:`mysqlx.RowResult`: The result object.
        rW)r@r�r�r1)rur�r�r�r�s     rc�get_row_resultzConnection.get_row_result�sE���
�=�=�h��V�T�T�
��#��
���x��-�-�-�����rlc�6�|j�|��S)zdRead row.

        Args:
            result (:class:`mysqlx.RowResult`): The result object.
        )r@�read_rowrQs  rcr�zConnection.read_row�s���}�%�%�f�-�-�-rlc�:�|j�|��dS)zeClose result.

        Args:
            result (:class:`mysqlx.Result`): The result object.
        N)r@�close_resultrQs  rcr�zConnection.close_result�s ��	
�
�"�"�6�*�*�*�*�*rlc�6�|j�|��S)zlGet column metadata.

        Args:
            result (:class:`mysqlx.Result`): The result object.
        )r@r�rQs  rcr�zConnection.get_column_metadatas���}�0�0��8�8�8rlc�0�|xjdz
c_|jS)z|Returns the next statement ID.

        Returns:
            int: A statement ID.

        .. versionadded:: 8.0.16
        r)rHrts rc�get_next_statement_idz Connection.get_next_statement_ids!��	
���a�����!�!rlc�4�|j���S)zgCheck if connection is open.

        Returns:
            bool: `True` if connection is open.
        )r?r�rts rcr�zConnection.is_opens���{�"�"�$�$�$rlc�"�d|_||_dS)z�Set the disconnection message from the server.

        Args:
            reason (str): disconnection reason from the server.
        TN)rKrL)rur�s  rcr�z"Connection.set_server_disconnecteds��%)��!�+1��(�(�(rlc��|jS)z�Verify if the session has been disconnect from the server.

        Returns:
            bool: `True` if the connection has been closed from the server
                  otherwise `False`.
        )rKrts rcr�z!Connection.is_server_disconnected(s
���(�(rlc��|jS)z�Get the disconnection message sent by the server.

        Returns:
            string: disconnection reason from the server.
        )rLrts rcr�z"Connection.get_disconnected_reason1s
���/�/rlc�d�|���sdS|j���dS)zDisconnect from server.N)r�r?r�rts rcr�zConnection.disconnect9s1���|�|�~�~�	��F���������rlc��|���sdS	|���|jr+|jD]}|j�|���d|_|j���|j���n?#tttf$r%}t�
d|��Yd}~nd}~wwxYw|j���dS#|j���wxYw)z*Close a sucessfully authenticated session.NrzGWarning: An error occurred while attempting to close the connection: %s)r�rOrJrIr@r�rH�
send_close�read_okrr!r�rvrwr?r�)rur�r�s   rc�
close_sessionzConnection.close_session?s-���|�|�~�~�	��F�	 ��$�$�&�&�&��,�
'�#�6�C�C�G��M�9�9�'�B�B�B�B�%&��"��M�$�$�&�&�&��M�!�!�#�#�#�#��� 0�'�:�	�	�	��O�O�!��
�
�
�
�
�
�
�
�����	����
�K���������D�K���������s0�A8B�C+�C
�(C�C+�C
�
C+�+Dc�0�|���sdS|j�|j���	|j�|j��|_dS#ttf$r&}t�	d|��Yd}~dSd}~wwxYw)z*Reset a sucessfully authenticated session.NzDWarning: An error occurred while attempting to reset the session: %s)
r�rErNr@�
send_resetrArr!rvrw)rur�s  rc�
reset_sessionzConnection.reset_sessionZs����|�|�~�~�	��F���	,���)�)�+�+�+�	�!�]�5�5�d�n�E�E�D�N�N�N��� 0�1�	�	�	��O�O���
�
�
�
�
�
�
�
�
�����	���s�$A�B�/B�Bc��|���sdS|j�|j���|j���|j���|j���dS)z�Announce to the server that the client wants to close the
        connection. Discards any session state of the server.
        N)r�rErNr@�send_connection_closer�r?r�rts rcrxzConnection.close_connectionis{���|�|�~�~�	��F���	,���)�)�+�+�+��
�+�+�-�-�-��
��������������rlr�)&r�r�r�r�rvrOrRr}r_rcrdr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rxr�rlrcr�r��s���������0�0�0�@'�'�'�	%�	%�	%�DS�DS�DS�L4M�4M�4M�l\�\�\�\�|���>%�%�%�%�%�%�%�%�%�	'�	'�	'�"�"�"�"0+�0+�0+�d������&�!�!���!�&�
P�
P���
P��������������������4������(�������.�.���.��+�+���+��9�9���9�	"�	"�	"�%�%�%�2�2�2�)�)�)�0�0�0���� � � �6
�
�
�
�
�
�
�
rlr�c�D��eZdZdZ�fd�Z�fd�Zd�Zd�Zd�Zd�Z	�xZ
S)r�aClass to hold :class:`Connection` instances in a pool.

    PooledConnection is used by :class:`ConnectionPool` to facilitate the
    connection to return to the pool once is not required, more specifically
    once the close_session() method is invoked. It works like a normal
    Connection except for methods like close() and sql().

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

    The sql() method is used to execute sql statements.

    Args:
        pool (ConnectionPool): The pool where this connection must return.

    .. versionadded:: 8.0.13
    c����t|t��std���t���|j��||_|jd|_|jd|_dS)Nz&pool should be a ConnectionPool objectrKrL)	rf�ConnectionPoolr~rrv�
cnx_configr�rKrL)rur�rs  �rcrvzPooledConnection.__init__�sf����$��/�/�	K� �!I�J�J�J�
�������)�)�)���	��O�F�+��	��O�F�+��	�	�	rlc�H��t�����dS)zGCloses the connection.

        This method closes the socket.
        N)rr�)rurs �rcrxz!PooledConnection.close_connection�s!���
	���������rlc�:�|j�|��dS)a�Do not close, but add connection back to pool.

        The close_session() 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 once the connection
        is get from the pool.
        N)r��add_connectionrts rcr�zPooledConnection.close_session�s ��	
�	� � ��&�&�&�&�&rlc�n�|j�|j���|���dS)zReconnect this connection.N)rErNrdrts rc�	reconnectzPooledConnection.reconnect�s:����	,���)�)�+�+�+��������rlc�.�|���dS)zQReset the connection.

        Resets the connection by re-authenticate.
        N)r�rts rc�resetzPooledConnection.reset�s��
	
�������rlc�"�t||��S�aCreates a :class:`mysqlx.SqlStatement` object to allow running the
        SQL statement on the target MySQL Server.

        Args:
            sql (string): The SQL statement to be executed.

        Returns:
            mysqlx.SqlStatement: SqlStatement object.
        )r4�rur�s  rcr�zPooledConnection.sql�s���D�#�&�&�&rl)r�r�r�r�rvrxr�r�r�r�r	r
s@rcr�r�vs����������$,�,�,�,�,� � � � � �'�'�'�������
'�
'�
'�
'�
'�
'�
'rlr�c�|�eZdZdZd�Zd�Zed���Zdd�Zd�Z	dd�Z
d	�Zd
�Zd�Z
d�Zdd�Zd�Zd�Zd�ZdS)r�a�This class represents a pool of connections.

    Initializes the Pool with the given name and settings.

    Args:
        name (str): The name of the pool, used to track a single pool per
                    combination of host and user.
        **kwargs:
            max_size (int): The maximun number of connections to hold in
                            the pool.
            reset_session (bool): If the connection should be reseted when
                                  is taken from the pool.
            max_idle_time (int): The maximum number of milliseconds to allow
                                 a connection to be idle in the queue before
                                 being closed. Zero value means infinite.
            queue_timeout (int): The maximum number of milliseconds a
                                 request will wait for a connection to
                                 become available. A zero value means
                                 infinite.
            priority (int): The router priority, to choose this pool over
                            other with lower priority.

    Raises:
        :class:`mysqlx.PoolError` on errors.

    .. versionadded:: 8.0.13
    c�@�|�|��d|_g|_d|_d|_tj��|_|�dd��|_	tj�||j	��|�dd��|_
|�dd��|_||_|�dd��|_|�dd��|_||_|d	|_|d
|_dS)NrT�max_size�r��
max_idle_time�
queue_timeoutrrKrL)�_set_pool_name�_open_sessions�_connections_openned�
_available�_timeoutr	�now�_timeout_stampr�
pool_max_size�queue�Queuervr�rrrrr�rKrL)rur�r`s   rcrvzConnectionPool.__init__�s������D�!�!�!����$&��!������
�&�l�n�n���#�Z�Z�
�B�7�7���
����T�4�#5�6�6�6�#�Z�Z���>�>���#�Z�Z���<�<�����
�#�Z�Z���<�<����
�
�:�q�1�1��
� ����6�N��	��6�N��	�	�	rlc���t�|��rtd|�d����t|��tkrtd|�d����||_dS)a�Set the name of the pool.

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

        Args:
            pool_name (str): The pool name.

        Raises:
            AttributeError: If the pool_name contains illegal characters
                            ([^a-zA-Z0-9._\-*$#]) or is longer than
                            connection._CNX_POOL_MAX_NAME_SIZE.
        zPool name 'z' contains illegal charactersz
' is too longN)�_CNX_POOL_NAME_REGEXr8r~r��_CNX_POOL_MAX_NAME_SIZEr�)ru�	pool_names  rcrzConnectionPool._set_pool_name�so�� �&�&�y�1�1�	Y� �!W�y�!W�!W�!W�X�X�X��y�>�>�3�3�	I� �!G�y�!G�!G�!G�H�H�H���	�	�	rlc�*�t|j��S)zDReturns the number of open connections that can return to this pool.)r�r
rts rc�open_connectionszConnectionPool.open_connectionss���4�,�-�-�-rlNc�:�|j�|��dS)zwRemoves a connection from this pool.

        Args:
            cnx (PooledConnection): The connection object.
        N)r
r��ru�cnxs  rc�remove_connectionz ConnectionPool.remove_connections!��	
�!�(�(��-�-�-�-�-rlc��|���dkr�	|�d|j���}	|���n#tt
tf$rYnwxYw|�|��n/#|�|��wxYw#tj	$rYnwxYw|���dk��dSdS)z*Removes all the connections from the pool.rT��blockrfN)
�qsizerrrxr�r�rrr�Emptyrs  rcr�z!ConnectionPool.remove_connectionss����j�j�l�l�Q��	0�

0��h�h�T�4�3E�h�F�F��0��(�(�*�*�*�*��$�g�~�>�����D������*�*�3�/�/�/�/��D�*�*�3�/�/�/�/������;�
�
�
���
�����j�j�l�l�Q��	0�	0�	0�	0�	0s:�B�A�A?�A&�#A?�%A&�&A?�?B�B+�*B+c�>�|jstd���|���rtd���|s�t|��}|�t
��������dd}td�|�	d��d�	d��D����dkr/|�d|j
�������|j�|��n`t|t��std	���|���r(|���|���|�|��d
S)a=Adds a connection to this pool.

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

        Args:
            cnx (PooledConnection): The connection object.

        Raises:
            PoolError: If no configuration is set, if no more connection can
                       be added (maximum reached) or if the connection can not
                       be instantiated.
        z&Connection configuration not available�'Failed adding connection; queue is fullrc3�4K�|]}t|��V��dSr���int�r$�ns  rc�	<genexpr>z0ConnectionPool.add_connection.<locals>.<genexpr>8�(����B�B��S��V�V�B�B�B�B�B�Brl�-rr��r�
�set mysqlx_wait_timeout = z1Connection instance not subclass of PooledSessionN)r�r"�fullr�r��_SELECT_VERSION_QUERY�executerN�tupler{rr
r\rfr�r�r��queue_connection)rur�vers   rcr�zConnectionPool.add_connections��� ��	F��D�E�E�E��9�9�;�;�	G��E�F�F�F��	�"�4�(�(�C��'�'�/�0�0�8�8�:�:�D�D�F�F�q�I�!�L�C��B�B�S�Y�Y�s�^�^�A�%6�%<�%<�S�%A�%A�B�B�B�B�B�F��
U�
���I�T�5G�I�I�J�J�R�R�T�T�T��%�,�,�S�1�1�1�1��c�#3�4�4�
U�� S�T�T�T��)�)�+�+�
��'�'�)�)�)��	�	�������c�"�"�"�"�"rlc��t|t��std���|jr|���	|�|d���dS#t
j$rtd��YdSwxYw)aGPut 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.

        Args:
            PooledConnection: The connection object.

        Raises:
            PoolError: On errors.
        z2Connection instance not subclass of PooledSession.F)rr"N)rfr�r"r��putr�Fullrs  rcr3zConnectionPool.queue_connectionHs����#�/�0�0�	R��P�Q�Q�Q���	 �������	A��H�H�S��H�&�&�&�&�&���z�	A�	A�	A��?�@�@�@�@�@�@�	A���s�A�A<�;A<c�:�|j�|��dS)zETracks connection in order of close it when client.close() is invoke.N)r
r\)ru�
connections  rc�track_connectionzConnectionPool.track_connection`s���!�(�(��4�4�4�4�4rlc��|jSr�rUrts rc�__str__zConnectionPool.__str__ds
���y�rlc��|jS)z�Returns if this pool is available for pool connections from it.

        Returns:
            bool: True if this pool is available else False.
        .. versionadded:: 8.0.20
        )rrts rcr�zConnectionPool.availablegs����rl���c��|jrDt�d||��d|_tj��|_||_dSdS)zhSets this pool unavailable for a period of time (in seconds).

        .. versionadded:: 8.0.20
        z4ConnectionPool.set_unavailable pool: %s time_out: %sFN)rrvrwr	r
rr)ru�time_outs  rcrzConnectionPool.set_unavailablepsY��
�?�	%��O�O�F���
�
�
�
$�D�O�"*�,�.�.�D��$�D�M�M�M�	%�	%rlc�D�d|_tj��|_dS)zaSets this pool available for pool connections from it.

        .. versionadded:: 8.0.20
        TN)rr	r
rrts rc�
set_availablezConnectionPool.set_availables��
���&�l�n�n����rlc��|j|jfS)z�Returns the penalized time (timeout) and the time at the penalty.

        Returns:
            tuple: penalty seconds (int), timestamp at penalty (datetime object)
        .. versionadded:: 8.0.20
        )rrrts rc�get_timeout_stampz ConnectionPool.get_timeout_stamp�s���
�t�2�3�3rlc�B�|jD]}|����dS)zEmpty this ConnectionPool.N)r
rxrs  rcr�zConnectionPool.close�s3���,�	#�	#�C�� � �"�"�"�"�	#�	#rlr�)r>)r�r�r�r�rvr�propertyrrr�r�r3r:r<r�rrBrDr�r�rlrcr�r��s��������8#�#�#�&���&�.�.��X�.�.�.�.�.�
0�
0�
0�(#�(#�(#�(#�TA�A�A�05�5�5�������
%�
%�
%�
%�-�-�-�4�4�4�#�#�#�#�#rlr�c��eZdZdZdZiZd�Zd�Zd�Ze	d���Z
d�Ze	d���Ze	d	���Z
d
�Ze	dd���Zdd�Zd
�Zd�Ze	d���ZdS)r�z�Manages a pool of connections for a host or hosts in routers.

    This class handles all the pools of Connections.

    .. versionadded:: 8.0.13
    Nc��tj�0t�|��t_it_tjSr�)r��_PoolsManager__instance�object�__new__�_PoolsManager__pools)�clss rcrKzPoolsManager.__new__�s2���"�	&�&,�n�n�S�&9�&9�L�#�#%�L� ��&�&rlc�b�|j�|g��}|D]}|j|krdS�dS)z�Verifies if a pool exists with the given name.

        Args:
            client_id (str): The client id.
            pool_name (str): The name of the pool.

        Returns:
            bool: Returns `True` if the pool exists otherwise `False`.
        TF)rLrr�)rurZr�poolsr�s     rc�_pool_existszPoolsManager._pool_exists�sJ���� � ��B�/�/���	�	�D��y�I�%�
��t�t�
��urlc��g}g}|�|��}|D]\}}|�|���|j�|�dd��g��D] }|j|vr|�|���!|S)z�Retrieves a list of pools that shares the given settings.

        Args:
            settings (dict): the configuration of the pool.

        Returns:
            list: A list of pools that shares the given settings.
        rZ�No id)�_get_connections_settingsr\rLrr�)rur�available_pools�
pool_names�connections_settings�router_namer[r�s        rc�
_get_poolszPoolsManager._get_pools�s������
�#�=�=�h�G�G��3�	+�	+�N�K�����k�*�*�*�*��L�$�$�X�\�\�+�w�%G�%G��L�L�	-�	-�D��y�J�&�
-��&�&�t�,�,�,���rlc��|���}|�dg��}g}d|vr|�d��d|vr*d|vr&|�dd|d|dd���|�d����|D]q}|���}|d|d<|d|d<|d	|d	<|�d
d��|d
<|�tdi|��|f���r|S)aHGenerates a list of separated connection settings for each host.

        Gets a list of connection settings for each host or router found in the
        given settings.

        Args:
            settings (dict): The configuration for the connections.

        Returns:
            list: A list of connections settings
        rMrKrLrr)r�weightrKrLc�@�|d|�dd��fS)NrrZr)rrs rcrz8PoolsManager._get_connections_settings.<locals>.<lambda>�s ��A�j�M�A�E�E�(�A�4F�4F�3F�#G�rl)rbrrZr�)r4r�popr\r�rd)r�
pool_settingsrMrVr!�connection_settingss      rcrSz&PoolsManager._get_connections_settings�s]��!�
�
���
��#�#�I�r�2�2��!���
�%�	)����i�(�(�(��]�"�	�v��'>�	��N�N� #��)�&�1�)�&�1�	��
�
�
�	���G�G��H�H�H��	�	�F�"/�"4�"4�"6�"6��*0��.���'�*0��.���'�.4�Z�.@��
�+�,2�J�J�x��,C�,C���)� �'�'�&�=�=�)<�=�=�'��
�
�
�
�$�#rlc��|�|��}|�dd��|jvrg|j|�dd��<|D]\}}|�|�dd��|��r�0|j�|�dd��g��}|�t|fi|������dS)a#Creates a `ConnectionPool` instance to hold the connections.

        Creates a `ConnectionPool` instance to hold the connections only if
        no other pool exists with the same configuration.

        Args:
            cnx_settings (dict): The configuration for the connections.
        rZrRN)rSrrLrPr\r�)ru�cnx_settingsrVrWrr�s      rc�create_poolzPoolsManager.create_pool�s��� $�=�=�l�K�K�����K��1�1���E�	F�CE�D�L��)�)�+�w�?�?�@�&:�	A�	A�!�K��� � ��!1�!1�+�w�!G�!G��U�U�
���<�#�#�L�$4�$4�[�'�$J�$J�B�O�O�D��K�K��{�?�?�h�?�?�@�@�@�@�		A�	Arlc��|sdSt|��dkr|dSt|��dz
}tjd|��}||S)z�Get a random router from the group with the given priority.

        Returns:
            Router: a random router.

        .. versionadded:: 8.0.20
        Nrr)r�r*r+)�	pool_listr,r-s   rc�_get_random_poolzPoolsManager._get_random_poolsZ���	��4��y�>�>�Q��	 ��Q�<���9�~�~��!����q�$�'�'�����rlc��g}d}|t|��krh||j}||kr6||���r|�||��n||krn|dz
}|t|��k�h|S)Nr)r�rr�r\)rOr-r6�sublist�
next_prioritys     rc�_get_sublistzPoolsManager._get_sublist!s������
��c�%�j�j� �	�!�%�L�1�M��}�,�
��u��1G�1G�1I�1I�
����u�U�|�,�,�,�,���.�
���Q�J�E�
�c�%�j�j� �	��rlc��d}|D](}|���r
||jkrn|dz
}�)g}|sD|t|��kr1|�|||��}|dz
}|s|t|��k�1|�|��S)Nrr)r�rr�rhrd)rurOr6r-r��subpools      rc�_get_next_poolzPoolsManager._get_next_pool.s������	�	�D��~�~���
�L�D�M�$A�
����Q�J�E�E����	�e�c�%�j�j�0�	��'�'��u�l�C�C�G��Q�J�E��	�e�c�%�j�j�0�	��$�$�W�-�-�-rlc��|�|r
|djS|D]!}|���r|j}|cS�"|djS)Nr)rr�)rOr6�t_pools   rc�_get_next_priorityzPoolsManager._get_next_priority:sh���	%�E�	%���8�$�$��	$�	$�F����!�!�
$�%���#�#�#�#�
$��Q�x� � rlc��|�|��}|D]n}|���r�|���\}}|r|}tj��|t|���zkr|����odS)N)�seconds)rXr�rDr	r
r
rB)rur�reviverOr�rf�
timeout_stamps       rc�_check_unavailable_poolsz%PoolsManager._check_unavailable_poolsEs�������)�)���	%�	%�D��~�~���
��%)�%;�%;�%=�%=�"�G�]��
!� ���|�~�~���7�1K�1K�1K�!K�L�
%��"�"�$�$�$��	%�	%rlc	�\�
��
fd�}|�|��}|�dd��}g}|�|��|�||��}|�t	d���||d<|�||���
t
j��}�
��~	�
���dk�r�|5	�
�d�
j	���}n##tj$rt	d��d�wxYw	|���r�
�
��|js|���||���n�#t t"t$f$�r�	|���n#t t"t$f$rYnwxYw�
�|��n#�
�|��wxYw�
���dkr�	�
�d�
j	���}	|���n#t t"t$f$rYnwxYw�
�|��n/#�
�|��wxYw#tj$rYnwxYw�
���dk��	t+�
��}�
�|��|���||��n#t t"t$f$rYnwxYw�
���dkr|	�
�d�
j	���}|����
�|��n#t t"t$f$rYnwxYw�
���dk�|n�#�
���dkr|	�
�d�
j	���}|����
�|��n#t t"t$f$rYnwxYw�
���dk�|wxYwYnwxYw|cddd��S#1swxYwYnЉ
j�
jkrEt+�
��}�
�|��|���||��|S|5	�
�d�
j	���}|���||��|cddd��S#tj$rt	d	��d�wxYw#1swxYwY�n
#t$t4tf$r�}|�d
�
�d|����t9|t��r�
�d��n|��
|��|�|��|�||���
�
�\|�||��}||d<|�||���
�
�)d
�|��}	t	d|	�d���|�Yd}~��vd}~wwxYw�
��~t	d���)a�Get a connection from the pool.

        This method returns an `PooledConnection` instance which has a reference
        to the pool that created it, and can be used as a normal Connection.

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

        Raises:
            :class:`PoolError`: On errors.

        Returns:
            PooledConnection: A pooled connection object.
        c���|�t��������dd}t	d�|�d��d�d��D����dkr1|�d�j�������dSdS)Nrc3�4K�|]}t|��V��dSr�r$r&s  rcr(zOPoolsManager.get_connection.<locals>.set_mysqlx_wait_timeout.<locals>.<genexpr>br)rlr*rrr+r.)r�r0r1rNr2r{r)rr4r�s  �rc�set_mysqlx_wait_timeoutz<PoolsManager.get_connection.<locals>.set_mysqlx_wait_timeout_s�����'�'�/�0�0�8�8�:�:�D�D�F�F�q�I�!�L�C��B�B�S�Y�Y�s�^�^�A�%6�%<�%<�S�%A�%A�B�B�B�B�B�F��
U�
���I�T�5G�I�I�J�J�R�R�T�T�T�T�T�
U�
Urlr6NzBUnable to connect to any of the target hosts. No pool is availablerTrz)Failed getting connection; pool exhaustedzpool max size has been reachedzpool: z error: r3z
  z2Unable to connect to any of the target hosts: [
  z
]r\) rXrrsrnr"rk�	threading�RLockrrrr r�r�rAr�r�r�rrxrr�r:r}rrr$r\rfrr�r_)rurrwrOr6�
error_list�lockrr�r�r�s          @rc�get_connectionzPoolsManager.get_connectionPs����	U�	U�	U�	U�	U�����)�)���|�|�N�D�9�9���
��%�%�h�/�/�/��.�.�u�l�C�C���	��T���
�$0��� ��"�"�5�,�7�7���� � ���k	�j
��:�:�<�<�!�#�PX��=#�=#�(�"&�(�(��t�?Q�(�"R�"R�C�C��$�{�(�(�(�"+� K�#�#�#'�(�(����5-�"�9�9�;�;�:� $� 7� 7� 9� 9� 9�$'�=�,� #�	�	����3�3�C�8�8�8�8�� ,�g�~�F�,-�,-�,-�<� #� 4� 4� 6� 6� 6� 6��$0�'�>�#J�%�%�%� $��%����!%� 6� 6�s� ;� ;� ;� ;��� 6� 6�s� ;� ;� ;� ;����#'�*�*�,�,��"2�
D�!D�*.�(�(�.2�D�<N�+3�+&�+&�C�%D�(+�(<�(<�(>�(>�(>�(>��,8�'�>�+R�%-�%-�%-�(,��%-����)-�(>�(>�s�(C�(C�(C�(C���(>�(>�s�(C�(C�(C�(C�����(-�{�!)�!)�!)�$(�D�!)����#'�*�*�,�,��"2�
D�-�&6�t�&<�&<�� $� 5� 5�c� :� :� :� #���
�
�
� 7� 7�� <� <� <� <��$0�'�>�#J�%�%�%� $��%����
'+�j�j�l�l�Q�&6�	!-�%-�.2�h�h�26�48�4F�/7�/*�/*��),�(<�(<�(>�(>�(>�(,�(>�(>�s�(C�(C�(C�(C��,8�'�>�+R�%-�%-�%-�(,��%-����'+�j�j�l�l�Q�&6�	!-���d�j�j�l�l�Q�&6�	!-�%-�.2�h�h�26�48�4F�/7�/*�/*��),�(<�(<�(>�(>�(>�(,�(>�(>�s�(C�(C�(C�(C��,8�'�>�+R�%-�%-�%-�(,��%-����'+�j�j�l�l�Q�&6�	!-�	!-�	!-�	!-�	!-���G,-����Z #�{=#�=#�=#�=#�=#�=#�=#�=#�=#�=#�=#�=#����=#�=#�=#�=#�=#�|�*�T�-?�?�X�*�4�0�0�C��)�)�#�.�.�.��K�K�M�M�M�+�+�C�0�0�0��J��X�X�X�"&�(�(��t�?Q�(�"R�"R�C��I�I�K�K�K�3�3�C�8�8�8�#&�X�X�X�X�X�X�X�X�� %�{�X�X�X�"+�,L�"M�"M�SW�W�X����
X�X�X�X����X�X�X�X���#�L�)�<�
�
�
��!�!�">�4�">�">��">�">�?�?�?��c�9�-�-�9��(�(��+�+�+�+��-�-�d�C�8�8�8��-�-�h�7�7�7��*�*�5�,�?�?���	#�#'�#:�#:�5�,�#O�#O�L�/;�H�^�,��.�.�u�l�C�C�D��#�$�k�k�*�5�5��'�-�$'�-�-�-��� #�#����������/
����i�k	�Z�F�G�G�Gs��"T�=P4�?C�P4� C<�<P4�AE�P4�P#�)E>�=F1�>F�F1�F�F1�P#�1G�P#�$I#�H�I	�H0�-I	�/H0�0I	�3P#�	I � P#�#I5�2P#�4I5�5P#�AK�N�K/�,N�.K/�/N�2P#�AM�P#�M+�(P#�*M+�+P#�P�!AO'�&P�'P�>P�P�P�P#� P4�"P#�#P4�'T�4P8�8T�;P8�<AT�T�T�<S"�T�" T�T�T	�	T�T	�
T�X�)C%X�Xc�4�|�|��}|D]r}|���|�dd���F|j�|�d����}||vr|�|���st|��S)zjCloses the connections in the pools

        Returns:
            int: The number of closed pools
        rZN)rXr�rrLr�r�)rur`rOr��client_poolss     rc�
close_poolzPoolsManager.close_pool�s�������-�-���	.�	.�D��J�J�L�L�L�����T�2�2�
.�#�|�/�/��0@�0@��0M�0M�N�N���<�'�.� �'�'��-�-�-���5�z�z�rlc��d}	|j}t|}n#ttf$rYnwxYw|s,|j}t
���D]\}}||vr|}�|r|�|��dS|�d��dS)a\Sets a pool as unavailable.

        The time a pool is set unavailable depends on the given error message
        or the error number.

        Args:
            pool (ConnectionPool): The pool to set unavailable.
            err (Exception): The raised exception raised by a connection belonging
                             to the pool.
        Ni��)�errnorhr~r^r��_TIMEOUT_PENALTIES�itemsr)r�r��penalty�err_no�err_msgrbr�s       rcr�z!PoolsManager.set_pool_unavailable�s�����	��Y�F�2�6�:�G�G����)�	�	�	��D�	�����	$��g�G�0�6�6�8�8�
$�
$�
��U��'�>�$�#�G���	)�� � ��)�)�)�)�)�
� � ��(�(�(�(�(s��-�-r�)r�r�r�r�rIrLrKrPrX�staticmethodrSrardrhrkrnrsr|rr�r�rlrcr�r��s>���������J��G�'�'�'���� ���.�($�($��\�($�TA�A�A�,� � ��\� �"�
�
��\�
�
.�
.�
.��!�!�!��\�!�	%�	%�	%�	%�RH�RH�RH�h��� �)�)��\�)�)�)rlr�c���eZdZdZd�Zd�Zd�Zd�Zed���Z	e	j
d���Z	d�Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�ZdS)�Sessiona*Enables interaction with a X Protocol enabled MySQL Product.

    The functionality includes:

    - Accessing available schemas.
    - Schema management operations.
    - Retrieval of connection information.

    Args:
        settings (dict): Connection data used to connect to the database.
    c�"�|�dtj��|_||_|�d��r�|�d��r�tstd���	tj�|dd��}n6#tj	j
$r}td|d�d���|�d}~wwxYwg|jd<|D]O}|jd�|j�
d	�
��|j|j|jd����Pd|jvs|jdd
uri|jd<|���d|vrf|dr^t%���|��t%���|��|_|j�t-d���n2t/|j��|_|j���|j�d��}|rz	|�dt5|���������dS#t8$r3}|jdkr|jnd|�d�}t||j��|�d}~wwxYwdS)NrQrKrVztMySQL host configuration requested DNS SRV. This requires the Python dnspython module. Please refer to documentation�SRVz Unable to locate any hosts for '�'rMT)�omit_final_dot)rKrLrrZrSFrY�poolingz+Connection could not be retrieved from poolrJzUSE i�Default schema '�' does not exists)rr(�use_purer�HAVE_DNSPYTHONr�dns�resolver�query�	exception�DNSExceptionr\�target�to_textrLrrZ�_init_attributesr�rar|�_connectionr"r�r}r�r5r1r!r�r�)rur�srv_recordsr��srvrJ�errmsgs       rcrvzSession.__init__s��� ���Z��1B�C�C��
�!����<�<����	�H�L�L��$;�$;�	�!�
�$�<����

�!�l�0�0��&�1A�5�I�I�����=�-�
�
�
�$�J�x��7G�J�J�J���������
����)+�D�N�9�%�"�
�
����y�)�0�0� #�
� 2� 2�$� 2� G� G� #��$'�L�"%�*�	������
$�4�>�9�	$��~�5�6�e�C�	$�,.�D�N�<�(��!�!�#�#�#��� �	'�X�i�%8�	'��N�N�&�&�x�0�0�0�+�~�~�<�<�X�F�F�D����
O�� M�N�N�N�
O� *�$�.�9�9�D����$�$�&�&�&���#�#�H�-�-���
	A�	
A����:� 0�� 8� 8�:�:�;�;�C�C�E�E�E�E�E��#�
A�
A�
A��y�D�(�F�C�G�G�E�F�E�E�E��
%�V�S�Y�7�7�S�@�����
A����
	A�
	As0�.&B�C�)C�C�7I�
J�.J�Jc��|Sr�r�rts rc�	__enter__zSession.__enter__Z����rlc�.�|���dSr�r��ru�exc_type�	exc_value�	tracebacks    rc�__exit__zSession.__exit__]r�rlc�<�tjdkrldtj��dvrd}n1dtj��dvrd}ntj��}dtj��d��}nptj��}tj��d	krd
tj��d��}n)d�t��dd���}tjd
��}|ddkrd}nd}ttj
����||tj��dd�d�t dd�D����|d�}|jd�|��d|jvr�|jdD]�}|jd|}t'|t��st)d|�d����t+|��dkrt)d|�d����|�d��rt)d|�����t'|t��st)d|�d|�d����t+|��d krt)d|�d!|�d"����||jd|<��d#Sd#S)$z5Setup default and user defined connection-attributes.r��64r�x86_64�32�i386zWindows-r�DarwinzmacOS-r*r3� �GPLv2zGPL-2.0�
Commercialzmysql-connector-pythonrrc�,�g|]}t|����Sr�)r])r$rs  rcr%z,Session._init_attributes.<locals>.<listcomp>�s��(F�(F�(F�A��Q���(F�(F�(Frl�)�_pid�	_platform�_os�_source_host�_client_name�_client_version�_client_licenserYrS�Attribute name '�' must be a string type� �"' exceeds 32 characters limit sizer[zHKey names in 'session-connect-attributes' cannot start with '_', found: z	' value 'z'  must be a string type��
' value: '�$' exceeds 1024 characters limit sizeN)r�r�ry�architecture�	win32_ver�machinerz�mac_verr_r;r<r{r]�getpidrN�gethostnamer=rrirfrr��
startswith)ru�
platform_arch�os_ver�license_chunks�client_license�default_attributes�	attr_name�
attr_values        rcr�zSession._init_attributes`s0��
�7�d�?�
	=��x�,�.�.�q�1�1�
8� (�
�
���.�0�0��3�3�
8� &�
�
� (� 5� 7� 7�
�9�� 2� 4� 4�Q� 7�9�9�F�F�$�,�.�.�M��� � �H�,�
=�9�(�"2�"4�"4�Q�"7�9�9������"4�"6�"6�q��s�";�<�<�� ��s�+�+���!���'�	*�&�N�N�)�N���	���$�$�&��"�.�0�0�4�"�x�x�(F�(F���1���(F�(F�(F�G�G�-�
�
�� 	
��|�$�+�+�,>�?�?�?�"�d�n�4�"	E�!�^�,C�D�!
E�!
E�	�!�^�,C�D�Y�O�
�!�)�S�1�1��(�M�9�M�M�M�����y�>�>�B�&��(�%�9�%�%�%����
�'�'��,�,��(�>�2;�>�>����
"�*�c�2�2��(�1�9�1�1�z�1�1�1�����z�?�?�T�)��(�=�9�=�=�
�=�=�=����
;E���|�,�Y�7�7�E"	E�"	E�!
E�!
Erlc��tjS)z8bool: `True` to use pure Python Protobuf implementation.)r(r�rts rcr�zSession.use_pure�s
��� � rlc�v�t|t��std���tj|��dS)Nz)'use_pure' option should be True or False)rf�boolr#r(�set_use_pure)rur�s  rcr�zSession.use_pure�s;���%��&�&�	P�"�#N�O�O�O���e�$�$�$�$�$rlc�>�|jj���S)zzReturns `True` if the session is open.

        Returns:
            bool: Returns `True` if the session is open.
        )r�r?r�rts rcr�zSession.is_open�s����&�.�.�0�0�0rlc�,�t|j|��Sr)r4r�rs  rcr�zSession.sql�s���D�,�c�2�2�2rlc��|jS)z~Returns the underlying connection.

        Returns:
            mysqlx.connection.Connection: The connection object.
        )r�rts rcr|zSession.get_connection�s
����rlc��|�d�����}d�|���D��S)z�Returns the list of schemas in the current session.

        Returns:
            `list`: The list of schemas in the current session.

        .. versionadded:: 8.0.12
        zSHOW DATABASESc��g|]
}|d��S)rr�)r$�rows  rcr%z'Session.get_schemas.<locals>.<listcomp>�s��5�5�5�3��A��5�5�5rl)r�r1rNrQs  rc�get_schemaszSession.get_schemas�sB�����*�+�+�3�3�5�5��5�5�&�"2�"2�"4�"4�5�5�5�5rlc�"�t||��S)z�Retrieves a Schema object from the current session by it's name.

        Args:
            name (string): The name of the Schema object to be retrieved.

        Returns:
            mysqlx.Schema: The Schema object with the given name.
        r�rur�s  rc�
get_schemazSession.get_schema�s���d�D�!�!�!rlc��|jj�d��}|r�|�t�t
|������������}	|dd|krt||��Sn"#t$rtd|�d���d�wxYwdS)aRetrieves a Schema object from the current session by the schema
        name configured in the connection settings.

        Returns:
            mysqlx.Schema: The Schema object with the given name at connect
                           time.
            None: In case the default schema was not provided with the
                  initialization data.

        Raises:
            :class:`mysqlx.ProgrammingError`: If the provided default schema
                                              does not exists.
        rJrr�r�N)r�rrr��_SELECT_SCHEMA_NAME_QUERY�formatr%r1rNrr|r#)rurJ�ress   rc�get_default_schemazSession.get_default_schema�s����!�*�.�.�x�8�8���	����2�9�9�&��.�.�I�I�J�J���������
�

��q�6�!�9��&�0�!�$��/�/�/�0���
�
�
�&�@�v�@�@�@�����
�����ts�!B$�$Cc��|j�dt�t	|����d��dS)z�Drops the schema with the specified name.

        Args:
            name (string): The name of the Schema object to be retrieved.
        r�TN)r�r��_DROP_DATABASE_QUERYr�r5r�s  rc�drop_schemazSession.drop_schema	sH��	
��)�)��'�.�.�/?��/E�/E�F�F��	
�	
�	
�	
�	
rlc��|j�dt�t	|����d��t||��S)z�Creates a schema on the database and returns the corresponding
        object.

        Args:
            name (string): A string value indicating the schema name.
        r�T)r�r��_CREATE_DATABASE_QUERYr�r5rr�s  rc�
create_schemazSession.create_schema	sP��	
��)�)��)�0�0�1A�$�1G�1G�H�H�$�	
�	
�	
��d�D�!�!�!rlc�>�|j�ddd��dS)z+Starts a transaction context on the server.r�zSTART TRANSACTIONTN�r�r�rts rc�start_transactionzSession.start_transaction	s$����)�)�%�1D�d�K�K�K�K�Krlc�>�|j�ddd��dS)zXCommits all the operations executed after a call to
        startTransaction().
        r��COMMITTNr�rts rc�commitzSession.commit"	s%��	
��)�)�%��4�@�@�@�@�@rlc�>�|j�ddd��dS)zYDiscards all the operations executed after a call to
        startTransaction().
        r��ROLLBACKTNr�rts rc�rollbackzSession.rollback(	s%��	
��)�)�%��T�B�B�B�B�BrlNc��|�tj���}nIt|t��r%t	|�����dkrt
d���|j�ddt|����d��|S)aCreates a transaction savepoint.

        If a name is not provided, one will be generated using the uuid.uuid1()
        function.

        Args:
            name (Optional[string]): The savepoint name.

        Returns:
            string: The savepoint name.
        Nr�Invalid SAVEPOINT namer�z
SAVEPOINT T)
�uuid�uuid1rfr]r��stripr#r�r�r5r�s  rc�
set_savepointzSession.set_savepoint.	s����	=��j�l�l�$�D�D��D�#�&�&�	=�#�d�j�j�l�l�*;�*;�q�*@�	=�"�#;�<�<�<���)�)��8� 0�� 6� 6�8�8�$�	
�	
�	
��rlc���t|t��r%t|�����dkrt	d���|j�ddt|����d��dS)zRollback to a transaction savepoint with the given name.

        Args:
            name (string): The savepoint name.
        rr�r�zROLLBACK TO SAVEPOINT TN�rfr]r�r�r#r�r�r5r�s  rc�rollback_tozSession.rollback_toC	s����$��$�$�	=��D�J�J�L�L�(9�(9�Q�(>�	=�"�#;�<�<�<���)�)��=�%5�d�%;�%;�=�=��	
�	
�	
�	
�	
rlc���t|t��r%t|�����dkrt	d���|j�ddt|����d��dS)z{Release a transaction savepoint with the given name.

        Args:
            name (string): The savepoint name.
        rr�r�zRELEASE SAVEPOINT TNr�r�s  rc�release_savepointzSession.release_savepointQ	s����$��$�$�	=��D�J�J�L�L�(9�(9�Q�(>�	=�"�#;�<�<�<���)�)��9�!1�$�!7�!7�9�9��	
�	
�	
�	
�	
rlc�j�|j���t|j��|_dS)zCloses the session.N)r�r�r�rrts rcr�z
Session.close_	s/����&�&�(�(�(�%�d�n�5�5����rlc�8�|j���dS)z8Closes all underliying connections as pooled connectionsN)r�rxrts rc�close_connectionszSession.close_connectionse	s����)�)�+�+�+�+�+rlr�)r�r�r�r�rvr�r�r�rFr��setterr�r�r|r�r�r�r�r�r�r�r�r�r�r�r�r�r�rlrcr�r�s�������
�
�9A�9A�9A�v������KE�KE�KE�Z�!�!��X�!��_�%�%��_�%�
1�1�1�
3�
3�
3� � � �	6�	6�	6�	"�	"�	"����<
�
�
�
"�
"�
"�L�L�L�A�A�A�C�C�C�����*
�
�
�
�
�
�6�6�6�,�,�,�,�,rlr�c�J�eZdZdZdd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�ZdS)
�Clienta(Class defining a client, it stores a connection configuration.

    Args:
        connection_dict (dict): The connection information to connect to a
                                MySQL server.
        options_dict (dict): The options to configure this client.

    .. versionadded:: 8.0.13
    Nc��||_|�i}g|_tj��|_|�|�dd����|�|�dd����|�|�dd����|�	|�dd����|j
|jd<|j|jd<|j|jd	<dS)
Nrrrrr�enabledTr�rZ)r�sessionsr��uuid4rZ�_set_pool_sizer�_set_max_idle_time�_set_queue_timeout�_set_pool_enabled�pooling_enabledr)ru�connection_dict�options_dicts   rcrvzClient.__init__u	s���'��
��	��L���
����������L�,�,�Z��<�<�=�=�=����� 0� 0��!� D� D�E�E�E����� 0� 0��!� D� D�E�E�E����|�/�/�	�4�@�@�A�A�A�#'�#7��
�i� �$(�M��
�j�!�%)�^��
�k�"�"�"rlc��|Sr�r�rts rcr�zClient.__enter__�	r�rlc�.�|���dSr�r�r�s    rcr�zClient.__exit__�	r�rlc��t|t��st|t��r|dkstd|�d����|dkrtn||_dS)a�Set the size of the pool.

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

        Args:
            pool_size (int): An integer equal or greater than 0 indicating
                             the pool size.

        Raises:
            :class:`AttributeError`: If the pool_size value is not an integer
                                     greater or equal to 0.
        rzGPool max_size value must be an integer greater than 0, the given value �
 is not validN)rfr�r%r~�_CNX_POOL_MAXSIZEr)ru�	pool_sizes  rcrzClient._set_pool_size�	s}��
�y�$�'�'�	��i��-�-�	��q�=�	�
!�8�(�8�8�8���
�
.7�!�^�J�)�)���
�
�
rlc���t|t��st|t��r|dkstd|�d����||_|dkrt
nt|dz��|jd<dS)a}Set the max idle time.

        This method sets the max idle time.

        Args:
            max_idle_time (int): An integer equal or greater than 0 indicating
                                 the max idle time.

        Raises:
            :class:`AttributeError`: If the max_idle_time value is not an
                                     integer greater or equal to 0.
        r>zYConnection max_idle_time value must be an integer greater or equal to 0, the given value rrrxrN)rfr�r%r~r�_CNX_POOL_MAX_IDLE_TIMEr)rurs  rcrzClient._set_max_idle_time�	s���
�}�d�+�+�	��m�S�1�1�	�!�2�%�	�
!�L�/<�L�L�L���
�
+���'4��'9�X�#�#�s�=�SW�CW�?X�?X�	
�
�o�&�&�&rlc�\�t|t��std���||_dS)aSet if the pool is enabled.

        This method sets if the pool is enabled.

        Args:
            enabled (bool): True if to enabling the pool.

        Raises:
            :class:`AttributeError`: If the value of enabled is not a bool type.
        z*The enabled value should be True or False.N)rfr�r~r
)rurs  rcr	zClient._set_pool_enabled�	s4���'�4�(�(�	O� �!M�N�N�N�&����rlc��t|t��st|t��r|dkstd|�d����||_|dkrt
nt|dz��|jd<d|jvr|j|jd<dSdS)	a}Set the queue timeout.

        This method sets the queue timeout.

        Args:
            queue_timeout (int): An integer equal or greater than 0 indicating
                                 the queue timeout.

        Raises:
            :class:`AttributeError`: If the queue_timeout value is not an
                                     integer greater or equal to 0.
        r>zYConnection queue_timeout value must be an integer greater or equal to 0, the given value rrrxrrRN)rfr�r%r~r�_CNX_POOL_QUEUE_TIMEOUTr)rurs  rcrzClient._set_queue_timeout�	s���
�}�d�+�+�	��m�S�1�1�	�!�2�%�	�
!�L�/<�L�L�L���
�
+���'4��'9�X�#�#�s�=�SW�CW�?X�?X�	
�
�o�&�
�D�M�1�	B�/3�/A�D�M�+�,�,�,�	B�	Brlc�b�t|j��}|j�|��|S)z~Creates a Session instance using the provided connection data.

        Returns:
            Session: Session object.
        )r�rrr\�ru�sessions  rc�get_sessionzClient.get_session�	s.���$�-�(�(���
���W�%�%�%��rlc��t���|j��|jD]}|����dS)z*Closes the sessions opened by this client.N)r�rrrr�rs  rcr�zClient.close�	sL�����!�!�$�-�0�0�0��}�	(�	(�G��%�%�'�'�'�'�	(�	(rlr�)
r�r�r�r�rvr�r�rrr	rrr�r�rlrcrrj	s���������4�4�4�4�"������K�K�K�2
�
�
�8
'�
'�
'�B�B�B�@���(�(�(�(�(rlrc��|�dd��}d|vo1|�d��dko|�d��dko)|�d��o|�d��}g}t�|r
|dd�n|��}d	}|D�] }i}t�|��}|r@|�d��}t|�d
����|d<|dz
}n6t�|��}|r|�d��}d|d<td
|����}|jstd|�����	|�|j|j���n&#t $r}t#d|��d��|�d}~wwxYw|�|����"d	|cxkrt'|��krnnt#dd���|rd|in|d	S)z�Parses a list of host, port pairs.

    Args:
        path: String containing a list of routers or just router

    Returns:
        Returns a dict with parsed values of host, port and priority if
        specified.
    r���,r�r�[�]r>rr3rrz//zInvalid address: r>z
Invalid URI: i�NrrrM)�replacer�r��endswith�	_SPLIT_REr{�_PRIORITY_RE�match�groupr%�
_ROUTER_RErr�rrirLrzr#r\r�)	�pathr�rM�address_listr �addressr!r&r�s	         rc�_parse_address_listr,
s\���<�<��R� � �D�
��_�
M����C���1�!4�
M����C���A�9M�N�	��O�O�C� � �	��M�M�#���
��G��?�?��#@�4��"��:�:�D�A�A�L��N��������"�"�7�+�+���	)��k�k�!�n�n�G�!$�U�[�[��^�^�!4�!4�F�:���a��N�N��$�$�W�-�-�E��
)��+�+�a�.�.��%(��z�"���g���(�(���~�	@� �!>�W�!>�!>�?�?�?�	I��M�M�u�~�E�J�M�?�?�?�?���	I�	I�	I�"�#8�3�#8�#8�$�?�?�S�H�����	I����	���v������>�
�
�
�
�C��-�-�
�
�
�
�
��
*��
�
�	
�$)�8�I�w���g�a�j�8s�'!F	�	
F,�F'�'F,c��ddi}t�|��}|r|���nd|f\}}|dvrtd|�d����|dkrd|d	<|�d
��ddd�\}}|�d
��ddd�\}}|�d��}||d��d��dkr"|dkr|�dd��\}|d<|�d��}|r|rd|vrtd|�d����|�	dd��\}	}
t|	��t|
��c|d<|d<|�d��rt|��|d<nF|�d��rtd���|�t|����d}t|d��D]�\}}
|�dd�����}||vrtd |�d����|t"vr&t|
�d����||<�s|
���}|d!vrd||<��|d"vrd#||<��|||<��|S)$aqParses the connection string and returns a dictionary with the
    connection settings.

    Args:
        uri: mysqlx URI scheme to connect to a MySQL server/farm.

    Returns:
        Returns a dict with parsed values of credentials and address of the
        MySQL server/farm.

    Raises:
        :class:`mysqlx.InterfaceError`: If contains a invalid option.
    rJrrW)rW�
mysqlx+srvzScheme 'z' is not validr.TrV�@Nr3�?�/�)r>rrz()r�zMalformed URI 'r�rHrI)r1r6rrrNz\.zWindows Pipe is not supported)rHrIrVr[r*zInvalid option: ')�1�true)�0�falseF)�_URI_SCHEME_REr&�groupsr�	partition�rfind�find�rsplitr�r{rr�rir,rr"rV�	_SSL_OPTS)�urirr&�scheme�userinfo�tmprK�	query_str�posrHrI�invalid_optionsrb�val�opt�val_strs                rc�_parse_connection_urirH8
s����"�~�H�� � ��%�%�E�$)�>�%�,�,�.�.�.��#��K�F�C�
�-�-�@��>��>�>�>�?�?�?�
���#�"�����M�M�#�&�&�s�s��s�+�M�H�c��m�m�C�(�(���1��-�O�D�)�
�*�*�S�/�/�C��C�D�D�z���s���r�!�7�c�A�g�7�#'�;�;�s�A�#6�#6� ��h�x� ��:�:�d���D��7�x�7�3�h�#6�7��5�s�5�5�5�6�6�6��^�^�C��+�+�N�D�(�-4�T�]�]�G�H�<M�<M�*�H�V��h�z�*����'�(�(�3�$�T�]�]�����	
����	�	�3��<�=�=�=����+�D�1�1�2�2�2�5�O��i��.�.�
(�
(���S��k�k�#�s�#�#�)�)�+�+���/�!�	=� �!;�S�!;�!;�!;�<�<�<��)��		(�#�C�I�I�d�O�O�4�4�H�S�M�M��i�i�k�k�G��-�'�
(� $���
�
��N�*�
(� %���
�
� '���
�
��Orlc�\
�t|������t��}|r(d�|��}td|�d����d|vr|dD]}t
|d���nd|vrt
|��d|vr�|d}	tt|t��r&|�
�����n|��|d<n3#ttf$r}td|d�d���|�d	}~wwxYwd
|vr/|dtjtjfvrtd���d|vrd
|vrtd
���d|vrd|vrtd���d
|vrG|�d��tjtjtjfvrtd���d|vr�|d}	t%t|t��r&|�
�����n|��|d<n3#ttf$r}td|d�d���|�d	}~wwxYwd|vr�|d}	t't|t��r&|�
�����n|��|d<n3#ttf$r}td|d�d���|�d	}~wwxYwd|vr�t|dt��rN|d����d��}|r|�d��|d<n7d	|d<n1t|dt*t,f��std���|�d��t&jkrd	|d<d|vrt/|��d|vr�	t|dt��rt1|d��|d<t|dt0��r|ddkrt�n#t$rt3d��d	�wxYwd|vr�t|dt4��std ���|�d!��rtd"���|�d#��rtd$���|�d��rtd%���nd|vr|�d#��sd|d#<d&|vrt7|��d'|vrt9|��d	Sd	S)(anValidates the settings to be passed to a Session object
    the port values are converted to int if specified or set to 33060
    otherwise. The priority values for each router is converted to int
    if specified.

    Args:
        settings: dict containing connection settings.

    Raises:
        :class:`mysqlx.InterfaceError`: On any configuration issue.
    z', 'zInvalid option(s): 'r�rMr2rKrOzInvalid SSL Mode 'NrCzCannot verify Server without CArEzCA Certificate not providedrDrBzClient Certificate not providedz$Must verify Server if CA is providedrPzInvalid Auth 'rTzpThe connection property 'compression' acceptable values are: 'preferred', 'required', or 'disabled'. The value 'z' is not acceptablerUz[]rz@Invalid type of the connection property 'compression-algorithms'rSrRrzEThe connection timeout value must be a positive integer (including 0)rVz(The value of 'dns-srv' must be a booleanrNz<Using Unix domain sockets with DNS SRV lookup is not allowedrLz;Specifying a port number with DNS SRV lookup is not allowedzASpecifying multiple hostnames with DNS SRV look up is not allowedrFrG)�set�keys�
difference�
_SESS_OPTSr_r�_validate_hostsrrfr]rVr�r~rzr��	VERIFY_CArrbrrr{�listr2�_validate_connection_attributesr%�	TypeErrorr��_validate_tls_versions�_validate_tls_ciphersuites)	r�invalid_opts�invalid_opts_listr!r�r�rPrT�compression_algorithmss	         rc�_validate_settingsrXw
s����x�}�}���'�'�2�2�:�>�>�L��J�"�K�K��5�5���H�4E�H�H�H�I�I�I��H��"��y�)�	+�	+�F��F�E�*�*�*�*�	+�	�8�	�"���!�!�!��X��D��J�'��	X�#*�,6�x��,E�,E�S���� � �&�&�(�(�(�8�$�$�H�Z� � ���
�+�	X�	X�	X� �!M�h�z�6J�!M�!M�!M�N�N�TW�W�����	X�����8�#�	D���(<��#���A
�)
�	D�!�!B�C�C�C��H��<���!9�<��:�;�;�;��H��@��8�!;�@��>�?�?�?��8��E����Z� 8� 8�������A�!�E�
�C�D�D�D�
���P�����	P�#�(2�4��(=�(=�G��
�
���"�"�$�$�$�4� � �H�V�����
�+�	P�	P�	P� �!E�(�6�2B�!E�!E�!E�F�F�C�O�����	P������ �
��}�-��	�&1��k�3�/�/�!��!�!�#�#�)�)�+�+�+� �'�'�H�]�#�#��
�
�+�	�	�	� �A��]�+�A�A�A����	
�����	���� �8�+�6��h�7�8�#�>�>�	��1�2�8�8�:�:�@�@��F�F�
#�&�
:�5K�5Q�5Q�RU�5V�5V��1�2�2�59��1�2�2��H�%=�>��u�
�N�N�	� �R���
��<�<�
�&�&�+�*>�>�	6�15�H�-�.��(�*�2�'��1�1�1��H�$�
�	��(�#4�5�s�;�;�
O�.1�(�;L�2M�.N�.N��*�+��x�(9�:�C�@�@�
!��-�.��2�
!�!� �	
!��
�	�	�	��(����
�	�����H��!��(�9�-�t�4�4�	M� �!K�L�L�L��<�<��!�!�	� �N���
��<�<����	� �M���
��<�<�	�"�"�	� �S���
�	�
�8�	�!�H�L�L��$8�$8�!� ������!�)��x�(�(�(��X�%�-�"�8�,�,�,�,�,�-�-sX�$A
C2�2D"�D�D"�A
H,�,I�=I�I�,A
J:�:K*�K%�%K*�A!P-�-Qc���d|vr�|dr�	t|d��|d<|ddks|ddkrtdd���nB#t$rtdd��d�t$rtd|d��d��d�wxYwd	|vrA|d	r9	t|d	��|d	<dS#t$rt	d
��d�wxYwd|vr	|r	||d	<dSdSdS)z�Validate hosts.

    Args:
        settings (dict): Settings dictionary.
        default_port (int): Default connection port.

    Raises:
        :class:`mysqlx.InterfaceError`: If priority or port are invalid.
    rrrz1Invalid priority value, must be between 0 and 100rzInvalid priorityNzInvalid priority: rLzInvalid portrK)r%r#�	NameErrorrzr)r�default_ports  rcrNrN�
s����X��
�(�:�"6�
�	�#&�x�
�';�#<�#<�H�Z� ��
�#�a�'�
�8�J�+?�#�+E�
�&�G�����
��
�	G�	G�	G�"�#5�t�<�<�$�F��	�	�	�"�;�X�j�%9�;�;�T����
�	����
���(�h�v�.�(�	;�"�8�F�#3�4�4�H�V������	;�	;�	;� ��0�0�d�:�	;����	�8�	�(��(�'������(�(�(�(s�AA�?B�B8�8Cc�V�i}d|vrdS|d}t|t��r�|dkri|d<dS|�d��r|�d��s|dvrt	d|�d����|dvr|d	vrd
|d<ni|d<dS|dd��d
��}|D]_}|dkr�	|�d��}|d}t
|��dkr|dnd}||vrt	d|�d����|||<�`�n4t|t��r7|D]3}||}t|t��st|��}|||<�4n�t|t��s|dvr|ri|d<nd
|d<dSt|t��r|D]}d||<�n�t|t��rc|D]_}|dkr�	|�d��}|d}t
|��dkr|dnd}||vrt	d|�d����|||<�`n(t|t��st	d|�d����|r�|���D]�\}}t|t��st	d|�d����t
|��dkrt	d|�d����|�d��rt	d|�d����t|t��st	d|�d|�d����t
|��dkrt	d|�d|�d������||d<dS)z�Validate connection-attributes.

    Args:
        settings (dict): Settings dictionary.

    Raises:
        :class:`mysqlx.InterfaceError`: If attribute name or value exceeds size.
    rSNrr r!)�Falser6�Truer4z]The value of 'connection-attributes' must be a boolean or a list of key-value pairs, found: 'r�)r]r6Frr>r�=rzDuplicate key 'z' used in connection-attributes)rrzLconnection-attributes must be Boolean or a list of key-value pairs, found: 'r�r�r�r�r[zBKey names in connection-attributes cannot start with '_', found: 'zAttribute 'r�r�r�)
rfr]r�r#rr{r�rg�reprr�rJrPr�)	rrYrl�conn_attributes�attr�
attr_name_valr��attr_valr�s	         rcrQrQs����J��h�.�����1�2�J��*�c�"�"�<
����	�02�H�,�-��F��!�!�#�&�&�	�+5�+>�+>�s�+C�+C�	�� B�B�	�!�B�4>�B�B�B���
��;�;�	��/�/�
7�49��0�1�1�46��0�1��F�$�Q�r�T�*�0�0��5�5��#�
	-�
	-�D��r�z�
�� �J�J�s�O�O�M�%�a�(�I�+.�}�+=�+=��+A�I�}�Q�'�'�r�H��J�&�
�$�P�i�P�P�P����%-�J�y�!�!�
	-�
�J��	%�	%�
�#�	/�	/�I�#�I�.�J��j�#�.�.�
.�!�*�-�-�
�$.�J�y�!�!�		/�

�J��	%�	%�
��v�)=�
��	6�02�H�,�-�-�05�H�,�-���	�J��	$�	$�
�#�	'�	'�I�$&�J�y�!�!�	'�	�J��	%�	%�
��
	-�
	-�D��r�z�
�� �J�J�s�O�O�M�%�a�(�I�+.�}�+=�+=��+A�I�}�Q�'�'�r�H��J�&�
�$�P�i�P�P�P����%-�J�y�!�!�
	-��
�D�
)�
)�
��
,�(�
,�
,�
,�
�
�	
�
��%/�%5�%5�%7�%7�	�	�!�I�z��i��-�-�
�$�I�y�I�I�I�����9�~�~��"�
�$�T�y�T�T�T�����#�#�C�(�(�
�$�1�$-�1�1�1�����j�#�.�.�
�$�$�)�$�$�z�$�$�$����
�:����%�
�$�1�)�1�1�z�1�1�1����
�)3�H�
$�%�%�%rlc�n�g}d|vrdS|d}t|t��r�|�d��r|�d��st	d|�d����|dd��d	��}|D]Y}|���}|d
kr�||vr#t	tjd|������|�	|���Zn�t|t��rS|st	d
���|D]>}||vr#t	tjd|������|�	|���?n^t|t��r|D]}|�	|���n.t	dd�t���d|�d����|st	d
���g}g}g}|D]T}|tvr|�	|��|tvr|�	|���?|�	|���U|rP|dgkr.ts't!t#j|t�����|���||d<dS|r't!t'j|t�����|r't	t)j|t�����dS)z�Validate tls-versions.

    Args:
        settings (dict): Settings dictionary.

    Raises:
        :class:`mysqlx.InterfaceError`: If tls-versions name is not valid.
    rFNr r!z%tls-versions must be a list, found: 'r�rr>rr�tls_versions�rPr�zKAt least one TLS protocol version must be specified in 'tls-versions' list.z>tls-versions should be a list with one or more of versions in r�z
. found: 'r)rfr]r�r#rr{r�r7r�r\rPrJr_rrr�r r8r�r9r:)	rrf�tls_versions_settings�tls_vers�tls_verr��use_tls_versions�deprecated_tls_versions�not_tls_versionss	         rcrSrS�s����L��X�%����$�^�4���'��-�-�(
�!�,�,�S�1�1�	�%�.�.�s�3�3�	�!�P�8M�P�P�P���
�)��2��.�4�4�S�9�9���
	-�
	-�G�!�-�-�/�/�K��b� �
���l�*�
�$�,�3�+�;�������

����,�,�,�,�
	-�
�)�4�	0�	0�
�$�	� �4���
�-�	)�	)�G��,�&�
�$�,�3��w�W�W�W����
����(�(�(�(�	)�
�)�3�	/�	/�
�,�	)�	)�G�����(�(�(�(�	)��
L��y�y�/�0�0�
L�
L�<H�
L�
L�
L�
�
�	
�
�
��
#�
�
�	
�
�� �����-�-���,�,�	-��#�#�G�,�,�,��-�-�	-�#�*�*�7�3�3�3�3��#�#�G�,�,�,�,��X��	�{�*�	�3E�	�#�$�+�L�:P�Q�Q���
�	������#3��� � � �	 �X��(�/�'�)?�
�
�
�
�	
�

�X��.�5�g�?U�V�V�W�W�W�X�Xrlc���g}d|vrdS|d}t|t��r�|�d��r|�d��st	d|�d����|dd��d	��}|st	d
���|D]?}|������}|r|�|���@n<t|ttf��r
d�|D��}nt	d|�d����|�d
d���tdd�n|d
dd�}|�
d���|d}g}i}g}	tdtj|��dz�D]B}
|�t |
��|	�t$|
���C|D]{}d|vr||	vr|�|��� ||vrE||}||vr#t't)jd|������|�|���it	d|�d����|st	d
���||d<dS)z�Validate tls-ciphersuites.

    Args:
        settings (dict): Settings dictionary.

    Raises:
        :class:`mysqlx.InterfaceError`: If tls-ciphersuites name is not valid.
    rGNr r!z)tls-ciphersuites must be a list, found: 'r�rr>rz:No valid cipher suite found in the 'tls-ciphersuites' listc��g|]}|�|��Sr�r�)r$�tls_css  rcr%z._validate_tls_ciphersuites.<locals>.<listcomp>s��U�U�U�v�f�U�F�U�U�UrlzItls-ciphersuites should be a list with one or more ciphersuites. Found: 'rFTr�rr*�tls_ciphersuitesrgzThe value 'z.' in cipher suites is not a valid cipher suite)rfr]r�r#rr{r��upperr\rPrJrrr�r-rirr�rr~r7r�)
rrq�tls_ciphersuites_settings�tls_cssrprf�
newer_tls_ver�translated_names�iani_cipher_suites_names�ossl_cipher_suites_namesrjr��translated_names
             rcrTrT�sJ������)���� (�);� <���+�S�1�1�
�%�0�0��5�5�	�)�2�2�3�7�7�	�!�1�-�1�1�1���
�,�A�b�D�1�7�7��<�<���	� �L���
��	0�	0�F��\�\�^�^�)�)�+�+�F��
0� �'�'��/�/�/��	0�
�-��c�{�	;�	;�
�U�U�1J�U�U�U����
4�0�
4�
4�
4�
�
�	
��<�<���-�-�	)��q�q�q�!�!�
�n�
%�a�a�a�
(�����d��#�#�#� ��O�M���!��!��*�9�
 �
&�}�
5�
5��
9�9��C�C��	!�'�'�(9�'�(B�C�C�C� �'�'�(8��(A�B�B�B�B� �����$�;�	�4�#;�;�	��#�#�D�)�)�)�)�
�-�
-�	�6�t�<�O��"2�2�
�$�,�3�/��������

�#�#�O�4�4�4�4� �R�d�R�R�R���
��
��H�
�
�	
�$4�H�
� � � rlc���i}|r�t|dt��rt|d��}n�t|dt��r9|d���D]\}}|||�dd��<�n5|r3|���D]\}}|||�dd��<�|st
d���t|��|S)aZParses the connection string and returns a dictionary with the
    connection settings.

    Args:
        *args: Variable length argument list with the connection data used
               to connect to the database. It can be a dictionary or a
               connection string.
        **kwargs: Arbitrary keyword arguments with connection data used to
                  connect to the database.

    Returns:
        mysqlx.Session: Session object.

    Raises:
        TypeError: If connection timeout is not a positive integer.
        :class:`mysqlx.InterfaceError`: If settings not provided.
    rr[r*zSettings not provided)rfr]rHrgr�r"rrX)r�r`rrbrEs     rc�_get_connection_settingsr{Bs���$�H��2��d�1�g�s�#�#�	6�,�T�!�W�5�5�H�H�
��Q���
&�
&�	6� ��G�M�M�O�O�
6�
6���S�25�����S�#�.�.�/�/��	�2������	2�	2�H�C��.1�H�S�[�[��c�*�*�+�+��6��4�5�5�5��x� � � ��Orlc�8�t|i|��}t|��S)a�Creates a Session instance using the provided connection data.

    Args:
        *args: Variable length argument list with the connection data used
               to connect to a MySQL server. It can be a dictionary or a
               connection string.
        **kwargs: Arbitrary keyword arguments with connection data used to
                  connect to the database.

    Returns:
        mysqlx.Session: Session object.
    )r{r�)r�r`rs   rcrrfs$��(��8��8�8�H��8���rlc�6�t|ttf��std���t	|��}t|ttf��std���t|t��r8	tj|��}nW#t$r}td��|�d}~wwxYwi}|���D]\}}|||�	dd��<�t|t��std���i}d|vr�|�
d��}t|t��std���|�
d	d
��|d	<|�
dd��|d<|�
d
d��|d
<|�
dd��|d<t|��dkrtd|�����t|��dkr$td|��������t||��S)a8Creates a Client instance with the provided connection data and settings.

    Args:
        connection_string: A string or a dict type object to indicate the             connection data used to connect to a MySQL server.

            The string must have the following uri format::

                cnx_str = 'mysqlx://{user}:{pwd}@{host}:{port}'
                cnx_str = ('mysqlx://{user}:{pwd}@['
                           '    (address={host}:{port}, priority=n),'
                           '    (address={host}:{port}, priority=n), ...]'
                           '       ?[option=value]')

            And the dictionary::

                cnx_dict = {
                    'host': 'The host where the MySQL product is running',
                    'port': '(int) the port number configured for X protocol',
                    'user': 'The user name account',
                    'password': 'The password for the given user account',
                    'ssl-mode': 'The flags for ssl mode in mysqlx.SSLMode.FLAG',
                    'ssl-ca': 'The path to the ca.cert'
                    "connect-timeout": '(int) milliseconds to wait on timeout'
                }

        options_string: A string in the form of a document or a dictionary             type with configuration for the client.

            Current options include::

                options = {
                    'pooling': {
                        'enabled': (bool), # [True | False], True by default
                        'max_size': (int), # Maximum connections per pool
                        "max_idle_time": (int), # milliseconds that a
                            # connection will remain active while not in use.
                            # By default 0, means infinite.
                        "queue_timeout": (int), # milliseconds a request will
                            # wait for a connection to become available.
                            # By default 0, means infinite.
                    }
                }

    Returns:
        mysqlx.Client: Client object.

    .. versionadded:: 8.0.13
    z(connection_data must be a string or dictz+connection_options must be a string or dictzA'pooling' options must be given in the form of a document or dictNr*r[r�z<'pooling' options must be given in the form document or dictrTrrrrrzUnrecognized pooling options: z!Unrecognized connection options: )rfr]rgrr{�json�loadsr
r�r"r\r�rKr)	�connection_string�options_string�
settings_dictrr�rbr��pooling_options_dict�pooling_optionss	         rc�
get_clientr�wsf��d�'�#�t��5�5�I��G�H�H�H�,�->�?�?�M��n�s�D�k�2�2�L��J�K�K�K��.�#�&�&�
8�	��:�n�5�5�L�L���	�	�	� �S����
�����	����
��(�.�.�0�0�	8�	8�J�C��27�L����S�#�.�.�/�/��l�D�)�)�
��O�
�
�	
����L� ��&�*�*�9�5�5���/�D�2�2�	� �N���
�+:�*=�*=�i��*N�*N��Y�'�+:�+>�+>�z�2�+N�+N��Z�(�0?�0C�0C�O�UV�0W�0W��_�-�0?�0C�0C�O�UV�0W�0W��_�-�����!�#�	U� �!S�/�!S�!S�T�T�T��|���q� �	� �I�L�4E�4E�4G�4G�I�I���
��-�!5�6�6�6s�<B�
B0�B+�+B0r�)�r�r�r��PROTOCOL_TLSv1�PROTOCOL_TLSv1_1�PROTOCOL_TLSv1_2r��hasattrr�PROTOCOL_SSLv23rr��ImportErrorr~�loggingr�ryrr*�rerNr}rxr�r��
dns.exceptionr��dns.resolverr�r	r
�	functoolsr�json.decoderr
�urllib.parserrr�authenticationrrr�	constantsrrrrrrrr�crudr�errorsrr r!r"r#r$�helpersr%r&r'�protobufr(r@r)r*r+r,r-r�r.r/r0r1r2r�r3r4r5r)r\�mysql.connector.abstractsr7r8r9r:�mysql.connector.utilsr;�mysql.connector.versionr<r=r�r�r�r�r�r0rr�compilerrr�_PENALTY_SERVER_OFFLINE�_PENALTY_MAXED_OUT�_PENALTY_NO_ADD_INFO�_PENALTY_CONN_TIMEOUT�_PENALTY_WRONG_PASSW�_PENALTY_RESTARTINGr�rhr$�VERBOSEr%r(r7r=rM�	getLoggerrvrdrkrnr�rgr�rr�r�rr�r�r�rr,rHrXrNrQrSrTr{rr�r�rlrc�<module>r�s���:;�:���J�J�J��M��#��'��'���L��7�3��'�'�	!����
�
 ����
!���m�4�4�H�����������M����L�L�L�����
��������	�	�	�	���������
�
�
�
�	�	�	�	�
�
�
�
�
�
�
�
�����������������������N�N�������N�N�N�����
)�(�(�(�(�(�(�(�������(�(�(�(�(�(�5�5�5�5�5�5�5�5�5�5�V�V�V�V�V�V�V�V�V�V�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�����������������������G�F�F�F�F�F�F�F�F�F�������Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�Q�G�G�G�G�G�G�G�G�G�G�G�G�G�G�C�C�C�C�C�C�C�C�C�C���������������������5�4�4�4�4�4�4�4�4�4�4�4�4�4��I�������3��;��R��+������!�r�z�"9�:�:��!��!��"��������#����+�$�/�*�-�)�&�)����!%�&9�:���B�J�)�*�*�	��r�z�>��
�K�K��
�R�Z�1�2�:�
>�
>�
����A�B�B��
�
�
�	������
�"�'�
�H�
%�
%�����8:�:�:�o(�o(�o(�o(�o(�o(�o(�o(�d;�;�;�|!,�!,�!,�!,�!,�T�!,�!,�!,�HA'�A'�A'�A'�A'�A'�A'�A'�Hp
�p
�p
�p
�p
�p
�p
�p
�fF'�F'�F'�F'�F'�z�F'�F'�F'�RT#�T#�T#�T#�T#�U�[�T#�T#�T#�ny)�y)�y)�y)�y)�y)�y)�y)�xU,�U,�U,�U,�U,�U,�U,�U,�p
T(�T(�T(�T(�T(�T(�T(�T(�n49�49�49�n<�<�<�~B-�B-�B-�J(�(�(�(�Dm3�m3�m3�`XX�XX�XX�vV4�V4�V4�r!�!�!�H���"`7�`7�`7�`7�`7s$�AA�A�A�B�B'�&B'