o
    –¨ÊhŒÚ  ã                   @   sà  d Z zddlZdZW n   dZY 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mZ ddlmZmZmZ ddlmZmZmZmZmZ dd	lmZmZmZmZ dd
lmZ ddlmZm Z  ddl!m"Z"m#Z# ddl$m%Z%m&Z& ddl'm(Z(m)Z)m*Z* ddl+m,Z,m-Z-m.Z. ddl/m0Z0 dZ1dZ2dZ3dZ4dZ5dZ6e	 7d¡Z8dZ9dZ:e ;d¡Z<dd„ Z=G dd„ de>ƒZ?dd„ Z@G d d!„ d!e>ƒZAG d"d#„ d#eAƒZBG d$d%„ d%ejCƒZDG d&d'„ d'e>ƒZEG d(d)„ d)e>ƒZFG d*d+„ d+e>ƒZGdS ),z4Implementation of communication for MySQL X servers.é    NTF©Úwrapsé   )ÚMySQL41AuthPluginÚPlainAuthPluginÚSha256MemoryAuthPlugin)ÚInterfaceErrorÚOperationalErrorÚ	PoolErrorÚProgrammingErrorÚTimeoutError)ÚPY3ÚSTRING_TYPESÚUNICODE_TYPESÚqueue©ÚSchema)ÚSSLModeÚAuth)ÚescapeÚget_item_or_attr)ÚProtocolÚMessageReaderWriter)ÚResultÚ	RowResultÚ	DocResult)ÚSqlStatementÚAddStatementÚquote_identifier)ÚProtobufi'  zDROP DATABASE IF EXISTS {0}z!CREATE DATABASE IF NOT EXISTS {0}zLSELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '{}'éc   éx   z[^a-zA-Z0-9._:\-*$#]i›Ä  Úmysqlxc               	   K   sL   g }dD ]}z|  t| | ƒ¡ W q ty   Y qw |s!t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ÚuserÚdatabaseÚ	client_idz.Failed generating pool name; specify pool_nameÚ_)ÚappendÚstrÚKeyErrorr
   Újoin)ÚkwargsÚpartsÚkey© r0   úC/var/www/html/env/lib/python3.10/site-packages/mysqlx/connection.pyÚgenerate_pool_nameN   s   ÿ
r2   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©Úselfr0   r0   r1   Ú__init__l   s   
zSocketStream.__init__c                 C   sŠ   |dur|d }zt  ||¡| _|d | _W dS  tyD   zt   t j¡| _| j |¡ | j |¡ d| _W Y dS  t	yC   t
dƒ‚w w )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_connectionr4   r7   Ú
ValueErrorÚAF_UNIXÚ
settimeoutÚconnectr6   ÚAttributeErrorr   )r9   ÚparamsÚconnect_timeoutr0   r0   r1   rA   r   s   	ÿúzSocketStream.connectc                 C   sb   | j du r	tdƒ‚g }|dkr,| j  |¡}|dkrtdƒ‚| |¡ |t|ƒ8 }|dks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)r4   r	   ÚrecvÚRuntimeErrorr)   Úlenr,   )r9   ÚcountÚbufÚdatar0   r0   r1   Úread‰   s   
	
û
zSocketStream.readc                 C   s"   | j du r	tdƒ‚| j  |¡ dS )z_Send data to the socket.

        Args:
            data (bytes): The data to be sent.
        NrE   )r4   r	   Úsendall)r9   rL   r0   r0   r1   rN   �   s   
zSocketStream.sendallc                 C   sF   | j sdS z| j  tj¡ | j  ¡  W n
 tjy   Y nw d| _ dS )zClose the socket.N)r4   Úshutdownr<   Ú	SHUT_RDWRÚcloseÚerrorr8   r0   r0   r1   rQ   §   s   þ
zSocketStream.closec                 C   s   |   ¡  d S ©N)rQ   r8   r0   r0   r1   Ú__del__³   s   zSocketStream.__del__c                 C   s   t s
|  ¡  tdƒ‚t tj¡}| ¡  |r<z| |¡ tj|_	W n t
tjfy; } z|  ¡  td |¡ƒ‚d}~ww |rdz| |¡ tj|_W n t
tjfyc } z|  ¡  td |¡ƒ‚d}~ww |r‰z| ||¡ W n t
tjfyˆ } z|  ¡  td |¡ƒ‚d}~ww | | j¡| _|tjkrû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 n tjyç } z| |¡ W Y d}~qÂd}~ww d}
 |
