a
    còf¿b ã                	   @   s(  d Z z\ddlZdZejejejdœZeedƒr:ejed< n
ej	ed< eedƒrZej
rZdZndZW n   dZdZY n0 ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZzddlZddlZW n eyø   dZY n0 dZdd	lmZmZ dd
lmZ ddl m!Z!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z.m/Z/m0Z0 ddl1m2Z2m3Z3m4Z4 ddl5m6Z6m7Z7m8Z8m9Z9m:Z: ddl;m<Z<m=Z=m>Z>m?Z?m@Z@ ddlAmBZBmCZCmDZD ddlEmFZF ejG Hd¡ ddlImJZJ ddlKmLZLmMZM dZNdZOdZPdZQdZRdZSdZTe Ud¡ZVd ZWd ZXd!ZYd"ZZd#Z[d#Z\d$Z]d"Z^eZeZeYeYe\e[e[e]d%œZ_d&e^iZ`d'd(d)d*œZae bd+¡Zcd,d-„ Zdd.d/„ ZeG d0d1„ d1efƒZgd2d3„ ZhG d4d5„ d5eiƒZjG d6d7„ d7ƒZkG d8d9„ d9efƒZlG d:d;„ d;elƒZmG d<d=„ d=ejnƒZoG d>d?„ d?efƒZpG d@dA„ dAefƒZqG dBdC„ dCefƒZrdS )Dz4Implementation of communication for MySQL X servers.é    NT)ÚTLSv1úTLSv1.1úTLSv1.2ÚPROTOCOL_TLSúTLSv1.3ÚHAS_TLSv1_3F)ÚdatetimeÚ	timedelta©Úwrapsé   )ÚMySQL41AuthPluginÚPlainAuthPluginÚSha256MemoryAuthPlugin)ÚInterfaceErrorÚNotSupportedErrorÚOperationalErrorÚ	PoolErrorÚProgrammingErrorÚTimeoutError©ÚSchema)ÚSSLModeÚAuthÚCOMPRESSION_ALGORITHMS)ÚescapeÚget_item_or_attrÚiani_to_openssl_cs_name)ÚProtocolÚMessageReaderÚMessageWriterÚHAVE_LZ4Ú	HAVE_ZSTD)Ú
BaseResultÚResultÚ	RowResultÚ	SqlResultÚ	DocResult)ÚSqlStatementÚAddStatementÚquote_identifier)ÚProtobufz..)Úlinux_distribution)ÚVERSIONÚLICENSEi'  zDROP DATABASE IF EXISTS {0}z!CREATE DATABASE IF NOT EXISTS {0}zLSELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '{}'zSHOW VARIABLES LIKE "VERSION"éc   éx   z[^a-zA-Z0-9._:\-*$#]i›Ä  i@B é<   i  i€Q )z[WinError 10053]z
[Errno 32]z[WinError 10061]z[Errno 111]z[WinError 10060]z[Errno 11001]z
[Errno -2]zAccess deniedé  z‘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  r2   ia  Úmysqlxc               	   K   sN   g }dD ].}z|  t| | ƒ¡ W q ty4   Y q0 q|sDtdƒ‚d |¡S )ab  Generate 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.
    )ÚhostÚportÚuserZdatabaseÚ	client_idz.Failed generating pool name; specify pool_nameÚ_)ÚappendÚstrÚKeyErrorr   Újoin)ÚkwargsÚpartsÚkey© r@   úN/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/mysqlx/connection.pyÚgenerate_pool_name�   s    rB   c                 C   s   | rt | tƒrt | ¡ dS )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)Zpenalty_dictr@   r@   rA   Ú!update_timeout_penalties_by_error¬   s    rG   c                   @   sl   e Zd ZdZdd„ Zefdd„Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚSocketStreamzImplements a socket stream.c                 C   s   d | _ d| _d| _d | _d S )NF)Ú_socketÚ_is_sslÚ
_is_socketÚ_host©Úselfr@   r@   rA   Ú__init__¸   s    zSocketStream.__init__c                 C   sœ   |dur|d }zt  ||¡| _|d | _W n^ tyŠ   z0t   t j¡| _| j |¡ | j |¡ d| _W n t	y„   t
dƒ‚Y n0 Y n0 | j d¡ dS )zÇConnects to a TCP service.

        Args:
            params (tuple): The connection parameters.

        Raises:
            :class:`mysqlx.InterfaceError`: If Unix socket is not supported.
        Néè  r   TzUnix socket unsupported)ÚsocketÚcreate_connectionrI   rL   Ú
ValueErrorÚAF_UNIXÚ
settimeoutÚconnectrK   ÚAttributeErrorr   )rN   ÚparamsÚconnect_timeoutr@   r@   rA   rV   ¾   s    	
zSocketStream.connectc                 C   s\   | j du rtdƒ‚g }|dkrR| j  |¡}|dkr:tdƒ‚| |¡ |t|ƒ8 }qd |¡S )z“Receive data from the socket.

        Args:
            count (int): Buffer size.

        Returns:
            bytes: The data received.
        NúMySQLx Connection not availabler   ó    zUnexpected connection close)rI   r   ÚrecvÚRuntimeErrorr9   Úlenr<   )rN   ÚcountÚbufÚdatar@   r@   rA   ÚreadÖ   s    	

zSocketStream.readc              
   C   s\   | j du rtdƒ‚z| j  |¡ W n4 tjyV } ztd |¡ƒ‚W Y d}~n
d}~0 0 dS )z_Send data to the socket.

        Args:
            data (bytes): The data to be sent.
        NrZ   zUnexpected socket error: {})rI   r   ÚsendallrQ   ÚerrorÚformat)rN   ra   Úerrr@   r@   rA   rc   ê   s    
zSocketStream.sendallc                 C   sF   | j s
dS z| j  tj¡ | j  ¡  W n tjy:   Y n0 d| _ dS )zClose the socket.N)rI   ÚshutdownrQ   Ú	SHUT_RDWRÚcloserd   rM   r@   r@   rA   ri   ÷   s    zSocketStream.closec                 C   s   |   ¡  d S ©N©ri   rM   r@   r@   rA   Ú__del__  s    zSocketStream.__del__c                 C   s”  t s|  ¡  tdƒ‚|du s |sLt ¡ }|tjkr8d|_|tjkrâtj	|_
n–|jdd� |d }	ts€|	dkr€t|ƒdkr€|d }	t|	 }
t |
¡}|	dkrâd	|vr²| jtjO  _d
|vrÊ| jtjO  _d|vrâ| jtjO  _|�rBz| |¡ tj|_
W nB ttjf�y@ } z"|  ¡  td |¡ƒ‚W Y d}~n
d}~0 0 |�r¢z| |¡ tj|_W nB ttjf�y  } z"|  ¡  td |¡ƒ‚W Y d}~n
d}~0 0 |�rüz| ||¡ W nB ttjf�yú } z"|  ¡  td |¡ƒ‚W Y d}~n
d}~0 0 |�r| d t|d |ƒ¡¡ z|j | j!| j"d�| _!W n4 tj#�yh } ztt$|ƒƒ‚W Y d}~n
d}~0 0 |tjk�r^d|_g }t%j&dk�r¬| j"dk�s¤| j"dk�r¬ddg}t' (| j"¡}| )|d g|d  ¡ d}g }|D ]^}zt *| j! +¡ |¡ W n6 tj#�y, } z| ,t$|ƒ¡ W Y d}~nd}~0 0 d} �q<�qÜ|�s^|  ¡  td d |¡¡ƒ‚d| _-| j! .¡ }	|	dv �r�d|	› d�}t/ 0|t1¡ dS )ax  Set 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)Úreverser   r   r   r   r   r   zInvalid CA Certificate: {}zInvalid CRL: {}zInvalid Certificate/Key: {}ú:)Úserver_hostnameÚntÚ	localhostz	127.0.0.1z$Unable to verify server identity: {}z, )r   r   zThis connection is using zZ which is now deprecated and will be removed in a future release of MySQL Connector/Python)2ÚSSL_AVAILABLEri   r]   ÚsslÚcreate_default_contextr   Z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   re   ÚVERIFY_CRL_CHECK_LEAFÚverify_flagsÚload_cert_chainÚset_ciphersr<   r   Úwrap_socketrI   rL   ÚCertificateErrorr:   ÚosÚnamerQ   ÚgethostbyaddrÚextendÚmatch_hostnameÚgetpeercertr9   rJ   ÚversionÚwarningsÚwarnÚDeprecationWarning)rN   Z
ssl_protosZssl_modeZssl_caZssl_crlZssl_certZssl_keyZssl_ciphersÚcontextZtls_versionÚssl_protocolrf   Z	hostnamesÚaliasesZmatch_foundZerrsÚhostnameZwarn_msgr@   r@   rA   Úset_ssl  sª    


ÿ
ÿ

$
$$ÿÿ"ÿ$
ÿ


ÿzSocketStream.set_sslc                 C   s   | j S )zpVerifies if SSL is being used.

        Returns:
            bool: Returns `True` if SSL is being used.
        )rJ   rM   r@   r@   rA   Úis_sslv  s    zSocketStream.is_sslc                 C   s   | j S )zŒVerifies if socket connection is being used.

        Returns:
            bool: Returns `True` if socket connection is being used.
        )rK   rM   r@   r@   rA   Ú	is_socket~  s    zSocketStream.is_socketc                 C   s   | j p
| jS )zvVerifies if connection is secure.

        Returns:
            bool: Returns `True` if connection is secure.
        )rJ   rK   rM   r@   r@   rA   Ú	is_secure†  s    zSocketStream.is_securec                 C   s
   | j duS )zrVerifies if connection is open.

        Returns:
            bool: Returns `True` if connection is open.
        N)rI   rM   r@   r@   rA   Úis_openŽ  s    zSocketStream.is_openN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rO   Ú_CONNECT_TIMEOUTrV   rb   rc   ri   rl   r™   rš   r›   rœ   r�   r@   r@   r@   rA   rH   ¶   s   prH   c                    s   t ˆ ƒ‡ fdd„ƒ}|S )zÆDecorator used to catch socket.error or RuntimeError.

    Raises:
        :class:`mysqlx.InterfaceError`: If `socket.Error` or `RuntimeError`
                                        is raised.
    c           	         sº  z¦t | ttfƒr$|  ¡ r$t|  ¡ Ž ‚ˆ | g|¢R i |¤Ž}t |tƒr¢| ¡ }|D ]P}|d tv rPt|d  }d 	|d |¡|d f}t | ttfƒrœ|  
|¡  q¢qP|W S  tjtttttf�y´ } zæˆ jdk�r–|�r–t |d tƒ�r–|d  ¡ }|�rŠ|d }t|d  }d 	|d |¡|d f}t | tƒ�r^| j ¡  |d dk�r^tƒ  | jt|Ž ¡ t | ttfƒ�rx|  
|¡ |  ¡  t|Ž ‚n
|  ¡  ‚ n
|  ¡  ‚ W Y d}~n
d}~0 0 dS )zWrapper function.ÚcodezConnection close: {}: {}ÚmsgÚget_column_metadatar   r2   N)rC   Ú
ConnectionÚPooledConnectionÚis_server_disconnectedr   Úget_disconnected_reasonr#   Zget_warningsÚCONNECTION_CLOSED_ERRORre   Úset_server_disconnectedrQ   rd   ÚConnectionResetErrorÚConnectionAbortedErrorr]   r   rž   r&   ÚpoolÚremove_connectionsÚPoolsManagerÚset_pool_unavailableÚ
disconnect)	rN   Úargsr=   Úresultr’   ÚwarningÚ	error_msgÚreasonrf   ©Úfuncr@   rA   Úwrapperž  s^    ÿ
ÿÿ
ÿÿÿÿ


z(catch_network_exception.<locals>.wrapperr
   )r¹   rº   r@   r¸   rA   Úcatch_network_exception—  s    +r»   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚRouterz“Represents a set of connection parameters.

    Args:
       settings (dict): Dictionary with connection settings
    .. versionadded:: 8.0.20
    c                 C   s   |   |¡ |  dd¡| d< d S )NÚ	availableT)rF   Úget)rN   Zconnection_paramsr@   r@   rA   rO   Ô  s    
zRouter.__init__c                 C   s   | d S )z’Verifies if the Router is available to open connections.

        Returns:
            bool: True if this Router is available else False.
        r½   r@   rM   r@   r@   rA   r½   Ø  s    zRouter.availablec                 C   s   d| d< dS )z:Sets this Router unavailable to open connections.
        Fr½   Nr@   rM   r@   r@   rA   Úset_unavailableà  s    zRouter.set_unavailablec                 C   s    d| v r| d S | d | d fS )z‘Verifies if the Router is available to open connections.

        Returns:
            tuple: host and port or socket information tuple.
        rQ   r4   r5   r@   rM   r@   r@   rA   Úget_connection_paramså  s    zRouter.get_connection_paramsN)rž   rŸ   r    r¡   rO   r½   r¿   rÀ   r@   r@   r@   rA   r¼   Í  s
   r¼   c                   @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	d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                 C   s0   || _ || _d| _d| _i | _g | _|  ¡  d S )Nr   T)Ú_routersÚ	_settingsÚ_cur_priority_idxÚ_can_failoverÚ_routers_directoryÚrouters_priority_listÚ_ensure_priorities)rN   ÚroutersÚsettingsr@   r@   rA   rO   ø  s    zRouterManager.__init__c                 C   sÜ   d}| j D ]<}| dd¡}|du r4|d7 }d|d< q
|dkr
tddƒ‚q
d|  k rbt| j ƒk rpn n
tdd	ƒ‚| j jd
d„ dd� | j D ]L}|d }|| j ¡ vrÂt|ƒg| j|< | j 	|¡ qŠ| j|  	t|ƒ¡ qŠdS )zuEnsure priorities.

        Raises:
            :class:`mysqlx.ProgrammingError`: If priorities are invalid.
        r   ÚpriorityNr   éd   z(The priorities must be between 0 and 100i§  z\You must either assign no priority to any of the routers or give a priority for every routeri   c                 S   s   | d S )NrË   r@   ©Úxr@   r@   rA   Ú<lambda>  r[   z2RouterManager._ensure_priorities.<locals>.<lambda>T)r?   rm   )
rÂ   r¾   r   r^   ry   rÆ   Úkeysr¼   rÇ   r9   )rN   Zpriority_countÚrouterrË   r@   r@   rA   rÈ     s*    

ÿþ
z RouterManager._ensure_prioritiesc                 C   s   | j | }d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                 S   s   g | ]}|  ¡ r|‘qS r@   )r½   )Ú.0rÑ   r@   r@   rA   Ú
<listcomp>*  r[   z8RouterManager._get_available_routers.<locals>.<listcomp>©rÆ   )rN   rË   Úrouter_listr@   r@   rA   Ú_get_available_routers#  s    
z$RouterManager._get_available_routersc                 C   sF   |   |¡}|sdS t|ƒdkr&|d S t|ƒd }t d|¡}|| S )z{Get a random router from the group with the given priority.

        Returns:
            Router: A random router.
        Nr   r   )rÖ   r^   ÚrandomÚrandint)rN   rË   rÕ   ÚlastÚindexr@   r@   rA   Ú_get_random_connection_params-  s    
z+RouterManager._get_random_connection_paramsc                 C   s   | j S )zŒReturns the next connection parameters.

        Returns:
            bool: True if there is more server to failover to else False.
        )rÅ   rM   r@   r@   rA   Úcan_failover=  s    zRouterManager.can_failoverc                 C   sÎ   | j sBd| _| j ¡ }| j dd¡|d< | j dd¡|d< t|ƒS | j| j }t| jƒ}d}|rÊ|  	|¡}|dus|| j|kr¤| j|d krÊt|  
|¡ƒd	k rÊd| _qÊ|  jd7  _| j|k r\| j| j }q\|S )
zvReturns the next connection parameters.

        Returns:
            Router: with the connection parameters.
        Fr4   rq   r5   i$�  TNr   é   )rÂ   rÅ   rÃ   Úcopyr¾   r¼   rÇ   rÄ   r^   rÛ   rÖ   )rN   Zrouter_settingsÚcur_priorityZrouters_priority_lenÚsearchrÑ   r@   r@   rA   Úget_next_routerE  s.    


ÿÿ
zRouterManager.get_next_routerc                 C   s   | j S )z™Returns the directory containing all the routers managed.

        Returns:
            dict: Dictionary with priorities as connection settings.
        rÔ   rM   r@   r@   rA   Úget_routers_directoryg  s    z#RouterManager.get_routers_directoryN)rž   rŸ   r    r¡   rO   rÈ   rÖ   rÛ   rÜ   rá   râ   r@   r@   r@   rA   rÁ   ð  s   
!
"rÁ   c                   @   sH  e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdEdd„Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZedd „ ƒZed!d"„ ƒZed#d$„ ƒZed%d&„ ƒZedFd'd(„ƒZed)d*„ ƒZed+d,„ ƒZed-d.„ ƒZed/d0„ ƒZed1d2„ ƒZd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Z d;d<„ Z!d=d>„ Z"d?d@„ Z#dAdB„ Z$dCdD„ Z%dS )Gr¦   zkConnection to a MySQL Server.

    Args:
        settings (dict): Dictionary with connection settings.
    c                 C   sÐ   || _ tƒ | _d | _d | _| d¡| _| d¡| _| d¡| _d | _	| dg ¡| _
d|v r‚|d r‚| j
 | d¡| dd ¡dœ¡ t| j
|ƒ| _| dt¡| _| jd	kr®d | _d	| _g | _d
| _d| _d | _d S )Nr6   ÚpasswordÚschemarÉ   r4   r5   )r4   r5   úconnect-timeoutr   TF)rÊ   rH   ÚstreamÚprotocolÚ	keep_openr¾   Ú_userÚ	_passwordZ_schemaÚ_active_resultrÂ   r9   rÁ   Úrouter_managerr¢   Ú_connect_timeoutÚ_stmt_counterÚ_prepared_stmt_idsÚ_prepared_stmt_supportedÚ_server_disconnectedÚ_server_disconnected_reason)rN   rÊ   r@   r@   rA   rO   v  s2    
þÿ
zConnection.__init__c                 C   s   | j dur| j  ¡  d| _ dS )zFetch active result.N)rë   Ú	fetch_allrM   r@   r@   rA   Úfetch_active_result•  s    

zConnection.fetch_active_resultc                 C   s
   || _ dS )a  Set active result.

        Args:
            `Result`: It can be :class:`mysqlx.Result`,
                      :class:`mysqlx.BufferingResult`,
                      :class:`mysqlx.RowResult`, :class:`mysqlx.SqlResult` or
                      :class:`mysqlx.DocResult`.
        N)rë   ©rN   r´   r@   r@   rA   Úset_active_result›  s    	zConnection.set_active_resultc              
   C   sš  d}| j  ¡ �r&zÚ| j  ¡ }| j | ¡ | j¡ t| jƒ}t| jƒ}t	||ƒ| _
| j
 ¡ j}|rndd„ |D ƒni }|  |¡ d| jv rž| jd }| j
j|d� | j dd¡}| j d¡}	|d	krÄdn|  |||	¡}
|  ¡  | j
 |
¡ W dS  tjtf�y" } z|}| ¡  W Y d}~qd}~0 0 q|du�rnt|tjƒ�rnt| jƒd
k�r^td | j¡ƒ‚td | j¡ƒ‚t| jƒd
k�rŒtd |¡ƒ‚tddƒ‚dS )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                 S   s   i | ]}t |d ƒ ¡ |“qS ©rŒ   )r   Úlower)rÒ   Úcapr@   r@   rA   Ú
<dictcomp>º  s   ÿz&Connection.connect.<locals>.<dictcomp>Ú
attributes©Zsession_connect_attrsÚcompressionÚ	preferredzcompression-algorithmsÚdisabledr   zLConnection attempt to the server was aborted. Timeout of {0} ms was exceededzdAll server connection attempts were aborted. Timeout of {0} ms was exceeded for each selected serverzCannot connect to host: {0}ú,Unable to connect to any of the target hostsi¡  )rì   rÜ   rá   ræ   rV   rÀ   rí   r   r    r   rç   Zget_capabilitesZcapabilitiesÚ_set_tls_capabilitiesrÊ   Úset_capabilitiesr¾   Ú_set_compression_capabilitiesÚ_authenticateZset_compressionrQ   rd   r]   r¿   rC   Útimeoutr^   rÂ   r   re   r   )rN   rd   rÑ   ÚreaderÚwriterZ	caps_dataÚcapsÚ
conn_attrsrý   Ú
algorithmsÚ	algorithmrf   r@   r@   rA   rV   ¦  sd    	
ÿ

ýþý


ÿþÿ þþÿzConnection.connectc                 C   sN  | j  d¡tjkrdS | j ¡ r:| j  d¡r6t d¡ dS d|vrR|  ¡  t	dƒ‚d}t
 ¡ dkr¤tƒ \}}}zd|v oˆ| d	¡d
 dk}W n ty¢   d}Y n0 tjdk rÂ|sÂ|  ¡  tdƒ‚| jjdd� | j | j  dd¡| j  dtj¡| j  d¡| j  d¡| j  d¡| j  d¡| j  d¡¡ d| j v �rJ| j d }| jj|d� dS )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
        zssl-modeNz(SSL not required when using Unix socket.ÚtlszSSL not enabled at serverFÚLinuxzOracle LinuxÚ.r   Ú7)rÝ   é   é	   z<The support for SSL is not available for this Python versionT)r  ztls-versionszssl-cazssl-crlzssl-certzssl-keyztls-ciphersuitesrû   rü   )rÊ   r¾   r   ZDISABLEDræ   r›   Ú_LOGGERrµ   Úclose_connectionr   ÚplatformÚsystemr,   ÚsplitÚ
IndexErrorÚsysÚversion_infor]   rç   r  r™   rv   )rN   r  Zis_ol7Údistnamer‘   r8   r	  r@   r@   rA   r  æ  sB    

ÿ





ú
z Connection._set_tls_capabilitiesNc                    s†  |  d¡}|du r4d}|dkr&t|ƒ‚t |¡ dS i }t|tƒr||d d d D ]&}dd	„ |d d
 d D ƒ||d < qRn*|jjjD ]}dd	„ |jj	jD ƒ||j
< q†|  dg ¡‰ d}|�rdd	„ |D ƒ}	‡ fdd	„|	D ƒ}
|
rðt  |
d ¡}n|dk�rtdƒ‚ndS |du �rBt�r(dˆ v �r(d}nt�r>dˆ v �r>d}nd}|ˆ v�rpd}|dk�rbt|ƒ‚t |¡ dS | jjd|id� |S )a  Set 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
        rý   Nz8Compression requested but the server does not support itÚrequiredÚvalueÚobjÚfldc                 S   s"   g | ]}|d  d d   d¡‘qS )ÚscalarÚv_stringr  úutf-8)Údecode©rÒ   r  r@   r@   rA   rÓ   ?  s   ÿz<Connection._set_compression_capabilities.<locals>.<listcomp>Úarrayr?   c                 S   s   g | ]}|j jj d ¡‘qS )r!  )r  r   r  r"  r#  r@   r@   rA   rÓ   E  s   ÿr  c                 S   s   g | ]}|t v rt | ‘qS r@   )r   ©rÒ   Úitemr@   r@   rA   rÓ   Q  s   ÿc                    s   g | ]}|ˆ v r|‘qS r@   r@   r%  ©Zserver_algorithmsr@   rA   rÓ   U  s   ÿr   zmThe connection compression is set as required, but none of the provided compression algorithms are supported.Zzstd_streamZlz4_messageZdeflate_streamzFCompression requested but the compression algorithm negotiation failed)rý   )r¾   r   r  rµ   rC   rD   r  r  r  r$  r?   r   r   r"   r!   rç   r  )rN   r  rý   r
  Zcompression_datar¤   Zcompression_dictr  r  Zclient_algorithmsÚmatchedr@   r'  rA   r    sZ    


þþÿ
ÿ





z(Connection._set_compression_capabilitiesc                 C   s°   | j  d¡}|rL|tjkr$|  ¡  q¬|tjkr8|  ¡  q¬|tjkr¬|  ¡  n`| j	 
¡ r`|  ¡  nLz|  ¡  W n ty~   Y n0 dS z|  ¡  W n tyª   tdƒ‚Y n0 dS )z#Authenticate with the MySQL server.ÚauthNzmAuthentication failed using MYSQL41 and SHA256_MEMORY, check username and password or try a secure connection)rÊ   r¾   r   ZPLAINÚ_authenticate_plainZSHA256_MEMORYÚ_authenticate_sha256_memoryZMYSQL41Ú_authenticate_mysql41ræ   rœ   r   )rN   r)  r@   r@   rA   r  w  s&    







zConnection._authenticatec                 C   sH   t | j| jƒ}| j | ¡ ¡ | j ¡ }| j | |¡¡ | j 	¡  dS )z=Authenticate with the MySQL server using `MySQL41AuthPlugin`.N)
r   ré   rê   rç   Úsend_auth_startÚ	auth_nameÚread_auth_continueÚsend_auth_continueÚ	auth_dataÚread_auth_ok©rN   ÚpluginÚ
extra_datar@   r@   rA   r,  ”  s
    
z Connection._authenticate_mysql41c                 C   sF   | j  ¡ stdƒ‚t| j| jƒ}| jj| ¡ | 	¡ d� | j 
¡  dS )z;Authenticate with the MySQL server using `PlainAuthPlugin`.z>PLAIN authentication is not allowed via unencrypted connection)r1  N)ræ   rœ   r   r   ré   rê   rç   r-  r.  r1  r2  )rN   r4  r@   r@   rA   r*  œ  s    
ÿzConnection._authenticate_plainc                 C   sH   t | j| jƒ}| j | ¡ ¡ | j ¡ }| j | |¡¡ | j 	¡  dS )zBAuthenticate with the MySQL server using `Sha256MemoryAuthPlugin`.N)
r   ré   rê   rç   r-  r.  r/  r0  r1  r2  r3  r@   r@   rA   r+  ¦  s
    
z&Connection._authenticate_sha256_memoryc                 C   s,   |j r(| j |j¡ | j |j¡ d|_ dS )zrDeallocates statement.

        Args:
            statement (Statement): A `Statement` based type object.
        FN)Úpreparedrç   Úsend_prepare_deallocateÚstmt_idrï   Úremove)rN   Ú	statementr@   r@   rA   Ú_deallocate_statement®  s    z Connection._deallocate_statementc                 C   sP   z|   ¡  | j |||¡ W n ty6   d| _Y dS 0 | j |j¡ d|_dS )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)	rô   rç   Zsend_prepare_preparer   rð   rï   r9   r8  r6  ©rN   Úmsg_typer¤   r:  r@   r@   rA   Ú_prepare_statement¹  s    zConnection._prepare_statementc                 C   s\  | j s| j |||¡ dS |jrr|  |¡ |  |||¡ | j sR| j |||¡ dS | j |||¡ d|_| ¡  nÞ|jr�|j	s�| j |||¡ nÀ|j	rÆ|j
sÆ|  |¡ | j |||¡ d|_	| ¡  nŠ|j	�s|j
�s|jsê|  |||¡ | j �s| j |||¡ dS | j |||¡ n8|j	�rP|j
�rP|  |¡ | j |||¡ d|_	| ¡  | ¡  dS )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)rð   rç   Úsend_msg_without_psZdeallocate_prepare_executer;  r>  Zsend_prepare_executeZreset_exec_counterr6  ÚchangedZrepeatedZincrement_exec_counterr<  r@   r@   rA   Ú_execute_prepared_pipelineÊ  s@    	




z%Connection._execute_prepared_pipelinec                 C   sV   |j }| jdu rtdƒ‚t|tƒs,tdƒ‚n| 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.
        NrZ   z'The SQL statement is not a valid stringÚsql)	rB  rç   r   rC   r:   r   Úbuild_execute_statementr?  r&   )rN   r:  rB  r=  r¤   r@   r@   rA   Úsend_sqlü  s    


ÿzConnection.send_sqlc                 C   sN   | j du rtdƒ‚| j  |¡\}}| j  ||¡ d}t|tƒrD|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.
        NrZ   )rç   r   Zbuild_insertÚsend_msgrC   r)   Úidsr$   )rN   r:  r=  r¤   rF  r@   r@   rA   Úsend_insert  s    

zConnection.send_insertc                 C   s6   | j  |¡\}}|  |||¡ | ¡ r.t| ƒS t| ƒS )aD  Send 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ç   Z
build_findrA  Zis_doc_basedr'   r%   ©rN   r:  r=  r¤   r@   r@   rA   Ú	send_find&  s    zConnection.send_findc                 C   s&   | j  |¡\}}|  |||¡ t| ƒS )a  Send an delete statement.

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

        Returns:
            :class:`mysqlx.Result`: The result object.
        )rç   Zbuild_deleterA  r$   rH  r@   r@   rA   Úsend_delete6  s    zConnection.send_deletec                 C   s&   | j  |¡\}}|  |||¡ t| ƒS )a  Send an delete statement.

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

        Returns:
            :class:`mysqlx.Result`: The result object.
        )rç   Zbuild_updaterA  r$   rH  r@   r@   rA   Úsend_updateE  s    zConnection.send_updatec                 C   sJ   z,| j  |||¡\}}| j  ||¡ t| ƒW S  tyD   |r@‚ Y n0 dS )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ç   rC  rE  r$   r   )rN   Ú	namespaceÚcmdZraise_on_failÚfieldsr=  r¤   r@   r@   rA   Úexecute_nonqueryT  s    ÿ
zConnection.execute_nonqueryc                 C   sN   | j  d|¡\}}| j  ||¡ t| ƒ}| ¡  |jdkrBtdƒ‚|d d S )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.
        rB  r   zNo data found)rç   rC  rE  r%   ró   r_   r   )rN   rB  r=  r¤   r´   r@   r@   rA   Úexecute_sql_scalarm  s    
zConnection.execute_sql_scalarc                 C   s*   | 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.
        r3   )rç   rC  rE  r%   )rN   rM  rN  r=  r¤   r@   r@   rA   Úget_row_result‚  s    ÿzConnection.get_row_resultc                 C   s   | j  |¡S )zdRead row.

        Args:
            result (:class:`mysqlx.RowResult`): The result object.
        )rç   Úread_rowrõ   r@   r@   rA   rR  ’  s    zConnection.read_rowc                 C   s   | j  |¡ dS )zeClose result.

        Args:
            result (:class:`mysqlx.Result`): The result object.
        N)rç   Úclose_resultrõ   r@   r@   rA   rS  ›  s    zConnection.close_resultc                 C   s   | j  |¡S )zlGet column metadata.

        Args:
            result (:class:`mysqlx.Result`): The result object.
        )rç   r¥   rõ   r@   r@   rA   r¥   ¤  s    zConnection.get_column_metadatac                 C   s   |  j d7  _ | j S )z|Returns the next statement ID.

        Returns:
            int: A statement ID.

        .. versionadded:: 8.0.16
        r   )rî   rM   r@   r@   rA   Úget_next_statement_id­  s    z Connection.get_next_statement_idc                 C   s
   | j  ¡ S )zgCheck if connection is open.

        Returns:
            bool: `True` if connection is open.
        )ræ   r�   rM   r@   r@   rA   r�   ¸  s    zConnection.is_openc                 C   s   d| _ || _dS )z†Set the disconnection message from the server.

        Args:
            reason (str): disconnection reason from the server.
        TN)rñ   rò   )rN   r·   r@   r@   rA   r«   À  s    z"Connection.set_server_disconnectedc                 C   s   | j S )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`.
        )rñ   rM   r@   r@   rA   r¨   É  s    z!Connection.is_server_disconnectedc                 C   s   | j S )z†Get the disconnection message sent by the server.

        Returns:
            string: disconnection reason from the server.
        )rò   rM   r@   r@   rA   r©   Ò  s    z"Connection.get_disconnected_reasonc                 C   s   |   ¡ sdS | j ¡  dS )zDisconnect from server.N)r�   ræ   ri   rM   r@   r@   rA   r²   Ú  s    zConnection.disconnectc              
   C   s¬   |   ¡ sdS zŽzD|  ¡  | jr<| jD ]}| j |¡ q$d| _| j ¡  | j ¡  W n: t	t