sû|  ¡  td d |¡¡ƒ‚d| _ dS )a  Set SSL parameters.

        Args:
            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.

        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 supportzInvalid CA Certificate: {}NzInvalid CRL: {}zInvalid Certificate/Key: {}ÚntÚ	localhostz	127.0.0.1r   r   FTz$Unable to verify server identity: {}z, )!ÚSSL_AVAILABLErQ   rH   ÚsslÚ
SSLContextÚPROTOCOL_TLSv1Úload_default_certsÚload_verify_locationsÚCERT_REQUIREDÚverify_modeÚIOErrorÚSSLErrorr   ÚformatÚVERIFY_CRL_CHECK_LEAFÚverify_flagsÚload_cert_chainÚwrap_socketr4   r   ÚVERIFY_IDENTITYÚosÚnamer7   r<   ÚgethostbyaddrÚextendÚmatch_hostnameÚgetpeercertÚCertificateErrorr)   r,   r5   )r9   Ússl_modeÚssl_caÚssl_crlÚssl_certÚssl_keyÚcontextÚerrÚ	hostnamesÚaliasesÚmatch_foundÚerrsÚhostnamer0   r0   r1   Úset_ssl¶   sp   
€þ
€þ€þ

€ÿÿ
zSocketStream.set_sslc                 C   ó   | j S )zpVerifies if SSL is being used.

        Returns:
            bool: Returns `True` if SSL is being used.
        )r5   r8   r0   r0   r1   Úis_sslü   ó   zSocketStream.is_sslc                 C   r{   )zŒVerifies if socket connection is being used.

        Returns:
            bool: Returns `True` if socket connection is being used.
        )r6   r8   r0   r0   r1   Ú	is_socket  r}   zSocketStream.is_socketc                 C   s   | j p| jS )zvVerifies if connection is secure.

        Returns:
            bool: Returns `True` if connection is secure.
        )r5   r6   r8   r0   r0   r1   Ú	is_secure  ó   zSocketStream.is_securec                 C   s
   | j duS )zrVerifies if connection is open.

        Returns:
            bool: Returns `True` if connection is open.
        N)r4   r8   r0   r0   r1   Úis_open  ó   
zSocketStream.is_openN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r:   Ú_CONNECT_TIMEOUTrA   rM   rN   rQ   rT   rz   r|   r~   r   r�   r0   r0   r0   r1   r3   j   s    
Fr3   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ˆ | g|¢R i |¤ŽW S  t jtfy   |  ¡  tdƒ‚w )zWrapper function.zCannot connect to host)r<   rR   rH   Ú
disconnectr   )r9   Úargsr-   ©Úfuncr0   r1   Úwrapper$  s   þz(catch_network_exception.<locals>.wrapperr   )r‹   rŒ   r0   rŠ   r1   Úcatch_network_exception  s   r�   c                   @   s  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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d"d#„ ƒZed$d%„ ƒZed&d'„ ƒZed(d)„ ƒZed*d+„ ƒZed,d-„ ƒZd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8S )9Ú
ConnectionzkConnection 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 rA|d rA| j
 | d¡| dd ¡dœ¡ d| _d	| _|  ¡  | j
jd
d„ d	d� | dt¡| _| jdkrfd | _d S d S )Nr%   ÚpasswordÚschemaÚroutersr#   r$   )r#   r$   éÿÿÿÿTc                 S   ó   | d S ©NÚpriorityr0   ©Úxr0   r0   r1   Ú<lambda>I  ó    z%Connection.__init__.<locals>.<lambda>©r/   Úreverseúconnect-timeoutr   )Úsettingsr3   ÚstreamÚreader_writerÚprotocolÚgetÚ_userÚ	_passwordÚ_schemaÚ_active_resultÚ_routersr)   Ú_cur_routerÚ_can_failoverÚ_ensure_prioritiesÚsortr‡   Ú_connect_timeout)r9   r�   r0   r0   r1   r:   5  s0   
þÿ

ýzConnection.__init__c                 C   s"   | j dur| j  ¡  d| _ dS dS )zFetch active result.N)r¥   Ú	fetch_allr8   r0   r0   r1   Úfetch_active_resultQ  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¥   ©r9   Úresultr0   r0   r1   Úset_active_resultW  ó   
	zConnection.set_active_resultc                 C   s‚   d}d}| j D ]"}| dd¡}|du r|d7 }||d< n	|dkr%tddƒ‚|d8 }qd|  k r7t| j ƒk r?n dS tdd	ƒ‚dS )
zuEnsure priorities.

        Raises:
            :class:`mysqlx.ProgrammingError`: If priorities are invalid.
        r   éd   r•   Nr   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   )r¦   r¡   r   rI   )r9   Úpriority_countr•   ÚrouterÚprir0   r0   r1   r©   b  s"   

ÿ
 þÿzConnection._ensure_prioritiesc                 C   sä   | j s#d| _d| jv r| jd | j dd¡fS d| jv r!| jd S dS | jr+| jdkr;d| _d| _| j D ]}d|d	< q4|  jd
7  _| j | j d }| j | j d }| jdkrad| j | jd
  d	< | jt| j ƒd
 krnd| _||fS )zkReturns the connection parameters.

        Returns:
            tuple: The connection parameters.
        Fr#   r$   é$�  r<   )rV   r¶   r’   TÚ	availabler   r   )r¦   r¨   r�   r¡   r§   rI   )r9   r´   r#   r$   r0   r0   r1   Ú_get_connection_paramsz  s(   





z!Connection._get_connection_paramsc              
   C   sô   d}| j r?z!| j |  ¡ | j¡ t| jƒ| _t| jƒ| _|  	¡  |  
¡  W dS  tjy; } z|}W Y d}~nd}~ww | j s|durgt|tjƒsP|jdv rgtsgt| jƒdkr_td | j¡ƒ‚td | j¡ƒ‚t| jƒdkrutd |¡ƒ‚td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.
        N)é   és   r   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}z'Failed to connect to any of the routersi¡  )r¨   rž   rA   r¸   r«   r   rŸ   r   r    Ú_handle_capabilitiesÚ_authenticater<   rR   Ú
isinstanceÚtimeoutÚerrnor   rI   r¦   r   ra   r   )r9   rR   rt   r0   r0   r1   rA   š  s8   	ÿ€ÿ÷þþ
zConnection.connectc              	   C   s:  | j  d¡tjkrdS | j ¡ r| j  d¡rt d¡ dS | j 	¡ j
}|r1t|d dƒ ¡ dks;n		 |  ¡  tdƒ‚d}t ¡ d	kret ¡ \}}}zd
|v oW| d¡d dk}W n tyd   d}Y nw tjdk rt|st|  ¡  tdƒ‚| jjdd� | j | j  dtj¡| j  d¡| j  d¡| j  d¡| j  d¡¡ dS )a1  Handle 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.
        zssl-modeNz(SSL not required when using Unix socket.r   rh   ÚtlsFzSSL not enabled at serverÚLinuxzOracle LinuxÚ.Ú7)é   é   é	   z<The support for SSL is not available for this Python versionT)rÀ   zssl-cazssl-crlzssl-certzssl-key)r�   r¡   r   ÚDISABLEDrž   r~   Ú_LOGGERÚwarningr    Úget_capabilitesÚcapabilitiesr   ÚlowerÚclose_connectionr	   ÚplatformÚsystemÚlinux_distributionÚsplitÚ
IndexErrorÚsysÚversion_inforH   Úset_capabilitiesrz   ÚREQUIRED)r9   rL   Úis_ol7ÚdistnameÚversionr(   r0   r0   r1   r»   À  sB   	

ÿÿÿÿ



üzConnection._handle_capabilitiesc                 C   s´   | j  d¡}|r+|tjkr|  ¡  dS |tjkr|  ¡  dS |tjkr)|  ¡  dS dS | j	 
¡ r6|  ¡  dS z|  ¡  W dS  tyF   Y nw z|  ¡  W dS  tyY   tdƒ‚w )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   ÚPLAINÚ_authenticate_plainÚSHA256_MEMORYÚ_authenticate_sha256_memoryÚMYSQL41Ú_authenticate_mysql41rž   r   r   )r9   rÚ   r0   r0   r1   r¼   ì  s,   


ÿ

ýÿÿzConnection._authenticatec                 C   óH   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©r9   ÚpluginÚ
extra_datar0   r0   r1   rà   	  ó
   
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)ræ   N)rž   r   r   r   r¢   r£   r    râ   rã   ræ   rç   )r9   ré   r0   r0   r1   rÜ     s   
ÿzConnection._authenticate_plainc                 C   rá   )zBAuthenticate with the MySQL server using `Sha256MemoryAuthPlugin`.N)
r   r¢   r£   r    râ   rã   rä   rå   ræ   rç   rè   r0   r0   r1   rÞ     rë   z&Connection._authenticate_sha256_memoryc                 G   sd   | j du r	tdƒ‚t|tƒstdƒ‚ts(t|tƒr(| j  dtt	|dƒƒ|¡ dS | j  d||¡ dS )a  Execute a SQL statement.

        Args:
            sql (str): The SQL statement.
            *args: Arbitrary arguments.

        Raises:
            :class:`mysqlx.ProgrammingError`: If the SQL statement is not a
                                              valid string.
        NrE   z'The SQL statement is not a valid stringÚsqlzutf-8)
r    r	   r½   r   r   r   r   Úsend_execute_statementÚbytesÚ	bytearray)r9   rì   r‰   r0   r0   r1   Úsend_sql#  s   