tfyŒ } zt d |¡¡ W Y d}~n
d}~0 0 W | j ¡  n| j ¡  0 dS )z*Close a sucessfully authenticated session.Nr   zGWarning: An error occurred while attempting to close the connection: {})r�   rô   rð   rï   rç   r7  rî   Z
send_closeÚread_okr   r   ÚOSErrorr  rµ   re   ræ   ri   )rN   r8  rf   r@   r@   rA   Úclose_sessionà  s    

ÿzConnection.close_sessionc              
   C   sr   |   ¡ sdS | jdur | j ¡  z| j | j¡| _W n8 ttfyl } zt 	d 
|¡¡ W Y d}~n
d}~0 0 dS )z*Reset a sucessfully authenticated session.NzDWarning: An error occurred while attempting to reset the session: {})r�   rë   ró   rç   Z
send_resetrè   r   r   r  rµ   re   )rN   rf   r@   r@   rA   Úreset_sessionø  s    

ÿzConnection.reset_sessionc                 C   sB   |   ¡ sdS | jdur | j ¡  | j ¡  | j ¡  | j ¡  dS )z€Announce to the server that the client wants to close the
        connection. Discards any session state of the server.
        N)r�   rë   ró   rç   Zsend_connection_closerU  ræ   ri   rM   r@   r@   rA   r    s    