ÿzConnection.send_sqlc                 C   s<   | j du r	tdƒ‚| 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.
        NrE   )r    r	   Úsend_insertr½   r   Úidsr   )r9   Ú	statementrò   r0   r0   r1   rñ   9  s   


zConnection.send_insertc                 C   s$   | j  |¡ | ¡ rt| ƒS t| ƒS )aB  Send an find statement.

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

        Returns:
            `Result`: It can be class:`mysqlx.DocResult` or
                      :class:`mysqlx.RowResult`.
        )r    Ú	send_findÚis_doc_basedr   r   ©r9   ró   r0   r0   r1   ÚfindL  s   zConnection.findc                 C   ó   | 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    Úsend_deleter   rö   r0   r0   r1   Údelete[  ó   zConnection.deletec                 C   rø   )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    Úsend_updater   rö   r0   r0   r1   Úupdatei  rû   zConnection.updatec                 G   s6   z| j  |||¡ t| ƒW S  ty   |r‚ Y dS w )az  Execute a non query command.

        Args:
            namespace (str): The namespace.
            cmd (str): The command.
            raise_on_fail (bool): `True` to raise on fail.
            *args: Arbitrary arguments.

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

        Returns:
            :class:`mysqlx.Result`: The result object.
        N)r    rí   r   r	   )r9   Ú	namespaceÚcmdÚraise_on_failr‰   r0   r0   r1   Úexecute_nonqueryw  s   
ÿÿzConnection.execute_nonqueryc                 G   s>   | j  d||¡ t| ƒ}| ¡  |jdkrtdƒ‚|d d S )a  Execute a SQL scalar.

        Args:
            sql (str): The SQL statement.
            *args: Arbitrary arguments.

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

        Returns:
            :class:`mysqlx.Result`: The result.
        rì   r   zNo data found)r    rí   r   r¬   rJ   r   )r9   rì   r‰   r¯   r0   r0   r1   Úexecute_sql_scalarŽ  s   
zConnection.execute_sql_scalarc                 G   s   | j  d||¡ t| ƒS )zÇReturns the row result.

        Args:
            cmd (str): The command.
            *args: Arbitrary arguments.

        Returns:
            :class:`mysqlx.RowResult`: The result object.
        Úxplugin)r    rí   r   )r9   rÿ   r‰   r0   r0   r1   Úget_row_result£  s   zConnection.get_row_resultc                 C   ó   | j  |¡S )zdRead row.

        Args:
            result (:class:`mysqlx.RowResult`): The result object.
        )r    Úread_rowr®   r0   r0   r1   r  ±  ó   zConnection.read_rowc                 C   ó   | j  |¡ dS )zeClose result.

        Args:
            result (:class:`mysqlx.Result`): The result object.
        N)r    Úclose_resultr®   r0   r0   r1   r	  º  s   zConnection.close_resultc                 C   r  )zlGet column metadata.

        Args:
            result (:class:`mysqlx.Result`): The result object.
        )r    Úget_column_metadatar®   r0   r0   r1   r
  Ã  r  zConnection.get_column_metadatac                 C   s
   | j  ¡ S )zgCheck if connection is open.

        Returns:
            bool: `True` if connection is open.
        )rž   r�   r8   r0   r0   r1   r�   Ì  r‚   zConnection.is_openc                 C   s   |   ¡ sdS | j ¡  dS )zDisconnect from server.N)r�   rž   rQ   r8   r0   r0   r1   rˆ   Ô  s   zConnection.disconnectc              
   C   s    |   ¡ sdS zCz| jdur| j ¡  | j ¡  | j ¡  W n ttfy9 } zt 	d 
|¡¡ W Y d}~nd}~ww W | j ¡  dS W | j ¡  dS | j ¡  w )z*Close a sucessfully authenticated session.NzGWarning: An error occurred while attempting to close the connection: {})r�   r¥   r¬   r    Ú
send_closeÚread_okr   r	   rÈ   rÉ   ra   rž   rQ   ©r9   rt   r0   r0   r1   Úclose_sessionÚ  s$   



€ÿ€ÿ€ûzConnection.close_sessionc              
   C   sl   |   ¡ sdS | jdur| j ¡  z| j ¡  W dS  ttfy5 } zt d 	|¡¡ W Y d}~dS d}~ww )z*Reset a sucessfully authenticated session.NzDWarning: An error occurred while attempting to reset the session: {})
r�   r¥   r¬   r    Ú
send_resetr   r	   rÈ   rÉ   ra   r  r0   r0   r1   Ú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    Úsend_connection_closer  rž   rQ   r8   r0   r0   r1   rÍ   ÷  s   



zConnection.close_connectionN) rƒ   r„   r…   r†   r:   r­   r°   r©   r¸   rA   r»   r¼   rà   rÜ   rÞ   r�   rð   rñ   r÷   rú   rý   r  r  r  r  r	  r
  r�   rˆ   r  r  rÍ   r0   r0   r0   r1   rŽ   /  sP     &,











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 )ÚPooledConnectiona  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 objectr#   r$   )
r½   ÚConnectionPoolrB   Úsuperr  r:   Ú
cnx_configÚpoolr#   r$   )r9   r  ©Ú	__class__r0   r1   r:     s   
zPooledConnection.__init__c                    s   t t| ƒ ¡  dS )zGCloses the connection.

        This method closes the socket.
        N)r  r  r  r8   r  r0   r1   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_connectionr8   r0   r0   r1   r  %  s   zPooledConnection.close_sessionc                 C   s    | j dur
| j  ¡  |  ¡  dS )z#Reconnect this connection.
        N)r¥   r¬   r¼   r8   r0   r0   r1   Ú	reconnect2  s   

zPooledConnection.reconnectc                 C   s   |   ¡  dS )zQReset the connection.

        Resets the connection by re-authenticate.
        N)r  r8   r0   r0   r1   Úreset9  s   zPooledConnection.resetc                 C   ó
   t | |ƒS )zÓCreates a :class:`mysqlx.SqlStatement` object to allow running the
        SQL statement on the target MySQL Server.

        Returns:
            :class:`mysqlx.SqlStatement`: The sql statement object.
        )r   )r9   Úsql_statementr0   r0   r1   rì   @  s   
zPooledConnection.sql)rƒ   r„   r…   r†   r:   rÍ   r  r  r  rì   Ú__classcell__r0   r0   r  r1   r    s    r  c                   @   sV   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„ Z
dd„ Zdd„ ZdS )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                 K   s�   |   |¡ d| _g | _| dd¡| _tj | | j¡ | dd¡| _| dd¡| _	|| _
| dd¡| _| dd¡| _|| _|d	 | _|d
 | _d S )Nr   Úmax_sizeé   r  TÚmax_idle_timeÚqueue_timeoutr•   r#   r$   )Ú_set_pool_nameÚ_open_sessionsÚ_connections_opennedr¡   Úpool_max_sizer   ÚQueuer:   r  r!  r�   r"  Ú	_priorityr  r#   r$   )r9   rh   r-   r0   r0   r1   r:   f  s   

zConnectionPool.__init__c                 C   s<   t  |¡rtd |¡ƒ‚t|ƒtkrt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_REGEXÚsearchrB   ra   rI   Ú_CNX_POOL_MAX_NAME_SIZErh   )r9   Ú	pool_namer0   r0   r1   r#  v  s   
ÿÿ
zConnectionPool._set_pool_namec                 C   s
   t | jƒS )zMReturns the number of open connections that can return to this pool.
        )rI   r%  r8   r0   r0   r1   Úopen_connections‹  s   
zConnectionPool.open_connectionsNc                 C   s¬   | j stdƒ‚|  ¡ rtdƒ‚|sFt| ƒ}| d¡ ¡  ¡ d d }tdd„ | d¡d  d	¡D ƒƒd
kr?| d 	d¡¡ ¡  | j
 |¡ n	t|tƒsOtdƒ‚|  |¡ 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 fullúshow variables like "version"r   r   c                 S   ó   g | ]}t |ƒ‘qS r0   ©Úint©Ú.0Únr0   r0   r1   Ú