zConnection.close_connection)N)N)&rž   rŸ   r    r¡   rO   rô   rö   rV   r  r  r  r,  r*  r+  r;  r>  rA  r»   rD  rG  rI  rJ  rK  rO  rP  rQ  rR  rS  r¥   rT  r�   r«   r¨   r©   r²   rW  rX  r  r@   r@   r@   rA   r¦   p  s\   @5 ÿ
]
2









		r¦   c                       sL   e Zd ZdZ‡ fdd„Z‡ fdd„Zdd„ Zdd	„ Zd
d„ Zdd„ Z	‡  Z
S )r§   a  Class 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                    sF   t |tƒstdƒ‚tt| ƒ |j¡ || _|jd | _|jd | _	d S )Nz&pool should be a ConnectionPool objectr4   r5   )
rC   ÚConnectionPoolrW   Úsuperr§   rO   Ú
cnx_configr®   r4   r5   )rN   r®   ©Ú	__class__r@   rA   rO   #  s    
zPooledConnection.__init__c                    s   t t| ƒ ¡  dS )zGCloses the connection.

        This method closes the socket.
        N)rZ  r§   rW  rM   r\  r@   rA   r  +  s    z!PooledConnection.close_connectionc                 C   s   | j  | ¡ dS )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_connectionrM   r@   r@   rA   rW  2  s    zPooledConnection.close_sessionc                 C   s    | j dur| j  ¡  |  ¡  dS )z#Reconnect this connection.
        N)rë   ró   r  rM   r@   r@   rA   Ú	reconnect?  s    