<listcomp>¬  ó    z1ConnectionPool.add_connection.<locals>.<listcomp>ú-rÂ   ©é   é
   úset mysqlx_wait_timeout = {}ú2Connection instance not subclass of PooledSession.N)r  r
   Úfullr  rì   Úexecuter¬   ÚtuplerÑ   ra   r%  r)   r½   Úqueue_connection)r9   ÚcnxÚverr0   r0   r1   r  ‘  s(   
ÿÿ&
ÿzConnectionPool.add_connectionc                 C   sT   t |tƒs	tdƒ‚| jr| ¡  z
| j|dd� W dS  tjy)   tdƒ Y dS w )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)Úblockr.  N)r½   r  r
   r  Úputr   ÚFull©r9   rB  r0   r0   r1   rA  ·  s   
ÿÿzConnectionPool.queue_connectionc                 C   r  )zNTracks connection in order of close it when client.close() is invoke.
        N)r%  r)   )r9   Ú
connectionr0   r0   r1   Útrack_connectionÐ  s   zConnectionPool.track_connectionc                 C   r{   rS   )rh   r8   r0   r0   r1   Ú__str__Õ  s   zConnectionPool.__str__c                 C   s   | j D ]}| ¡  qdS )z#Empty this ConnectionPool.
        N)r%  rÍ   rG  r0   r0   r1   rQ   Ø  s   

ÿzConnectionPool.closerS   )rƒ   r„   r…   r†   r:   r#  Úpropertyr-  r  rA  rI  rJ  rQ   r0   r0   r0   r1   r  J  s    

&r  c                   @   sP   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S )ÚPoolsManagerz–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 rS   )rL  Ú_PoolsManager__instanceÚobjectÚ__new__Ú_PoolsManager__pools)Úclsr0   r0   r1   rO  é  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)rP  r¡   rh   )r9   r'   r,  Úpoolsr  r0   r0   r1   Ú_pool_existsï  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.
        r'   úNo id)Ú_get_connections_settingsr)   rP  r¡   rh   )r9   r�   Úavailable_poolsÚ
pool_namesÚconnections_settingsÚrouter_namer(   r  r0   r0   r1   Ú
_get_poolsÿ  s   	


€zPoolsManager._get_poolsc                 C   s¸   |  ¡ }| dg ¡}g }d|v r| d¡ d|v r*d|v r*| d|d |d dœ¡ |jdd„ dd	� |D ]$}|  ¡ }|d |d< |d |d< |d
 |d
< | tdi |¤Ž|f¡ q5|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‘   r#   r$   r   )r•   r#   r$   c                 S   r“   r”   r0   r–   r0   r0   r1   r˜   ,  r™   z8PoolsManager._get_connections_settings.<locals>.<lambda>Trš   r•   Nr0   )Úcopyr¡   Úpopr)   rª   r2   )r9   r�   Úpool_settingsr‘   rX  r´   Úconnection_settingsr0   r0   r1   rU    s,   
þÿÿz&PoolsManager._get_connections_settingsc                 C   s‚   |   |¡}| dd¡| jvrg | j| dd¡< |D ]%\}}|  | dd¡|¡r(q| j | dd¡g ¡}| t|fi |¤Ž¡ qd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.
        r'   rT  N)rU  r¡   rP  rS  r)   r  )r9   Úcnx_settingsrX  rY  r�   r  r0   r0   r1   Úcreate_pool7  s   
	ÿÿùzPoolsManager.create_poolc              
   C   sh  |   |¡}t|ƒ}t|ƒD �]#}|| }�z| ¡ dkr{t ¡ �R z
|jd|jd�}W n tj	y7   t
dƒ‚w | ¡  | d¡ ¡  ¡ d d }tdd„ | d	¡d  d
¡D ƒƒdkrf| d d¡¡ ¡  |W  d  ƒ W   S 1 suw   Y  n¡|j|jk r½t|ƒ}| |¡ | ¡  | d¡ ¡  ¡ d d }tdd„ | d	¡d  d
¡D ƒƒdkr¸| d d¡¡ ¡  |W   S t ¡ �R zC|jd|jd�}| ¡  | d¡ ¡  ¡ d d }tdd„ | d	¡d  d
¡D ƒƒdkrù| d d¡¡ ¡  |W W  d  ƒ W   S  tj	�y   t
dƒ‚w 1 �sw   Y  W q ttf�y1   ||d k�r/‚ Y qw 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.
        r   T)rD  r¾   z)Failed getting connection; pool exhaustedr/  r   c                 S   r0  r0   r1  r3  r0   r0   r1   r6  r  r7  z/PoolsManager.get_connection.<locals>.<listcomp>r8  rÂ   r9  r<  Nc                 S   r0  r0   r1  r3  r0   r0   r1   r6    r7  c                 S   r0  r0   r1  r3  r0   r0   r1   r6  Ž  r7  zpool max size has been reached)rZ  rI   ÚrangeÚqsizeÚ	threadingÚRLockr¡   r"  r   ÚEmptyr
   r  rì   r?  r¬   r@  rÑ   ra   r-  r&  r  rI  rA   r   r   )r9   r�   rR  Ú	num_poolsÚpool_numberr  rB  rC  r0   r0   r1   Úget_connectionP  sž   


ÿÿÿ
ÿÿÿÿ(ñ

ÿÿÿÿ

ÿ
ÿÿÿÿôÿó€üÌ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
        r'   N)rZ  rQ   r¡   rP  ÚremoverI   )r9   r_  rR  r  Úclient_poolsr0   r0   r1   Ú
close_pool›  s   

€zPoolsManager.close_pool)rƒ   r„   r…   r†   rM  rP  rO  rS  rZ  rU  r`  rh  rk  r0   r0   r0   r1   rL  ß  s    !KrL  c                   @   s´   e Zd Z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|v r,|d r,tƒ  |¡ tƒ  |¡| _| jd u r+td|d�‚nt	| jƒ| _| j 
¡  | j  d¡}|rnz|  d t|ƒ¡¡ ¡  W d S  tym } z|jdkr^|jnd |¡}t||jƒ‚d }~ww d S )	Nzuse-pureÚpoolingz.connection could not be retrieve from pool. %s)Úvaluesr�   zUSE {}i  ú#Default schema '{}' does not exists)r¡   r   Úuse_pureÚ	_settingsrL  r`  rh  Ú_connectionr
   rŽ   rA   rì   ra   r   r?  r	   r¿   Úmsgr   )r9   r�   r�   rt   Úerrmsgr0   r0   r1   r:   ¹  s0   
ÿÿ
ÿ€üýzSession.__init__c                 C   s   t jS )zAbool: `True` to use pure Python Protobuf implementation.
        )r   rp  r8   r0   r0   r1   rp  Ñ  s   zSession.use_purec                 C   s    t |tƒs	tdƒ‚t |¡ d S )Nz)'use_pure' option should be True or False)r½   Úboolr   r   Úset_use_pure)r9   Úvaluer0   r0   r1   rp  ×  s   
c                 C   s   | j j ¡ S )zzReturns `True` if the session is open.

        Returns:
            bool: Returns `True` if the session is open.
        )rr  rž   r�   r8   r0   r0   r1   r�   Ý  r€   zSession.is_openc                 C   s   t | j|ƒS )z}Creates a :class:`mysqlx.SqlStatement` object to allow running the
        SQL statement on the target MySQL Server.
        )r   rr  )r9   rì   r0   r0   r1   rì   å  s   zSession.sqlc                 C   r{   )z~Returns the underlying connection.

        Returns:
            mysqlx.connection.Connection: The connection object.
        )rr  r8   r0   r0   r1   rh  ë  r}   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   r0   )r4  Úrowr0   r0   r1   r6  ü  r7  z'Session.get_schemas.<locals>.<listcomp>)rì   r?  r¬   r®   r0   r0   r1   Úget_schemasó  s   zSession.get_schemasc                 C   r  )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   ©r9   rh   r0   r0   r1   Ú
get_schemaþ  r±   zSession.get_schemac                 C   sr   | j j d¡}|r7|  t t|ƒ¡¡ ¡  ¡ }z|d d |kr&t	| |ƒW S W dS  t
y6   td |¡ƒ‚w 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   ro  N)rr  r�   r¡   rì   Ú_SELECT_SCHEMA_NAME_QUERYra   r   r?  r¬   r   rÒ   r   )r9   r�   Úresr0   r0   r1   Úget_default_schema	  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.
        rì   TN)rr  r  Ú_DROP_DATABASE_QUERYra   r   rz  r0   r0   r1   Ú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.
        rì   T)rr  r  Ú_CREATE_DATABASE_QUERYra   r   r   rz  r0   r0   r1   Úcreate_schema-  s   ÿ