zPooledConnection.reconnectc                 C   s   |   ¡  dS )zQReset the connection.

        Resets the connection by re-authenticate.
        N)r_  rM   r@   r@   rA   ÚresetF  s    zPooledConnection.resetc                 C   s
   t | |ƒS ©a  Creates 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.
        )r(   ©rN   rB  r@   r@   rA   rB  M  s    
zPooledConnection.sql)rž   rŸ   r    r¡   rO   r  rW  r_  r`  rB  Ú__classcell__r@   r@   r\  rA   r§     s   r§   c                   @   sŠ   e Zd ZdZdd„ Zdd„ Zedd„ ƒZd d	d
„Zdd„ Z	d!dd„Z
dd„ Zdd„ Zdd„ Zdd„ Zd"dd„Zdd„ Zdd„ Zdd„ ZdS )#rY  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                 K   s¦   |   |¡ d| _g | _d| _d| _t ¡ | _| dd¡| _	t
j | | j	¡ | dd¡| _| dd¡| _|| _| dd¡| _| dd¡| _|| _|d	 | _|d
 | _d S )Nr   TÚmax_sizeé   rX  Úmax_idle_timeÚqueue_timeoutrË   r4   r5   )Ú_set_pool_nameZ_open_sessionsÚ_connections_opennedÚ
_availableÚ_timeoutr   ÚnowÚ_timeout_stampr¾   Úpool_max_sizeÚqueueÚQueuerO   rX  rf  rÊ   rg  rË   r[  r4   r5   )rN   rŒ   r=   r@   r@   rA   rO   v  s     


zConnectionPool.__init__c                 C   s<   t  |¡rtd |¡ƒ‚t|ƒtkr2td |¡ƒ‚|| _dS )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.
        z+Pool name '{0}' contains illegal characterszPool name '{0}' is too longN)Ú_CNX_POOL_NAME_REGEXrà   rW   re   r^   Ú_CNX_POOL_MAX_NAME_SIZErŒ   )rN   Ú	pool_namer@   r@   rA   rh  ‰  s    
ÿÿzConnectionPool._set_pool_namec                 C   s
   t | jƒS )zMReturns the number of open connections that can return to this pool.
        )r^   ri  rM   r@   r@   rA   Úopen_connectionsž  s    zConnectionPool.open_connectionsNc                 C   s   | j  |¡ dS )zwRemoves a connection from this pool.

        Args:
            cnx (PooledConnection): The connection object.
        N)ri  r9  ©rN   Úcnxr@   r@   rA   Úremove_connection¤  s    z ConnectionPool.remove_connectionc              
   C   s€   |   ¡ dkr|z| jd| jd�}W n tjy4   Y q 0 z6z| ¡  W n ttjt	fy^   Y n0 W |  
|¡ q |  
|¡ 0 q dS )z*Removes all the connections from the pool.r   T©Úblockr  N)Úqsizer¾   rg  ro  ÚEmptyr  r]   rQ   rd   r   rw  ru  r@   r@   rA   r¯   ¬  s    ÿ
z!ConnectionPool.remove_connectionsc                 C   sÆ   | j stdƒ‚|  ¡ rtdƒ‚|sŽt| ƒ}| d¡ ¡  ¡ d d }tdd„ | d¡d  d	¡D ƒƒd
kr€| d 	| j
¡¡ ¡  | j |¡ n*t|tƒs tdƒ‚| ¡ 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 fullzshow variables like "version"r   r   c                 S   s   g | ]}t |ƒ‘qS r@   ©Úint©rÒ   Únr@   r@   rA   rÓ   ×  r[   z1ConnectionPool.add_connection.<locals>.<listcomp>ú-r  ©é   r   é
   úset mysqlx_wait_timeout = {}ú2Connection instance not subclass of PooledSession.N)r[  r   Úfullr§   rB  Úexecuteró   Útupler  re   rf  ri  r9   rC   r¨   r¯   ri   Úqueue_connection)rN   rv  Úverr@   r@   rA   r^  ¼  s4    ÿÿ ÿÿ

ÿzConnectionPool.add_connectionc                 C   sT   t |tƒstdƒ‚| jr | ¡  z| j|dd� W n tjyN   tdƒ Y n0 dS )aG  Put 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.
        r†  F)ry  r|  N)rC   r§   r   rX  Úputro  ÚFullru  r@   r@   rA   rŠ  æ  s    
ÿzConnectionPool.queue_connectionc                 C   s   | j  |¡ dS )zNTracks connection in order of close it when client.close() is invoke.
        N)ri  r9   )rN   Ú
connectionr@   r@   rA   Útrack_connectionÿ  s    zConnectionPool.track_connectionc                 C   s   | j S rj   r÷   rM   r@   r@   rA   Ú__str__  s    zConnectionPool.__str__c                 C   s   | j S )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
        )rj  rM   r@   r@   rA   r½     s    zConnectionPool.availableéÿÿÿÿc                 C   s.   | j r*t d| |¡ d| _ t ¡ | _|| _dS )zhSets this pool unavailable for a period of time (in seconds).

        .. versionadded:: 8.0.20
        z4ConnectionPool.set_unavailable pool: %s time_out: %sFN)rj  r  rµ   r   rl  rm  rk  )rN   Ztime_outr@   r@   rA   r¿     s    ÿ
zConnectionPool.set_unavailablec                 C   s   d| _ t ¡ | _dS )zaSets this pool available for pool connections from it.

        .. versionadded:: 8.0.20
        TN)rj  r   rl  rm  rM   r@   r@   rA   Úset_available  s    zConnectionPool.set_availablec                 C   s   | j | jfS )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
        )rk  rm  rM   r@   r@   rA   Úget_timeout_stamp$  s    z ConnectionPool.get_timeout_stampc                 C   s   | j D ]}| ¡  qdS )z#Empty this ConnectionPool.
        N)ri  r  ru  r@   r@   rA   ri   -  s    
zConnectionPool.close)N)N)r‘  )rž   rŸ   r    r¡   rO   rh  Úpropertyrt  rw  r¯   r^  rŠ  r�  r�  r½   r¿   r’  r“  ri   r@   r@   r@   rA   rY  Z  s    


*	
	rY  c                   @   s„   e Zd ZdZdZi Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zddd„Zddd„Zdd„ Zdd„ Zdd„ ZdS )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                 C   s"   t jd u rt | ¡t _i t _t jS rj   )r°   Ú_PoolsManager__instanceÚobjectÚ__new__Ú_PoolsManager__pools)Úclsr@   r@   rA   r—  >  s    
zPoolsManager.__new__c                 C   s,   | j  |g ¡}|D ]}|j|kr dS qdS )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)r˜  r¾   rŒ   )rN   r7   rs  Úpoolsr®   r@   r@   rA   Ú_pool_existsD  s
    

zPoolsManager._pool_existsc                 C   s^   g }g }|   |¡}|D ]\}}| |¡ q| j | dd¡g ¡D ]}|j|v r@| |¡ q@|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.
        r7   úNo id)Ú_get_connections_settingsr9   r˜  r¾   rŒ   )rN   rÊ   Zavailable_poolsZ
pool_namesÚconnections_settingsÚrouter_namer8   r®   r@   r@   rA   Ú
_get_poolsT  s    	

zPoolsManager._get_poolsc                 C   sÈ   |  ¡ }| dg ¡}g }d|v r*| d¡ d|v rVd|v rV| dd|d |d dœ¡ |jdd„ d	� |D ]X}|  ¡ }|d |d< |d |d< |d
 |d
< | dd¡|d< | tf i |¤Ž|f¡ qj|S )aH  Generates 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
        rÉ   r4   r5   rÌ   r   )rË   Úweightr4   r5   c                 S   s   | d |   dd¡ fS )NrË   r¡  r   )r¾   rÍ   r@   r@   rA   rÏ   ‚  r[   z8PoolsManager._get_connections_settings.<locals>.<lambda>)r?   rË   r¡  )rÞ   r¾   Úpopr9   ry   rB   )rN   rÊ   Zpool_settingsrÉ   rž  rÑ   Zconnection_settingsr@   r@   rA   r�  k  s0    
ýÿÿz&PoolsManager._get_connections_settingsc                 C   s„   |   |¡}| dd¡| jvr.g | j| dd¡< |D ]L\}}|  | dd¡|¡rRq2q2| j | dd¡g ¡}| t|fi |¤Ž¡ q2dS )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.
        r7   rœ  N)r�  r¾   r˜  r›  r9   rY  )rN   Úcnx_settingsrž  rŸ  rÊ   r®   r@   r@   rA   Úcreate_poolŽ  s    	
ÿÿzPoolsManager.create_poolc                 C   s<   |sdS t |ƒdkr|d S t |ƒd }t d|¡}|| S )z�Get a random router from the group with the given priority.

        Returns:
            Router: a random router.

        .. versionadded:: 8.0.20
        Nr   r   )r^   r×   rØ   )rN   Z	pool_listrÙ   rÚ   r@   r@   rA   Ú_get_random_pool§  s    zPoolsManager._get_random_poolc                 C   sZ   g }d }|t |ƒk rV|| j}||krB||  ¡ rB| || ¡ n
||krLqV|d7 }q|S )Nr   )r^   rË   r½   r9   )rN   rš  rÚ   rß   ZsublistZnext_priorityr@   r@   rA   Úget_sublist¸  s    

zPoolsManager.get_sublistc                 C   sb   d}|D ]"}|  ¡ r"||jkr" q,|d7 }qg }|sX|t|ƒk rX|  |||¡}|d7 }q0|  |¡S )Nr   r   )r½   rË   r^   r¦  r¥  )rN   rš  rß   rÚ   r®   Zsubpoolr@   r@   rA   Ú_get_next_poolÄ  s    

zPoolsManager._get_next_poolc                 C   s@   |d u r|r|d j S |D ]}| ¡ r|j }|  S q|d j S )Nr   )rË   r½   )rN   rš  rß   Zt_poolr@   r@   rA   Ú_get_next_priorityÐ  s    

zPoolsManager._get_next_priorityc                 C   sT   |   |¡}|D ]@}| ¡ rq| ¡ \}}|r0|}t ¡ |t|d� kr| ¡  qd S )N)Úseconds)r   r½   r“  r   rl  r	   r’  )rN   rÊ   Zreviverš  r®   r  Ztimeout_stampr@   r@   rA   Ú_check_unavailable_poolsÛ  s    
z%PoolsManager._check_unavailable_poolsc           	         s†  ‡ fdd„}|   |¡}| dd¡}g }|  |¡ |  ||¡}|du rLtdƒ‚||d< |  ||¡‰ ˆ du�rz�z:ˆ  ¡ dk�rît ¡ ��T zˆ jdˆ j	d�}W n t
jy¸   td	ƒ‚Y n0 z,| ¡ rÌˆ  ¡  |jsÚ| ¡  ||ƒ W �nÞ ttjtf�yÄ   z8z| ¡  W n ttjtf�y(   Y n0 W ˆ  |¡ nˆ  |¡ 0 ˆ  ¡ dk�rÈzˆ jdˆ j	d�}W n t
j�y|   Y nH0 z8z| ¡  W n ttjtf�y¨   Y n0 W ˆ  |¡ nˆ  |¡ 0 �qDzžz&tˆ ƒ}ˆ  |¡ | ¡  ||ƒ W n ttjtf�y   Y n0 W ˆ  ¡ dk�rÀz&ˆ jdˆ j	d�}| ¡  ˆ  |¡ W n ttjtf�y`   Y n0 �qnXˆ  ¡ dk�r¾z&ˆ jdˆ j	d�}| ¡  ˆ  |¡ W n ttjtf�y¸   Y n0 �qh0 Y n0 |W  d  ƒ W S 1 �sâ0    Y  n¶ˆ jˆ jk �r$tˆ ƒ}ˆ  |¡ | ¡  ||ƒ |W S t ¡ �f z6ˆ jdˆ j	d�}| ¡  ||ƒ |W W  d  ƒ W S  t
j�y‚   td
ƒ‚Y n0 W d  ƒ n1 �sš0    Y  W q` tttf�yv } z°| d ˆ |¡¡ t|tƒ�rèˆ  d¡ n|   ˆ |¡ |  |¡ |  ||¡‰ ˆ du �rV|  ||¡}||d< |  ||¡‰ ˆ du �rVd !|¡}td |¡ƒ‚W Y d}~q`W Y d}~q`d}~0 0 q`tdƒ‚dS )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                    sZ   |   t¡ ¡  ¡ d d }tdd„ | d¡d  d¡D ƒƒdkrV|   d ˆ j¡¡ ¡  d S )	Nr   r   c                 S   s   g | ]}t |ƒ‘qS r@   r}  r  r@   r@   rA   rÓ   ÷  r[   zPPoolsManager.get_connection.<locals>.set_mysqlx_wait_timeout.<locals>.<listcomp>r�  r  r‚  r…  )rB  Ú_SHOW_VERSION_QUERYrˆ  ró   r‰  r  re   rf  )rv  r‹  ©r®   r@   rA   Úset_mysqlx_wait_timeoutô  s    ÿÿÿz<PoolsManager.get_connection.<locals>.set_mysqlx_wait_timeoutrß   NzCUnable to connect to any of the target hosts. No pool is available.r   Trx  z)Failed getting connection; pool exhaustedzpool max size has been reachedzpool: {} error: {}rÝ   z
  z6Unable to connect to any of the target hosts: [
  {}
]r   )"r   r¾   rª  r¨  r   r§  rz  Ú	threadingÚRLockrg  ro  r{  r¨   r¯   rè   r`  r]   rQ   rd   r   r  rw  r§   r�  rV   rt  rn  r   r9   re   rC   r¿   r±   r<   )	rN   rÊ   r­  rš  rß   Z
error_listrv  rf   r¤   r@   r¬  rA   Úget_connectionæ  sÔ    


ÿ
ÿ
ÿ

ÿùÿ(

ÿ2



ÿ$zPoolsManager.get_connectionc                 C   sX   |   |¡}|D ]@}| ¡  | dd¡dur| j | d¡¡}||v r| |¡ qt|ƒS )zjCloses the connections in the pools

        Returns:
            int: The number of closed pools
        r7   N)r   ri   r¾   r˜  r9  r^   )rN   r£  rš  r®   Zclient_poolsr@   r@   rA   Ú
close_poolq  s    
zPoolsManager.close_poolc              	   C   sp   d}z|j }t| }W n ttfy,   Y n0 |sR|j}tD ]}||v r<t| }q<|rb| |¡ n
| d¡ dS )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 † )ÚerrnorE   rW   r;   r¤   Ú_TIMEOUT_PENALTIESr¿   )rN   r®   rf   ZpenaltyZerr_noÚerr_msgZtimeout_penaltyr@   r@   rA   r±   �  s    
z!PoolsManager.set_pool_unavailable)N)N)rž   rŸ   r    r¡   r•  r˜  r—  r›  r   r�  r¤  r¥  r¦  r§  r¨  rª  r°  r±  r±   r@   r@   r@   rA   r°   4  s"   #

 r°   c                   @   sÌ   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zed
d„ ƒZ	e	j
dd„ ƒZ	dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd.d$d%„Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd#S )/ÚSessionaW  Enables interaction with a X Protocol enabled MySQL Product.

    The functionality includes:

    - Accessing available schemas.
    - Schema management operations.
    - Enabling/disabling warning generation.
    - Retrieval of connection information.

    Args:
        settings (dict): Connection data used to connect to the database.
    c              
   C   sº  |  dtj¡| _|| _|  d¡r´|  d¡r´ts6tdƒ‚ztj |d d¡}W n( tj	j
yt   td |d ¡ƒ‚Y n0 g | jd< |D ].}| jd  |jjdd	�|j|j|jd
œ¡ q„d| jvsÌ| jd dkrÞi | jd< |  ¡  d|v �r"|d �r"tƒ  |¡ tƒ  |¡| _| jd u �r8tdƒ‚nt| jƒ| _| j ¡  | j  d¡}|�r¶z|  d t|ƒ¡¡ ¡  W nN t�y´ } z4|jdk�rŠ|jnd |¡}t||jƒ‚W Y d }~n
d }~0 0 d S )Nzuse-purer4   zdns-srvztMySQL host configuration requested DNS SRV. This requires the Python dnspython module. Please refer to documentationZSRVz$Unable to locate any hosts for '{0}'rÉ   T)Zomit_final_dot)r4   r5   rË   r¡  úconnection-attributesFrû   Úpoolingz+Connection could not be retrieved from poolrä   zUSE {}i  ú#Default schema '{}' does not exists) r¾   r+   Úuse_purerÃ   ÚHAVE_DNSPYTHONr   ÚdnsÚresolverÚqueryÚ	exceptionZDNSExceptionre   r9   ÚtargetZto_textr5   rË   r¡  Ú_init_attributesr°   r¤  r°  Ú_connectionr   r¦   rV   rB  r*   rˆ  r   r²  r¤   )rN   rÊ   Zsrv_recordsZsrvrä   rf   Úerrmsgr@   r@   rA   rO   «  sP    ÿ