zSession.create_schemac                 C   ó   | j  ddd¡ dS )z+Starts a transaction context on the server.rì   zSTART TRANSACTIONTN©rr  r  r8   r0   r0   r1   Ústart_transaction8  s   zSession.start_transactionc                 C   rƒ  )zXCommits all the operations executed after a call to
        startTransaction().
        rì   ÚCOMMITTNr„  r8   r0   r0   r1   Úcommit<  ó   zSession.commitc                 C   rƒ  )zYDiscards all the operations executed after a call to
        startTransaction().
        rì   ÚROLLBACKTNr„  r8   r0   r0   r1   ÚrollbackB  rˆ  zSession.rollbackNc                 C   sX   |du rd  t ¡ ¡}nt|tƒrt| ¡ ƒ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 namerì   zSAVEPOINT {0}T)ra   ÚuuidÚuuid1r½   r   rI   Ústripr   rr  r  r   rz  r0   r0   r1   Úset_savepointH  s   

þzSession.set_savepointc                 C   ó@   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‹  rì   zROLLBACK TO SAVEPOINT {0}TN©	r½   r   rI   rŽ  r   rr  r  ra   r   rz  r0   r0   r1   Úrollback_to]  ó   

þzSession.rollback_toc                 C   r�  )z{Release a transaction savepoint with the given name.

        Args:
            name (string): The savepoint name.
        r   r‹  rì   zRELEASE SAVEPOINT {0}TNr‘  rz  r0   r0   r1   Úrelease_savepointi  r“  zSession.release_savepointc                 C   s   | j  ¡  t| jƒ| _ dS )zCloses the session.N)rr  r  rŽ   rq  r8   r0   r0   r1   rQ   u  s   
zSession.closec                 C   s   | j  ¡  dS )z8Closes all underliying connections as pooled connectionsN)rr  rÍ   r8   r0   r0   r1   Úclose_connections{  s   zSession.close_connectionsrS   )rƒ   r„   r…   r†   r:   rK  rp  Úsetterr�   rì   rh  ry  r{  r~  r€  r‚  r…  r‡  rŠ  r�  r’  r”  rQ   r•  r0   r0   r0   r1   rl  ¬  s.    

	
rl  c                   @   sJ   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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 )
Nr  r   r!  r   r"  ÚenabledTrm  r'   )r�   ÚsessionsrŒ  Úuuid4r'   Ú_set_pool_sizer¡   Ú_set_max_idle_timeÚ_set_queue_timeoutÚ_set_pool_enabledÚpooling_enabledr  )r9   Úconnection_dictÚoptions_dictr0   r0   r1   r:   Š  s   
zClient.__init__c                 C   sF   t |tƒst |tƒr|dkstd |¡ƒ‚|dkrt| _dS || _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)r½   ru  r2  rB   ra   Ú_CNX_POOL_MAXSIZEr  )r9   Ú	pool_sizer0   r0   r1   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   r;   r!  N)r½   ru  r2  rB   ra   r!  Ú_CNX_POOL_MAX_IDLE_TIMEr�   )r9   r!  r0   r0   r1   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)r½   ru  rB   rŸ  )r9   r˜  r0   r0   r1   rž  Ç  s   

zClient._set_pool_enabledc                 C   sl   t |tƒst |tƒr|dkstd |¡ƒ‚|| _|dkrtnt|d ƒ| jd< d| jvr4| j| jd< dS 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   r;   r"  rœ   N)r½   ru  r2  rB   ra   r"  Ú_CNX_POOL_QUEUE_TIMEOUTr�   )r9   r"  r0   r0   r1   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.
        )rl  r�   r™  r)   ©r9   Úsessionr0   r0   r1   Úget_sessionñ  s   
zClient.get_sessionc                 C   s&   t ƒ  | j¡ | jD ]}| ¡  q
dS )z3Closes the sessions opened by this client.
        N)rL  rk  r�   r™  r•  r¦  r0   r0   r1   rQ   û  s   

ÿzClient.closerS   )rƒ   r„   r…   r†   r:   r›  rœ  rž  r�  r¨  rQ   r0   r0   r0   r1   r—  €  s    
	
r—  )Hr†   rX   rW   rÓ   r<   ÚloggingrŒ  rÎ   rg   Úrerc  Ú	functoolsr   Úauthenticationr   r   r   Úerrorsr   r	   r
   r   r   Úcompatr   r   r   r   Úcrudr   Ú	constantsr   r   Úhelpersr   r   r    r   r   r¯   r   r   r   ró   r   r   r   Úprotobufr   r‡   r  r�  r|  r¢  r+  Úcompiler)  r¤  r¥  Ú	getLoggerrÈ   r2   rN  r3   r�   rŽ   r  r'  r  rL  rl  r—  r0   r0   r0   r1   Ú<module>   sf   

 4   XF  N U