ü

ÿ


ÿzSession.__init__c                 C   s   | S rj   r@   rM   r@   r@   rA   Ú	__enter__Ü  s    zSession.__enter__c                 C   s   |   ¡  d S rj   rk   ©rN   Úexc_typeÚ	exc_valueÚ	tracebackr@   r@   rA   Ú__exit__ß  s    zSession.__exit__c                 C   sÀ  t jdkrRdt ¡ d v r d}ndt ¡ d v r6d}nt ¡ }d t ¡ d ¡}n>t ¡ }t ¡ d	kr|d
 dt ¡ d ¡}nd 	t
ƒ dd… ¡}t d¡}|d dkr¬d}nd}tt  ¡ ƒ||t ¡ dd 	dd„ tdd… D ƒ¡|dœ}| jd  |¡ d| jv �r¼| jd D ]¬}| jd | }t|tƒ�s:td |¡ƒ‚t|ƒdk�rVtd |¡ƒ‚| d¡�rptd |¡ƒ‚t|tƒ�sŒtd ||¡ƒ‚t|ƒd k�rªtd! ||¡ƒ‚|| jd |< �qd"S )#z5Setup default and user defined connection-attributes.rp   Z64r   Úx86_64Z32Úi386z
Windows-{}r   ÚDarwinz{}-{}ÚmacOSr�  rÝ   ú ZGPLv2zGPL-2.0Z
Commercialzmysql-connector-pythonr  c                 S   s   g | ]}t |ƒ‘qS r@   )r:   )rÒ   rÎ   r@   r@   rA   rÓ     r[   z,Session._init_attributes.<locals>.<listcomp>é   )Ú_pidÚ	_platformÚ_osZ_source_hostZ_client_nameZ_client_versionZ_client_licenserû   r¶  z)Attribute name '{}' must be a string typeé    z4Attribute name '{}' exceeds 32 characters limit sizer8   zJKey names in 'session-connect-attributes' cannot start with '_', found: {}z4Attribute name '{}' value '{}' must be a string typei   zBAttribute name '{}' value: '{}' exceeds 1024 characters limit sizeN)r‹   rŒ   r  Úarchitecturere   Ú	win32_verÚmachiner  Úmac_verr<   r,   r.   r  r:   ÚgetpidrQ   Úgethostnamer-   rÃ   rF   rC   r   r^   Ú
startswith)rN   Zplatform_archZos_verZlicense_chunksZclient_licenseZdefault_attributesÚ	attr_nameÚ
attr_valuer@   r@   rA   rÀ  â  s`    


òÿþþþþzSession._init_attributesc                 C   s   t jS )zAbool: `True` to use pure Python Protobuf implementation.
        )r+   r¹  rM   r@   r@   rA   r¹  *  s    zSession.use_purec                 C   s    t |tƒstdƒ‚t |¡ d S )Nz)'use_pure' option should be True or False)rC   Úboolr   r+   Zset_use_pure)rN   r  r@   r@   rA   r¹  0  s    
c                 C   s   | j j ¡ S )zzReturns `True` if the session is open.

        Returns:
            bool: Returns `True` if the session is open.
        )rÁ  ræ   r�   rM   r@   r@   rA   r�   6  s    zSession.is_openc                 C   s   t | j|ƒS ra  )r(   rÁ  rb  r@   r@   rA   rB  >  s    
zSession.sqlc                 C   s   | j S )z~Returns the underlying connection.

        Returns:
            mysqlx.connection.Connection: The connection object.
        )rÁ  rM   r@   r@   rA   r°  J  s    zSession.get_connectionc                 C   s    |   d¡ ¡ }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
        zSHOW DATABASESc                 S   s   g | ]}|d  ‘qS )r   r@   )rÒ   Úrowr@   r@   rA   rÓ   [  r[   z'Session.get_schemas.<locals>.<listcomp>)rB  rˆ  ró   rõ   r@   r@   rA   Úget_schemasR  s    zSession.get_schemasc                 C   s
   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   ©rN   rŒ   r@   r@   rA   Ú
get_schema]  s    	zSession.get_schemac                 C   st   | j j d¡}|rp|  t t|ƒ¡¡ ¡  ¡ }z |d d |krLt	| |ƒW S W n  t
yn   td |¡ƒ‚Y n0 dS )a  Retrieves 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.
        rä   r   r¸  N)rÁ  rÊ   r¾   rB  Ú_SELECT_SCHEMA_NAME_QUERYre   r   rˆ  ró   r   r  r   )rN   rä   Úresr@   r@   rA   Úget_default_schemah  s    ÿÿ
zSession.get_default_schemac                 C   s   | j  dt t|ƒ¡d¡ dS )z‹Drops the schema with the specified name.

        Args:
            name (string): The name of the Schema object to be retrieved.
        rB  TN)rÁ  rO  Ú_DROP_DATABASE_QUERYre   r*   rß  r@   r@   rA   Údrop_schemaƒ  s    ÿzSession.drop_schemac                 C   s$   | j  dt 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.
        rB  T)rÁ  rO  Ú_CREATE_DATABASE_QUERYre   r*   r   rß  r@   r@   rA   Úcreate_schemaŒ  s    ÿzSession.create_schemac                 C   s   | j  ddd¡ dS )z+Starts a transaction context on the server.rB  zSTART TRANSACTIONTN©rÁ  rO  rM   r@   r@   rA   Ústart_transaction—  s    zSession.start_transactionc                 C   s   | j  ddd¡ dS )zXCommits all the operations executed after a call to
        startTransaction().
        rB  ZCOMMITTNrè  rM   r@   r@   rA   Úcommit›  s    zSession.commitc                 C   s   | j  ddd¡ dS )zYDiscards all the operations executed after a call to
        startTransaction().
        rB  ZROLLBACKTNrè  rM   r@   r@   rA   Úrollback¡  s    zSession.rollbackNc                 C   sX   |du rd  t ¡ ¡}n"t|tƒr2t| ¡ ƒdkr:tdƒ‚| j 	dd  t
|ƒ¡d¡ |S )a  Creates 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.
        Nz{0}r   úInvalid SAVEPOINT namerB  zSAVEPOINT {0}T)re   ÚuuidÚuuid1rC   r:   r^   Ústripr   rÁ  rO  r*   rß  r@   r@   rA   Úset_savepoint§  s    ÿþzSession.set_savepointc                 C   s@   t |tƒrt| ¡ ƒdkr"tdƒ‚| j dd t|ƒ¡d¡ dS )zRollback to a transaction savepoint with the given name.

        Args:
            name (string): The savepoint name.
        r   rì  rB  zROLLBACK TO SAVEPOINT {0}TN©	rC   r:   r^   rï  r   rÁ  rO  re   r*   rß  r@   r@   rA   Úrollback_to¼  s    ÿþzSession.rollback_toc                 C   s@   t |tƒrt| ¡ ƒdkr"tdƒ‚| j dd t|ƒ¡d¡ dS )z{Release a transaction savepoint with the given name.

        Args:
            name (string): The savepoint name.
        r   rì  rB  zRELEASE SAVEPOINT {0}TNrñ  rß  r@   r@   rA   Úrelease_savepointÈ  s    ÿþzSession.release_savepointc                 C   s   | j  ¡  t| jƒ| _ dS )zCloses the session.N)rÁ  rW  r¦   rÃ   rM   r@   r@   rA   ri   Ô  s    
zSession.closec                 C   s   | j  ¡  dS )z8Closes all underliying connections as pooled connectionsN)rÁ  r  rM   r@   r@   rA   Úclose_connectionsÚ  s    zSession.close_connections)N)rž   rŸ   r    r¡   rO   rÃ  rÈ  rÀ  r”  r¹  Úsetterr�   rB  r°  rÞ  rà  rã  rå  rç  ré  rê  rë  rð  rò  ró  ri   rô  r@   r@   r@   rA   rµ  �  s2   1H

	
rµ  c                   @   sZ   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚClienta7  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                 C   s’   || _ |d u ri }g | _t ¡ | _|  | dd¡¡ |  | dd¡¡ |  | dd¡¡ |  	| dd¡¡ | j
| j d< | j| j d< | j| j d	< d S )
Nrd  re  rf  r   rg  ÚenabledTr·  r7   )rÊ   Úsessionsrí  Úuuid4r7   Ú_set_pool_sizer¾   Ú_set_max_idle_timeÚ_set_queue_timeoutÚ_set_pool_enabledÚpooling_enabledrd  )rN   Zconnection_dictZoptions_dictr@   r@   rA   rO   é  s    
zClient.__init__c                 C   s   | S rj   r@   rM   r@   r@   rA   rÃ  ú  s    zClient.__enter__c                 C   s   |   ¡  d S rj   rk   rÄ  r@   r@   rA   rÈ  ý  s    zClient.__exit__c                 C   s@   t |tƒst |tƒr|dks*td |¡ƒ‚|dkr6tn|| _dS )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.
        r   zWPool max_size value must be an integer greater than 0, the given value {} is not valid.N)rC   rÜ  r~  rW   re   Ú_CNX_POOL_MAXSIZErd  )rN   Z	pool_sizer@   r@   rA   rú   	  s    ÿþzClient._set_pool_sizec                 C   sR   t |tƒst |tƒr|dks*td |¡ƒ‚|| _|dkr<tn
t|d ƒ| jd< dS )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‘  ziConnection max_idle_time value must be an integer greater or equal to 0, the given value {} is not valid.r   rP   rf  N)rC   rÜ  r~  rW   re   rf  Ú_CNX_POOL_MAX_IDLE_TIMErÊ   )rN   rf  r@   r@   rA   rû  	  s    
ÿÿþÿ
ÿzClient._set_max_idle_timec                 C   s   t |tƒstdƒ‚|| _dS )a  Set 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)rC   rÜ  rW   rþ  )rN   r÷  r@   r@   rA   rý  ,	  s    
zClient._set_pool_enabledc                 C   sh   t |tƒst |tƒr|dks*td |¡ƒ‚|| _|dkr<tn
t|d ƒ| jd< d| jvrd| j| jd< dS )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‘  ziConnection queue_timeout value must be an integer greater or equal to 0, the given value {} is not valid.r   rP   rg  rå   N)rC   rÜ  r~  rW   re   rg  Ú_CNX_POOL_QUEUE_TIMEOUTrÊ   )rN   rg  r@   r@   rA   rü  ;	  s    
ÿÿþÿ
ÿ
zClient._set_queue_timeoutc                 C   s   t | jƒ}| j |¡ |S )z~Creates a Session instance using the provided connection data.

        Returns:
            Session: Session object.
        )rµ  rÊ   rø  r9   ©rN   Úsessionr@   r@   rA   Úget_sessionV	  s    
zClient.get_sessionc                 C   s&   t ƒ  | j¡ | jD ]}| ¡  qdS )z3Closes the sessions opened by this client.
        N)r°   r±  rÊ   rø  rô  r  r@   r@   rA   ri   `	  s    
zClient.close)N)rž   rŸ   r    r¡   rO   rÃ  rÈ  rú  rû  rý  rü  r  ri   r@   r@   r@   rA   rö  ß  s   	

rö  )sr¡   rs   rr   ÚPROTOCOL_TLSv1ÚPROTOCOL_TLSv1_1ÚPROTOCOL_TLSv1_2r{   Úhasattrr   ÚPROTOCOL_SSLv23r   rz   r  rQ   Úloggingrí  r  ro  r‹   r×   Úrer®  r’   Zdns.resolverr»  Zdns.exceptionÚImportErrorrº  r   r	   Ú	functoolsr   Zauthenticationr   r   r   Úerrorsr   r   r   r   r   r   Zcrudr   Ú	constantsr   r   r   Úhelpersr   r   r   rç   r   r   r    r!   r"   r´   r#   r$   r%   r&   r'   r:  r(   r)   r*   Úprotobufr+   Úpathr9   Zmysql.connector.utilsr,   Zmysql.connector.versionr-   r.   r¢   rä  ræ  rá  r«  rÿ  rr  Úcompilerq  r   r  Z_PENALTY_SERVER_OFFLINEZ_PENALTY_MAXED_OUTZ_PENALTY_NO_ADD_INFOZ_PENALTY_CONN_TIMEOUTZ_PENALTY_WRONG_PASSWZ_PENALTY_RESTARTINGr³  rE   rª   Ú	getLoggerr  rB   rG   r–  rH   r»   rD   r¼   rÁ   r¦   r§   rp  rY  r°   rµ  rö  r@   r@   r@   rA   Ú<module>   sÎ   ý



 
óÿû	

 b6#      &I [  k  D