
    :?h             	      t   S r SSKJr  SSKJr   SSKrSr\R                  \R                  \R                  S.r
\" \S5      (       a  \R                  O\R                  \
S'   \" \S	5      =(       a    \R                  rSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJrJrJrJ r J!r!J"r"J#r#J$r$J%r%   SSK&r'SSK(r'Sr)SSK*J*r*J+r+  SSK,J-r-  SSK.J/r/  SSK0J1r1J2r2J3r3  SSK4J5r5J6r6J7r7  SSK8J9r9J:r:J;r;J<r<J=r=J>r>J?r?J@r@  SSKAJBrB  SSKCJDrDJErEJFrFJGrGJHrHJIrI  SSKJJKrKJLrLJMrM  SSKNJNrN  SSKOJPrP  SSKQJRrRJSrSJTrTJUrUJVrV  SSKWJXrXJYrYJZrZJ[r[J\r\  SSK]J^r^J_r_J`r`JaraJbrbJcrcJdrdJereJfrfJgrgJhrh  SSKJiriJjrjJkrkJlrl  \R                  R                  S5        SSKoJprpJqrqJrrrJsrs  SSKtJuru  SSKvJwrwJxrx  S S!S"S#.ryS$rzS%r{S&r|S'r}S(r~S)rS*r\GR                  " S+5      rS,rS,rS-rS.rS/rS/rS0rS.r\\\\\\\\S1.rS2\0r\GR                  " S35      r\GR                  " S4\GR                  5      r\GR                  " S5\GR                  5      r\GR                  " S65      r/ S7Qr\/ S8Q-   rSXS9 jrSYS: jr " S; S<5      rSZS= jr " S> S?\5      r " S@ SA5      r " SB SC5      r " SD SE\5      r " SF SG\GR:                  5      r " SH SI5      r " SJ SK5      r " SL SM5      rS[SN jrS\SO jrS]SP jr S^     S_SQ jjrS]SR jrS]SS jrS]ST jrS`SU jrSaSV jr      SbSW jrg! \ a
    S
rS
r0 r
 GNf = f! \ a    S
r) GNjf = f)cz4Implementation of communication for MySQL X servers.    )annotations)TracebackTypeNT)TLSv1TLSv1.1TLSv1.2PROTOCOL_TLSTLSv1.3HAS_TLSv1_3F)	AnyCallableDictListMappingOptionalTupleTypeUnion)datetime	timedeltawraps)JSONDecodeError)	parse_qslunquoteurlparse   )MySQL41AuthPluginPlainAuthPluginSha256MemoryAuthPlugin)COMPRESSION_ALGORITHMSDEPRECATED_TLS_VERSIONSOPENSSL_CS_NAMESSUPPORTED_TLS_VERSIONSTLS_CIPHER_SUITESAuthCompressionSSLModeSchema)InterfaceErrorNotSupportedErrorOperationalError	PoolErrorProgrammingErrorTimeoutError)escapeget_item_or_attriani_to_openssl_cs_name)logger)Protobuf)HAVE_LZ4	HAVE_ZSTDMessageReaderMessageWriterProtocol)
BaseResult	DocResultResult	RowResult	SqlResult)AddStatementDeleteStatementFindStatementInsertStatementModifyStatementReadStatementRemoveStatementSelectStatementSqlStatementUpdateStatementquote_identifier)
ColumnTypeMessageTypeResultBaseTypeStatementType..)DUPLICATED_IN_LIST_ERRORTLS_VER_NO_SUPPORTEDTLS_VERSION_DEPRECATED_ERRORTLS_VERSION_ERROR)linux_distribution)LICENSEVERSIONzThis 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.zThis session was closed because the connection has been killed in a different session. Use 'mysqlx.getSession()' or 'mysqlx.getClient()' to create a new one.)i    ia  i'  zDROP DATABASE IF EXISTS {}z CREATE DATABASE IF NOT EXISTS {}zLSELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '{}'zSELECT @@versionc   x   z[^a-zA-Z0-9._:\-*$#]i  i@B <   i  iQ )z[WinError 10053]z
[Errno 32]z[WinError 10061]z[Errno 111]z[WinError 10060]z[Errno 11001]z
[Errno -2]zAccess deniedrV   z,(?![^\(\)]*\))z!^\(address=(.+),priority=(\d+)\)$z^\(address=(.+)[,]*\)$z"^([a-zA-Z][a-zA-Z0-9+\-.]+)://(.*))ssl-certssl-cassl-keyssl-crltls-versionstls-ciphersuites)userpasswordschemahostportrouterssocketssl-modeauthuse-pureconnect-timeoutconnection-attributescompressioncompression-algorithmsdns-srvc                     / nS H   n UR                  [        X   5      5        M"     U(       d  [        S5      eSR	                  U5      $ ! [         a     MT  f = f)a>  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.
)rc   rd   r`   database	client_idz.Failed generating pool name; specify pool_name_)appendstrKeyErrorr-   join)kwargspartskeys      Y/var/www/ev-aguas/ev-aguas-proceso/venv/lib/python3.13/site-packages/mysqlx/connection.pygenerate_pool_namer{      s_     E@	LLV[)* A HII88E?  		s   A
AAc                j    U (       a,  [        U [        5      (       a  [        R                  U 5        ggg)zUpdate the timeout penalties directory.

Update the timeout penalties by error dictionary used to deactivate a pool.
Args:
    penalty_dict (dict): The dictionary with the new timeouts.
N)
isinstancedict_TIMEOUT_PENALTIES_BY_ERR_NOupdate)penalty_dicts    rz   !update_timeout_penalties_by_errorr      s(     
<66$++L9 7|    c                      \ rS rSrSrSS jr\4SS jjrSS jrSS jr	SS jr
SS jr                SS	 jrSS
 jrSS jrSS jrSS jrSrg)SocketStream   zImplements a socket stream.c                <    S U l         SU l        SU l        S U l        g )NF)_socket_is_ssl
_is_socket_hostselfs    rz   __init__SocketStream.__init__  s    04" %$(
r   c                   Ub  US-  n [         R                  " X5      U l        US   U l        U R                  R                  S5        g! [         a     [         R                   " [         R
                  5      U l        U R                  R                  U5        U R                  R                  U5        SU l         N! [         a    [        S5      Sef = ff = f)zConnects 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)rf   create_connectionr   r   
ValueErrorAF_UNIX
settimeoutconnectr   AttributeErrorr*   )r   paramsconnect_timeouts      rz   r   SocketStream.connect  s     &-4O	J!33DL  DJ 	%  	JJ%}}V^^<''8$$V,"&! J$%>?TIJ	Js   %A 
CA&B>>CCc                
   U R                   c  [        S5      e/ nUS:  aS  U R                   R                  U5      nUS:X  a  [        S5      eUR	                  U5        U[        U5      -  nUS:  a  MS  SR                  U5      $ )zkReceive data from the socket.

Args:
    count (int): Buffer size.

Returns:
    bytes: The data received.
MySQLx Connection not availabler   r   zUnexpected connection close)r   r,   recvRuntimeErrorrs   lenrv   )r   countbufdatas       rz   readSocketStream.read"  s     <<"#DEEai<<$$U+Ds{"#@AAJJtSYE ai xx}r   c                    U R                   c  [        S5      e U R                   R                  U5        g! [         a  n[        SU 35      UeSnAff = f)zGSend data to the socket.

Args:
    data (bytes): The data to be sent.
Nr   zUnexpected socket error: )r   r,   sendallOSError)r   r   errs      rz   r   SocketStream.sendall6  sY     <<"#DEE	OLL  & 	O"%>se#DE3N	Os   6 
A AAc                    U R                   (       d  g U R                   R                  [        R                  5        U R                   R	                  5         SU l         g! [
         a     Nf = f)zClose the socket.N)r   shutdownrf   	SHUT_RDWRcloser   r   s    rz   r   SocketStream.closeC  sV    ||	LL!!&"2"23LL    		s   AA 
A,+A,c                $    U R                  5         g Nr   r   s    rz   __del__SocketStream.__del__O  s    

r   c                :	   [         (       d  U R                  5         [        S5      eUb  U(       dZ  [        R                  " 5       nU[
        R                  :w  a  SUl        U[
        R                  :X  a  [        R                  Ul
        OUR                  SS9  US   n	[        (       d  U	S:X  a  [        U5      S:  a  US   n	[        U	   n
[        R                  " U
5      nU	S:X  a{  S	U;  a#  U=R                   [        R"                  -  sl        S
U;  a#  U=R                   [        R$                  -  sl        SU;  a#  U=R                   [        R&                  -  sl        U(       a'   UR)                  U5        [        R*                  Ul
        U(       a'   UR)                  U5        [        R2                  Ul        U(       a   UR7                  XV5        U(       a-  UR9                  SR;                  [=        US   U5      5      5         UR?                  U R@                  U RB                  S9U l         U[
        R                  :X  a  SUl        / n[F        RH                  S:X  a  U RB                  S;   a  SS/n[J        RL                  " U RB                  5      nURO                  US   /US   -   5        Sn/ nU H5  n [        RP                  " U R@                  RS                  5       U5        Sn  O   U(       d-  U R                  5         [1        SSR;                  U5       35      eSU l,        U R@                  R[                  5       n	U	S;   a"  SU	 S3n[\        R^                  " U[`        5        gg! [,        [        R.                  4 a$  nU R                  5         [1        SU 35      UeSnAff = f! [,        [        R.                  4 a$  nU R                  5         [1        SU 35      UeSnAff = f! [,        [        R.                  4 a$  nU R                  5         [1        SU 35      UeSnAff = f! [        RD                   a  n[1        U 5      UeSnAff = f! [        RD                   a&  nURU                  [W        U5      5         SnAGM  SnAff = f)a  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)	localhost	127.0.0.1r   r   z"Unable to verify server identity: , )r   r   zThis connection is using zZ which is now deprecated and will be removed in a future release of MySQL Connector/Python)1SSL_AVAILABLEr   r   sslcreate_default_contextr'   VERIFY_IDENTITYcheck_hostnameREQUIRED	CERT_NONEverify_modesortTLS_V1_3_SUPPORTEDr   TLS_VERSIONS
SSLContextoptionsOP_NO_TLSv1_2OP_NO_TLSv1_1OP_NO_TLSv1load_verify_locationsCERT_REQUIREDIOErrorSSLErrorr*   VERIFY_CRL_CHECK_LEAFverify_flagsload_cert_chainset_ciphersrv   r2   wrap_socketr   r   CertificateErrorosnamerf   gethostbyaddrextendmatch_hostnamegetpeercertrs   rt   r   versionwarningswarnDeprecationWarning)r   
ssl_protosssl_modessl_cassl_crlssl_certssl_keyssl_cipherscontexttls_versionssl_protocolr   	hostnamesaliasesmatch_founderrshostnamewarn_msgs                     rz   set_sslSocketStream.set_sslR  s   4 }JJLGHHZ002G7222).&7+++&)mm#OODO)$Q-K&&9,
Oa'(m'4Lnn\2Gi'J.OOs'8'88OJ.OOs'8'88O*,OOs6OP--f5&)&7&7#
 E--g6'*'@'@$
 Q'':
 0ALM	4"..t||TZZ.XDL w...%)G"Iww$4::1K#K(+6	**4::6Ggaj\GAJ67KD%
 &&t||'?'?'A8L
 #'K & 

$848IJ   ll**,..+K= 9) ) 
 MM($67 /y S\\* P

$'?u%EFCOP S\\* E

$}SE%:;DE S\\* Q

$'@%FGSPQ ## 	4 C5*3	4( ++ *KKC))*sx   ,&M4 &N5 O6 )P7 /Q 4N2N--N25O3O..O36P4P//P47QQQ R4RRc                    U R                   $ )zXVerifies if SSL is being used.

Returns:
    bool: Returns `True` if SSL is being used.
)r   r   s    rz   is_sslSocketStream.is_ssl  s     ||r   c                    U R                   $ )ztVerifies if socket connection is being used.

Returns:
    bool: Returns `True` if socket connection is being used.
)r   r   s    rz   	is_socketSocketStream.is_socket  s     r   c                @    U R                   =(       d    U R                  $ )z^Verifies if connection is secure.

Returns:
    bool: Returns `True` if connection is secure.
)r   r   r   s    rz   	is_secureSocketStream.is_secure  s     ||.t.r   c                    U R                   SL$ )zZVerifies if connection is open.

Returns:
    bool: Returns `True` if connection is open.
N)r   r   s    rz   is_openSocketStream.is_open  s     ||4''r   )r   r   r   r   NreturnNone)r   r   r   floatr   r  )r   intr   bytes)r   r  r   r  )r   	List[str]r   rt   r   rt   r   rt   r   rt   r   rt   r   r  r   r  r   bool)__name__
__module____qualname____firstlineno____doc__r   _CONNECT_TIMEOUTr   r   r   r   r   r   r   r   r   r   __static_attributes__ r   rz   r   r      s    %) ?O &4(O
~8~8 ~8 	~8
 ~8 ~8 ~8 ~8 
~8@/(r   r   c                4   ^  [        T 5      SU 4S jj5       nU$ )zDecorator used to catch OSError or RuntimeError.

Raises:
    :class:`mysqlx.InterfaceError`: If `OSError` or `RuntimeError`
                                    is raised.
c                F  >  [        U [        [        45      (       a+  U R                  5       (       a  [	        U R                  5       6 eT	" U /UQ70 UD6n[        U[        5      (       aq  UR                  5       nU H[  nUS   [        ;   d  M  [        US      nSUS    SU 3US   4n[        U [        [        45      (       a  U R                  U5          U$    U$ ! [        [        [        [        4 Ga(  nT	R                  S:X  Ga  U(       a  [        US   [        5      (       a  US   R                  5       nU(       a  US   n[        US      nSUS    SU 3US   4n[        U [        5      (       aM  U R                  R!                  5         US   S:X  a*  [#        5       R%                  U R                  [	        U6 5        [        U [        [        45      (       a  U R                  U5        U R'                  5         [	        U6 UeU R'                  5         e SnAff = f)	zWrapper function.codezConnection close: msgz: get_column_metadatar   rV   N)r}   
ConnectionPooledConnectionis_server_disconnectedr*   get_disconnected_reasonr:   get_warningsCONNECTION_CLOSED_ERRORset_server_disconnectedr   r   r/   r  r>   poolremove_connectionsPoolsManagerset_pool_unavailable
disconnect)
r   argsrw   resultwarnsr   	error_msgreasonr   funcs
            rz   wrapper(catch_network_exception.<locals>.wrapper  s   .	4*.>!?@@//11$d&B&B&DEE$000F&*--#002!DF|'>>$;DL$I	0eR	{K L" &dZ9I,JKK 88@M " M|D 	!66tAw	22Q,,. 8D 7V EI,T%[MI;GVF "$(899		446<4/(N?? $		>6+B "$5E(FGG44V<OO%(&1s:OO5	s&   BC A
C C H 8D#HH )r   r   r!  r   rw   r   r   r   r   )r&  r'  s   ` rz   catch_network_exceptionr)    s#     4[0 0d Nr   c                  N   ^  \ rS rSrSrSU 4S jjrS	S jrS
S jrSS jrSr	U =r
$ )Routeri1  zRepresents a set of connection parameters.

Args:
   settings (dict): Dictionary with connection settings
.. versionadded:: 8.0.20
c                n   > [         TU ]  5         U R                  U5        U R                  SS5      U S'   g )N	availableT)superr   r   get)r   connection_params	__class__s     rz   r   Router.__init__9  s0    %& HH[$7[r   c                    U S   $ )zzVerifies if the Router is available to open connections.

Returns:
    bool: True if this Router is available else False.
r-  r  r   s    rz   r-  Router.available>  s     K  r   c                    SU S'   g)z1Sets this Router unavailable to open connections.Fr-  Nr  r   s    rz   set_unavailableRouter.set_unavailableF  s    ![r   c                ,    SU ;   a  U S   $ U S   U S   4$ )zyVerifies if the Router is available to open connections.

Returns:
    tuple: host and port or socket information tuple.
rf   rc   rd   r  r   s    rz   get_connection_paramsRouter.get_connection_paramsJ  s)     t>!Vd6l++r   r  )r0  Mapping[str, Any]r   r  r  r   )r   z%Union[str, Tuple[str, Optional[int]]])r  r	  r
  r  r  r   r-  r6  r9  r  __classcell__r1  s   @rz   r+  r+  1  s!    8
!", ,r   r+  c                  ^    \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrS
rg)RouterManageriU  zManages 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                t    Xl         X l        SU l        SU l        0 U l        / U l        U R                  5         g )Nr   T)_routers	_settings_cur_priority_idx_can_failover_routers_directoryrouters_priority_list_ensure_priorities)r   re   settingss      rz   r   RouterManager.__init__^  s8    !&'#';=02"!r   c                0   SnU R                    H6  nUR                  SS5      nUc  US-  nSUS'   M$  US:  d  M,  [        SS5      e   SUs=:  a  [        U R                   5      :  a  O  O[        SS	5      eU R                   R	                  S
 SS9  U R                    Ht  nUS   nX0R
                  ;  a6  [        U5      /U R
                  U'   U R                  R                  U5        MM  U R
                  U   R                  [        U5      5        Mv     g)z]Ensure priorities.

Raises:
    :class:`mysqlx.ProgrammingError`: If priorities are invalid.
r   priorityNr   d   z(The priorities must be between 0 and 100  \You must either assign no priority to any of the routers or give a priority for every router  c                    U S   $ )NrK  r  xs    rz   <lambda>2RouterManager._ensure_priorities.<locals>.<lambda>  s    :r   T)ry   r   )	rA  r/  r.   r   r   rE  r+  rF  rs   )r   priority_countrouterrK  s       rz   rG   RouterManager._ensure_prioritiesh  s    mmFzz*d3H!#%(z"C&'QSWXX $ ~2DMM 22" 	  	6E mmFj)H6665;F^4D''1**11(;''188H $r   c                |    U R                   U   nU Vs/ sH  o3R                  5       (       d  M  UPM     nnU$ s  snf )zGet a list of the current available routers that shares the given priority.

Returns:
    list: A list of the current available routers.
)rE  r-  )r   rK  router_listrV  s       rz   _get_available_routers$RouterManager._get_available_routers  s=     --h7,7NK&;K;K;MvKN Os   99c                    U R                  U5      nU(       d  g[        U5      S:X  a  US   $ [        U5      S-
  n[        R                  " SU5      nX$   $ )zcGet a random router from the group with the given priority.

Returns:
    Router: A random router.
Nr   r   )rZ  r   randomrandint)r   rK  rY  lastindexs        rz   _get_random_connection_params+RouterManager._get_random_connection_params  sY     11(;{q q>!;!#q$'!!r   c                    U R                   $ )ztReturns the next connection parameters.

Returns:
    bool: True if there is more server to failover to else False.
)rD  r   s    rz   can_failoverRouterManager.can_failover  s     !!!r   c                   U R                   (       dj  SU l        U R                  R                  5       nU R                  R	                  SS5      US'   U R                  R	                  SS5      US'   [        U5      $ U R                  U R                     n[        U R                  5      nSnU(       a  U R                  U5      nUc  U R                  U:  a;  U R                  US-
  :X  a%  [        U R                  U5      5      S:  a  SU l         U$ U =R                  S-  sl        U R                  U:  a  U R                  U R                     nU(       a  M  W$ )	z^Returns the next connection parameters.

Returns:
    Router: with the connection parameters.
Frc   r   rd   $  Tr      )rA  rD  rB  copyr/  r+  rF  rC  r   ra  rZ  )r   router_settingscur_priorityrouters_priority_lensearchrV  s         rz   get_next_routerRouterManager.get_next_router  s=    }}!&D"nn113O&*nn&8&8&MOF#&*nn&8&8&GOF#/**11$2H2HI"4#=#=>77EF!T%;%;?S%S**.BQ.FFD77EFJ).D& 	 ""a'"%%(<<#99$:P:PQ f  r   c                    U R                   $ )zReturns the directory containing all the routers managed.

Returns:
    dict: Dictionary with priorities as connection settings.
)rE  r   s    rz   get_routers_directory#RouterManager.get_routers_directory  s     &&&r   )rD  rC  rA  rE  rB  rF  N)re   List[Router]rH  Dict[str, Any]r   r  r   )rK  r  r   rs  )rK  r  r   r+  r  )r   r+  )r   zDict[int, List[Router]])r  r	  r
  r  r  r   rG  rZ  ra  rd  rn  rq  r  r  r   rz   r?  r?  U  s-    "!IF" "!F'r   r?  c                  $   \ rS rSrSrS&S jrS'S jrS(S jrS'S jrS)S jr	 S*       S+S	 jjr
S'S
 jrS'S jrS'S jrS'S jrS,S jr        S-S jr        S-S jr\S.S j5       r\S/S j5       r\    S0S j5       r\S1S j5       r\S2S j5       r\ S*         S3S jj5       r\S4S j5       r\S5S j5       r\S6S j5       r\S7S j5       r\S8S j5       rS9S jrS:S jrS;S jr S:S jr!S<S  jr"S'S! jr#S'S" jr$S'S# jr%S'S$ jr&S%r'g)=r  i  z_Connection to a MySQL Server.

Args:
    settings (dict): Dictionary with connection settings.
c                   Xl         [        5       U l        S U l        S U l        UR                  S5      U l        UR                  S5      U l        UR                  S5      U l        S U l	        UR                  S/ 5      U l
        SU;   aG  US   (       a=  U R                  R                  UR                  S5      UR                  SS 5      S.5        [        U R                  U5      U l        UR                  S[        5      U l        U R                  S	:X  a  S U l        S	U l        / U l        S
U l        SU l        S U l        g )Nr`   ra   rb   re   rc   rd   rc   rd   rj   r   TF)rH  r   streamprotocol	keep_openr/  _user	_password_schema_active_resultrA  rs   r?  router_managerr  _connect_timeout_stmt_counter_prepared_stmt_ids_prepared_stmt_supported_server_disconnected_server_disconnected_reason)r   rH  s     rz   r   Connection.__init__  s   (0$0N,0)-$,LL$8
(0Z(@&.ll8&<8<&.ll9b&AX(6"2MM  $LL0$LL6 .;4==(-S/7||/0
   A% %)D!"#-/.2%*/!RV(r   c                b    U R                   b"  U R                   R                  5         SU l         gg)zFetch active result.N)r~  	fetch_allr   s    rz   fetch_active_resultConnection.fetch_active_result  s-    *))+"&D +r   c                    Xl         g)zSet 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~  r   r"  s     rz   set_active_resultConnection.set_active_result  s
     %r   c                   SnU R                   R                  5       (       Ga   U R                   R                  5       nU R                  R	                  UR                  5       U R                  5        [        U R                  5      n[        U R                  5      n[        X45      U l
        U R                  R                  5       R                  nU(       a+  U Vs0 sH  n[        US5      R                  5       U_M      snO0 nU R                  U5        SU R                   ;   a(  U R                   S   nU R                  R#                  US9  U R                   R%                  S[&        R(                  5      n	U R                   R%                  S5      n
U	[&        R*                  :X  a  SOU R-                  XyU
5      nU R/                  5         U R                  R1                  U5        gUbj  [9        U[:        R<                  5      (       aK  [?        U R@                  5      S::  a  [C        SU R                   S	35      e[C        S
U R                   S35      e[?        U R@                  5      S::  a  [E        SU 35      e[E        SS5      es  snf ! [2        [4        4 a  nUnWR7                  5          SnAOSnAff = fU R                   R                  5       (       a  GM  N)zAttempt 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.
Nr   
attributessession_connect_attrsrl   rm   r   z9Connection attempt to the server was aborted. Timeout of z ms was exceededz8All server connection attempts were aborted. Timeout of z) ms was exceeded for each selected serverzCannot connect to host: ,Unable to connect to any of the target hostsi  )#r  rd  rn  rx  r   r9  r  r7   r8   r9   ry  get_capabilitescapabilitiesr1   lower_set_tls_capabilitiesrH  set_capabilitiesr/  r&   	PREFERREDDISABLED_set_compression_capabilities_authenticateset_compressionr   r   r6  r}   rf   timeoutr   rA  r/   r*   )r   errorrV  readerwriter	caps_datacapcaps
conn_attrsrl   
algorithms	algorithmr   s                rz   r   Connection.connect  s    !!..00'),,<<>##002D4I4I 't{{3&t{{3 ( 8 MM99;HH	 ! LUU9C%c6288:C?9U  **40  4==0!%|!<JMM222T #mm//{?T?TU!]]../GH
 #k&:&:: ;;:  ""$--i8 E6>>!B!B4==!Q&"""&"7"7!88HJ  "334 5"" 
 t}}" #;E7!CDDKTRR] V4 \* )&&(()M !!..00s+   B7J $J?C&J J J7J22J7c                   U R                   R                  S5      [        R                  :X  a  gU R                  R                  5       (       a7  U R                   R                  S5      (       a  [        R                  " S5        gSU;  a  U R                  5         [        S5      eSn[        R                  " 5       S:X  a1  [        5       u  p4n SU;   =(       a    UR                  S	5      S
   S:H  n[        R                   S:  a"  U(       d  U R                  5         [#        S5      eU R$                  R'                  SS9  U R                  R)                  U R                   R                  SS5      U R                   R                  S[        R*                  5      U R                   R                  S5      U R                   R                  S5      U R                   R                  S5      U R                   R                  S5      U R                   R                  S5      5        SU R                   ;   a)  U R                   S   nU R$                  R'                  US9  gg! [         a    Sn GNxf = f)aa  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
rg   Nz(SSL not required when using Unix socket.tlszSSL not enabled at serverFLinuxzOracle Linux.r   7)rh     	   z<The support for SSL is not available for this Python versionT)r  r^   r[   r]   rZ   r\   r_   r  r  )rH  r/  r'   r  rx  r   r3   warningclose_connectionr,   platformsystemrS   split
IndexErrorsysversion_infor   ry  r  r   r   )r   r  is_ol7distnamer   rr   r  s          rz   r   Connection._set_tls_capabilitiesY  s    ==Z(G,<,<<;;  ""}}  ,,IJ!!#"#>????'#5#7 Hq'83Tc8J18MQT8T i'!!#N  	&&4&0MMnd3MMj'*:*:;MMh'MMi(MMj)MMi(MM01	
 4==(|4JMM***L )'  s   #I I+*I+Nc                   UR                  S5      nUc8  SnU[        R                  :X  a  [        U5      e[        R
                  " U5        g0 n[        U[        5      (       aK  US   S   S    H;  nUS   S   S    Vs/ sH  nUS   S	   S   R                  S
5      PM     snXgS   '   M=     OUR                  R                  R                   Hl  nUR                  R                  R                   Vs/ sH2  nUR                  R                  R                  R                  S
5      PM4     snXgR                  '   Mn     UR                  S/ 5      n	Sn
U(       a}  U Vs/ sH  nU[         ;   d  M  [         U   PM     nnU Vs/ sH  oU	;   d  M
  UPM     nnU(       a  [         R                   " US   5      n
O U[        R                  :X  a  [#        S5      egU
c*  [$        (       a	  SU	;   a  Sn
O[&        (       a	  SU	;   a  Sn
OSn
X;  a8  SnU[        R                  :X  a  [#        U5      e[        R
                  " U5        gU R(                  R+                  SU
0S9  U
$ s  snf s  snf s  snf s  snf )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
rl   Nz8Compression requested but the server does not support itvalueobjfldarrayscalarv_stringzutf-8ry   r  r   zmThe connection compression is set as required, but none of the provided compression algorithms are supported.zstd_streamlz4_messagedeflate_streamzFCompression requested but the compression algorithm negotiation failed)rl   )r/  r&   r   r+   r3   r  r}   r~   decoder  r  r  r  r  r  ry   r    r*   r6   r5   ry  r  )r   r  rl   r  compression_datar  compression_dictr  r  server_algorithmsr  itemclient_algorithmsmatcheds                 rz   r  (Connection._set_compression_capabilities  s|   <  88M2#LCk222',,NN3&--'07> "%Wg!6w!?0!? (OJ/8??H!?0 U, ? (--1155 "%!6!6-!6 LL))//66w?!6- ) 6 -00bA	  '!&D11 -&t,&  !
 ):W(9EV=Vt(9GW266wqzB	 4 44$<   y].??)	m/@@)	,	-%  k222$S))NN3&&K3K&Lq0-!
 Xs$   ?#I48I#I(/I(I-I-c                0   U R                   R                  S5      nU(       ap  U[        R                  :X  a  U R	                  5         gU[        R
                  :X  a  U R                  5         gU[        R                  :X  a  U R                  5         ggU R                  R                  5       (       a  U R	                  5         g U R                  5         g! [         a     Of = f U R                  5         g! [         a  n[        SU 35      UeSnAff = f)z#Authenticate with the MySQL server.rh   NzrAuthentication failed using MYSQL41 and SHA256_MEMORY, check username and password or try a secure connection err:)rH  r/  r%   PLAIN_authenticate_plainSHA256_MEMORY_authenticate_sha256_memoryMYSQL41_authenticate_mysql41rx  r   r*   )r   rh   r   s      rz   r  Connection._authenticate  s    }}  (tzz!((*+++002%**, &[[""$$$$&**,  " 
002! $??BeE 	s*   C 
C"!C"&C7 7
DDDc                R   [        U R                  U R                  5      nU R                  R	                  UR                  5       5        U R                  R                  5       nU R                  R                  UR                  U5      5        U R                  R                  5         g)z=Authenticate with the MySQL server using `MySQL41AuthPlugin`.N)
r   r{  r|  ry  send_auth_start	auth_nameread_auth_continuesend_auth_continue	auth_dataread_auth_okr   plugin
extra_datas      rz   r   Connection._authenticate_mysql41  sp    "4::t~~>%%f&6&6&89]]557
(()9)9*)EF""$r   c                8   U R                   R                  5       (       d  [        S5      e[        U R                  U R
                  5      nU R                  R                  UR                  5       UR                  5       S9  U R                  R                  5         g)z;Authenticate with the MySQL server using `PlainAuthPlugin`.z>PLAIN authentication is not allowed via unencrypted connection)r  N)rx  r   r*   r   r{  r|  ry  r  r  r  r  )r   r  s     rz   r  Connection._authenticate_plain  st    {{$$&& P  !T^^<%%f&6&6&8FDTDTDV%W""$r   c                R   [        U R                  U R                  5      nU R                  R	                  UR                  5       5        U R                  R                  5       nU R                  R                  UR                  U5      5        U R                  R                  5         g)zBAuthenticate with the MySQL server using `Sha256MemoryAuthPlugin`.N)
r   r{  r|  ry  r  r  r  r  r  r  r  s      rz   r  &Connection._authenticate_sha256_memory#  sp    '

DNNC%%f&6&6&89]]557
(()9)9*)EF""$r   c                    UR                   (       aR  U R                  R                  UR                  5        U R                  R                  UR                  5        SUl         gg)zZDeallocates statement.

Args:
    statement (Statement): A `Statement` based type object.
FN)preparedry  send_prepare_deallocatestmt_idr  remove)r   	statements     rz   _deallocate_statement Connection._deallocate_statement+  sL     MM11)2C2CD##**9+<+<=!&I r   c                     U R                  5         U R                  R                  XU5        U R
                  R                  UR                  5        SUl        g! [         a
    SU l         gf = f)zPrepares 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  ry  send_prepare_preparer+   r  r  rs   r  r  r   msg_typer  r  s       rz   _prepare_statementConnection._prepare_statement6  sg    (	$$&MM..xiH 	&&y'8'89!		 ! 	,1D)	s   ,A A/.A/c                   U R                   (       d  U R                  R                  XU5        gUR                  (       a  U R	                  U5        U R                  XU5        U R                   (       d  U R                  R                  XU5        gU R                  R                  XU5        SUl        UR                  5         GOUR                  (       a/  UR                  (       d  U R                  R                  XU5        GO]UR                  (       aV  UR                  (       dE  U R	                  U5        U R                  R                  XU5        SUl	        UR                  5         OUR                  (       d  UR                  (       dn  UR                  (       d  U R                  XU5        U R                   (       d  U R                  R                  XU5        gU R                  R                  XU5        OfUR                  (       aU  UR                  (       aD  U R	                  U5        U R                  R                  XU5        SUl	        UR                  5         UR                  5         g)zExecutes 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  ry  send_msg_without_psdeallocate_prepare_executer  r  send_prepare_executereset_exec_counterr  changedrepeatedincrement_exec_counterr  s       rz   _execute_prepared_pipeline%Connection._execute_prepared_pipelineS  s   * ,,MM--hYG//&&y1##H9=0011(KMM..xiH38I0((*	(9(9MM..xiHy'9'9&&y1MM--hYG %I((*""9+=+=%%''yA0011(KMM..xiH9#5#5&&y1MM--hYG %I((*((*r   c                   UR                   nU R                  c  [        S5      e[        U[        5      (       d  [        S5      eU R                  R                  SU5      u  p4U R                  R                  X4U5        [        U 5      $ )zExecute a SQL statement.

Args:
    sql (str): The SQL statement.

Raises:
    :class:`mysqlx.ProgrammingError`: If the SQL statement is not a
                                      valid string.
r   z'The SQL statement is not a valid stringsql)	r  ry  r,   r}   rt   r.   build_execute_statementr  r>   )r   r  r  r  r  s        rz   send_sqlConnection.send_sql  sr     mm== "#DEE#s##"#LMM==eSI))(Cr   c                    U R                   c  [        S5      eU R                   R                  U5      u  p#U R                   R                  X#5        Sn[	        U[
        5      (       a  UR                  n[        X5      $ )zSend an insert statement.

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

Returns:
    :class:`mysqlx.Result`: A result object.
Nr   )ry  r,   build_insertsend_msgr}   r?   idsr<   )r   r  r  r  r  s        rz   send_insertConnection.send_insert  sh     == "#DEE229=x-i..--Cd  r   c                    U R                   R                  U5      u  p#U R                  X#U5        UR                  5       (       a  [	        U 5      $ [        U 5      $ )a  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`.
)ry  
build_findr  is_doc_basedr;   r=   r   r  r  r  s       rz   	send_findConnection.send_find  sK     00;''yA"+"8"8":":yO	$Or   c                v    U R                   R                  U5      u  p#U R                  X#U5        [        U 5      $ )zSend an delete statement.

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

Returns:
    :class:`mysqlx.Result`: The result object.
)ry  build_deleter  r<   r
  s       rz   send_deleteConnection.send_delete  4     229=''yAd|r   c                v    U R                   R                  U5      u  p#U R                  X#U5        [        U 5      $ )zSend an delete statement.

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

Returns:
    :class:`mysqlx.Result`: The result object.
)ry  build_updater  r<   r
  s       rz   send_updateConnection.send_update  r  r   c                     U R                   R                  XU5      u  pVU R                   R                  XV5        [        U 5      $ ! [         a    U(       a  e  gf = f)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)ry  r  r  r<   r,   )r   	namespacecmdraise_on_failfieldsr  r  s          rz   execute_nonqueryConnection.execute_nonquery  s]    ,	 MMAAMH MM""81$< 	 	s   AA AAc                    U R                   R                  SU5      u  p#U R                   R                  X#5        [        U 5      nUR	                  5         UR
                  S:X  a  [        S5      eUS   S   $ )zExecute a SQL scalar.

Args:
    sql (str): The SQL statement.

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

Returns:
    :class:`mysqlx.Result`: The result.
r  r   zNo data found)ry  r  r  r=   r  r   r*   )r   r  r  r  r"  s        rz   execute_sql_scalarConnection.execute_sql_scalar
  sh     ==eSIx-4<<1 11ay|r   c                    U R                   R                  SX5      u  p4U R                   R                  X45        [        U 5      $ )zReturns the row result.

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

Returns:
    :class:`mysqlx.RowResult`: The result object.
mysqlx)ry  r  r  r=   )r   r  r  r  r  s        rz   get_row_resultConnection.get_row_result  s8     ==hTx-r   c                8    U R                   R                  U5      $ )zLRead row.

Args:
    result (:class:`mysqlx.RowResult`): The result object.
)ry  read_rowr  s     rz   r%  Connection.read_row.  s     }}%%f--r   c                :    U R                   R                  U5        g)zMClose result.

Args:
    result (:class:`mysqlx.Result`): The result object.
N)ry  close_resultr  s     rz   r(  Connection.close_result7  s     	""6*r   c                8    U R                   R                  U5      $ )zTGet column metadata.

Args:
    result (:class:`mysqlx.Result`): The result object.
)ry  r  r  s     rz   r  Connection.get_column_metadata@  s     }}0088r   c                D    U =R                   S-  sl         U R                   $ )z\Returns the next statement ID.

Returns:
    int: A statement ID.

.. versionadded:: 8.0.16
r   )r  r   s    rz   get_next_statement_id Connection.get_next_statement_idI  s!     	a!!!r   c                6    U R                   R                  5       $ )zOCheck if connection is open.

Returns:
    bool: `True` if connection is open.
)rx  r   r   s    rz   r   Connection.is_openT  s     {{""$$r   c                    SU l         Xl        g)znSet the disconnection message from the server.

Args:
    reason (str): disconnection reason from the server.
TN)r  r  )r   r%  s     rz   r  "Connection.set_server_disconnected\  s     %)!+1(r   c                    U R                   $ )zVerify if the session has been disconnect from the server.

Returns:
    bool: `True` if the connection has been closed from the server
          otherwise `False`.
)r  r   s    rz   r  !Connection.is_server_disconnectede  s     (((r   c                    U R                   $ )znGet the disconnection message sent by the server.

Returns:
    string: disconnection reason from the server.
)r  r   s    rz   r  "Connection.get_disconnected_reasonn  s     ///r   c                d    U R                  5       (       d  gU R                  R                  5         g)zDisconnect from server.N)r   rx  r   r   s    rz   r   Connection.disconnectv  s     ||~~r   c                *   U R                  5       (       d  g U R                  5         U R                  (       a5  U R                   H  nU R                  R                  U5        M      SU l        U R                  R                  5         U R                  R                  5         U R                  R                  5         g! [        [        [        4 a!  n[        R                  " SU5         SnANLSnAff = f! U R                  R                  5         f = f)z*Close a sucessfully authenticated session.Nr   zGWarning: An error occurred while attempting to close the connection: %s)r   r  r  r  ry  r  r  
send_closeread_okr*   r,   r   r3   r  rx  r   )r   r  r   s      rz   close_sessionConnection.close_session|  s    ||~~	 $$&,,#66GMM99'B  7%&"MM$$&MM!!# KK  0': 	NN! 	 KKs*   B
B= =C3C.)C6 .C33C6 6Dc                <   U R                  5       (       d  gU R                  b  U R                  R                  5          U R                  R	                  U R
                  5      U l        g! [        [        4 a!  n[        R                  " SU5         SnAgSnAff = f)z*Reset a sucessfully authenticated session.NzDWarning: An error occurred while attempting to reset the session: %s)
r   r~  r  ry  
send_resetrz  r*   r,   r3   r  )r   r   s     rz   reset_sessionConnection.reset_session  s|    ||~~*))+	!]]55dnnEDN 01 	NN 	s   *A* *B:BBc                   U R                  5       (       d  gU R                  b  U R                  R                  5         U R                  R	                  5         U R                  R                  5         U R                  R                  5         g)zpAnnounce to the server that the client wants to close the
connection. Discards any session state of the server.
N)r   r~  r  ry  send_connection_closer;  rx  r   r   s    rz   r  Connection.close_connection  s`     ||~~*))+++-r   )r~  r  r|  r  r  rA  r}  r  r  r  r{  rz  ry  r  rH  rx  rH  rt  r   r  r   )r"  rL   r   r  )r  rt  r   r  r   )r  rt  rl   rt   r  zOptional[List[str]]r   Optional[str])r  rM   r   r  )r  rt   r  rK   r  zgUnion[FindStatement, DeleteStatement, ModifyStatement, ReadStatement, RemoveStatement, UpdateStatement]r   r  )r  rG   r   r>   )r  z$Union[AddStatement, InsertStatement]r   r<   )r  z%Union[FindStatement, SelectStatement]r   zUnion[DocResult, RowResult])r  z'Union[DeleteStatement, RemoveStatement]r   r<   )r  z'Union[ModifyStatement, UpdateStatement]r   r<   )
r  rt   r  rt   r  r  r  Optional[Dict[str, Any]]r   zOptional[Result])r  rM   r   r  )r  rt   r  rt  r   r=   )r"  r=   r   zOptional[MessageType])r"  r<   r   r  )r"  r<   r   zList[ColumnType]r   r  r  )r%  zUnion[str, Tuple[str, int]]r   r  )r   z%Optional[Union[str, Tuple[str, int]]])(r  r	  r
  r  r  r   r  r  r   r  r  r  r  r  r  r  r  r  r)  r  r  r  r  r  r  r  r"  r%  r(  r  r-  r   r  r  r  r   r<  r@  r  r  r  r   rz   r  r    s     WD'	%DSL4Mt +/	aa a (	a
 
aF>%%%	'"" "
	" 
":<+<+ <+
	<+ 
<+|  & ! !& P>P	$P P"      ,0  	
 ) 
 @  (   . . + + 9 9	"%2)0 6
r   r  c                  h   ^  \ rS rSrSrS
U 4S jjrSU 4S jjrSS jrSS jrSS jr	SS jr
S	rU =r$ )r  i  aS  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                   > [        U[        5      (       d  [        S5      e[        TU ]  UR
                  5        Xl        UR
                  S   U l        UR
                  S   U l        g )Nz&pool should be a ConnectionPool objectrc   rd   )	r}   ConnectionPoolr   r.  r   
cnx_configr  rc   rd   )r   r  r1  s     rz   r   PooledConnection.__init__  sR    $// !IJJ)$(	0	0	r   c                "   > [         TU ]  5         g)z7Closes the connection.

This method closes the socket.
N)r.  r<  )r   r1  s    rz   r  !PooledConnection.close_connection  s    
 	r   c                :    U R                   R                  U 5        g)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_connectionr   s    rz   r<  PooledConnection.close_session  s     			  &r   c                r    U R                   b  U R                   R                  5         U R                  5         g)zReconnect this connection.N)r~  r  r  r   s    rz   	reconnectPooledConnection.reconnect  s,    *))+r   c                $    U R                  5         g)zAReset the connection.

Resets the connection by re-authenticate.
N)rT  r   s    rz   resetPooledConnection.reset  s    
 	r   c                    [        X5      $ zCreates 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.
)rG   r   r  s     rz   r  PooledConnection.sql  s     D&&r   )rc   r  rd   )r  rK  r   r  r   r  rt   r   rG   )r  r	  r
  r  r  r   r  r<  rT  rW  r  r  r<  r=  s   @rz   r  r    s+    $1 '
' 
'r   r  c                      \ rS rSrSrSS jrSS jr\SS j5       rSSS jjr	SS jr
SSS	 jjrSS
 jrSS jrSS jrSS jrSSS jjrSS jrSS jrSS jrSrg) rK  i  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                
   U R                  U5        SU l        / U l        SU l        SU l        [
        R                  " 5       U l        UR                  SS5      U l	        [        R                  R                  X R                  5        UR                  SS5      U l        UR                  SS5      U l        X l        UR                  SS5      U l        UR                  SS5      U l        X l        US	   U l        US
   U l        g )Nr   Tmax_size   r@  max_idle_timequeue_timeoutrK  rc   rd   )_set_pool_name_open_sessions_connections_openned
_available_timeoutr   now_timeout_stampr/  pool_max_sizequeueQueuer   r@  rb  rH  rc  rK  rL  rc   rd   )r   r   rw   s      rz   r   ConnectionPool.__init__  s    D!#$<>! $(0"(**Z"<T#5#56#)::ot#D"(**_b"A(."(**_b"A#ZZ
A6*0		r   c                    [         R                  U5      (       a  [        SU S35      e[        U5      [        :  a  [        SU S35      eXl        g)aC  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 'z' contains illegal charactersz' is too longN)_CNX_POOL_NAME_REGEXrm  r   r   _CNX_POOL_MAX_NAME_SIZEr   )r   	pool_names     rz   rd  ConnectionPool._set_pool_name,  sP      &&y11 ;yk9V!WXXy>33 ;yk!GHH	r   c                ,    [        U R                  5      $ )zDReturns the number of open connections that can return to this pool.)r   rf  r   s    rz   open_connectionsConnectionPool.open_connections?  s     4,,--r   Nc                :    U R                   R                  U5        g)z_Removes a connection from this pool.

Args:
    cnx (PooledConnection): The connection object.
N)rf  r  r   cnxs     rz   remove_connection ConnectionPool.remove_connectionD  s     	!!((-r   c                j   U R                  5       S:  aT   U R                  SU R                  S9n UR                  5         U R                  U5        U R                  5       S:  a  MS  gg! [        [
        [        4 a     N@f = f! U R                  U5        f = f! [        R                   a     N_f = f)z*Removes all the connections from the pool.r   Tblockr  N)
qsizer/  rc  r  r   r   r*   rz  rl  Emptyrx  s     rz   r  !ConnectionPool.remove_connectionsL  s    jjlQ
0hhT43E3EhF0((* **3/ jjlQ %g~>  **3/ ;; s4   B A* *B?B BB BB21B2c                   U R                   (       d  [        S5      eU R                  5       (       a  [        S5      eU(       d  [        U 5      nUR	                  [
        5      R                  5       R                  5       S   S   n[        S UR                  S5      S   R                  S5       5       5      S:  a,  UR	                  SU R                   35      R                  5         U R                  R                  U5        OU[        U[        5      (       d  [        S	5      eUR                  5       (       a   U R                  5         UR!                  5         U R#                  U5        g
)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 fullr   c              3  6   #    U H  n[        U5      v   M     g 7fr   r  .0ns     rz   	<genexpr>0ConnectionPool.add_connection.<locals>.<genexpr>u       B%ASVV%A   -r     r   
   set mysqlx_wait_timeout = z1Connection instance not subclass of PooledSessionN)rL  r-   fullr  r  _SELECT_VERSION_QUERYexecuter  tupler  rb  rf  rs   r}   r  r  r   queue_connection)r   ry  vers      rz   rQ  ConnectionPool.add_connection[  s     DEE99;;EFF"4(C''/088:DDFqI!LCBSYYs^A%6%<%<S%ABB F 
 4T5G5G4HIJRRT%%,,S1c#344 STT))++'')		c"r   c                    [        U[        5      (       d  [        S5      eU R                  (       a  UR                  5          U R	                  USS9  g! [
        R                   a  n[        S5      UeSnAff = f)a  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.
z2Connection instance not subclass of PooledSession.F)r~  r  N)r}   r  r-   r@  putrl  Full)r   ry  r   s      rz   r  ConnectionPool.queue_connection  so     #/00PQQ 	PHHSH&zz 	PEFCO	Ps   A A9(A44A9c                :    U R                   R                  U5        g)zETracks connection in order of close it when client.close() is invoke.N)rf  rs   )r   
connections     rz   track_connectionConnectionPool.track_connection  s    !!((4r   c                    U R                   $ r   )r   r   s    rz   __str__ConnectionPool.__str__  s    yyr   c                    U R                   $ )zReturns if this pool is available for pool connections from it.

Returns:
    bool: True if this pool is available else False.
.. versionadded:: 8.0.20
)rg  r   s    rz   r-  ConnectionPool.available  s     r   c                    U R                   (       a@  [        R                  " SU U5        SU l         [        R                  " 5       U l        Xl        gg)zXSets this pool unavailable for a period of time (in seconds).

.. versionadded:: 8.0.20
z4ConnectionPool.set_unavailable pool: %s time_out: %sFN)rg  r3   r  r   ri  rj  rh  )r   time_outs     rz   r6  ConnectionPool.set_unavailable  sA    
 ??NNF
 $DO"*,,.D$M r   c                F    SU l         [        R                  " 5       U l        g)zQSets this pool available for pool connections from it.

.. versionadded:: 8.0.20
TN)rg  r   ri  rj  r   s    rz   set_availableConnectionPool.set_available  s    
 &llnr   c                2    U R                   U R                  4$ )zReturns the penalized time (timeout) and the time at the penalty.

Returns:
    tuple: penalty seconds (int), timestamp at penalty (datetime object)
.. versionadded:: 8.0.20
)rh  rj  r   s    rz   get_timeout_stamp ConnectionPool.get_timeout_stamp  s     t2233r   c                J    U R                    H  nUR                  5         M     g)zEmpty this ConnectionPool.N)rf  r  rx  s     rz   r   ConnectionPool.close  s    ,,C  " -r   )rg  rf  re  rh  rj  rL  rc   rb  r   rk  rd   rK  rc  r@  rH  )r   rt   rw   r   r   r  )rr  rt   r   r  rH  r   )ry  zOptional[PooledConnection]r   r  r   ry  r  r   r  )r  r  r   r  )r   rt   r  ))r  r  r   r  )r   zTuple[int, datetime])r  r	  r
  r  r  r   rd  propertyru  rz  r  rQ  r  r  r  r-  r6  r  r  r   r  r  r   rz   rK  rK    s^    8(&& . ..0(#TP05%-4#r   rK  c                  :   \ rS rSr% SrSrS \S'   0 rS\S'   SS jrSS jr	SS	 jr
\    SS
 j5       rSS jr\SS j5       r\        SS j5       r      SS jr\ S     SS jj5       r S     SS jjrS S jrS!S jr\      S"S j5       rSrg)#r  i  zManages a pool of connections for a host or hosts in routers.

This class handles all the pools of Connections.

.. versionadded:: 8.0.13
N_PoolsManager__instancert  _PoolsManager__poolsc                    [         R                  c)  [        R                  U 5      [         l        0 [         l        [         R                  $ r   )r  r  object__new__r  )clss    rz   r  PoolsManager.__new__  s3    ""*&,nnS&9L##%L &&&r   c                r    U R                   R                  U/ 5      nU H  nUR                  U:X  d  M    g   g)zVerifies 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   )r   rq   rr  poolsr  s        rz   _pool_existsPoolsManager._pool_exists  s8       B/DyyI%  r   c                   / n/ nU R                  U5      nU H  u  pVUR                  U5        M     U R                  R                  UR                  SS5      / 5       H&  nUR                  U;   d  M  UR                  U5        M(     U$ )zRetrieves 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.
rq   No id)_get_connections_settingsrs   r  r/  r   )r   rH  available_pools
pool_namesconnections_settingsrouter_namerr   r  s           rz   
_get_poolsPoolsManager._get_pools  s     
#==hG 3NKk* 3 LL$$X\\+w%GLDyyJ&&&t, M r   c                   U R                  5       nUR                  S/ 5      n/ nSU;   a  UR                  S5        SU;   a"  SU;   a  UR                  SSUS   US   S.5        UR	                  S S9  U H\  nUR                  5       nUS   US'   US   US'   US	   US	'   UR                  S
S5      US
'   UR                  [        S0 UD6U45        M^     U$ )a  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
re   rc   rd   rL  r   )rK  weightrc   rd   c                2    U S   U R                  SS5      * 4$ )NrK  r  r   )r/  rQ  s    rz   rS  8PoolsManager._get_connections_settings.<locals>.<lambda>)  s    AjMAEE(A4F3F#Gr   )ry   rK  r  r  )ri  r/  poprs   r   r{   )rH  pool_settingsre   r  rV  connection_settingss         rz   r  &PoolsManager._get_connections_settings  s    !##Ir2!%i(]"v'>NN #)&1)&1	 	GHF"/"4"4"6*0.'*0.'.4Z.@
+,2JJx,C) ''&=)<='  $#r   c                   U R                  U5      nUR                  SS5      U R                  ;  a  / U R                  UR                  SS5      '   U Hu  u  p4U R                  UR                  SS5      U5      (       a  M.  U R                  R                  UR                  SS5      / 5      nUR	                  [        U40 UD65        Mw     g)zCreates 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.
rq   r  N)r  r/  r  r  rs   rK  )r   cnx_settingsr  r  rH  r  s         rz   create_poolPoolsManager.create_pool8  s      $==lK K1ECEDLL))+w?@ &:!K  !1!1+w!GUU<<##L$4$4['$JBODKK{?h?@	 &:r   c                    U (       d  g[        U 5      S:X  a  U S   $ [        U 5      S-
  n[        R                  " SU5      nX   $ )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^  )	pool_listr_  r`  s      rz   _get_random_poolPoolsManager._get_random_poolN  sG     y>QQ<9~!q$'r   c                    / nS nU[        U 5      :  a\  X   R                  nX$:X  a+  X   R                  5       (       a  UR                  X   5        OX$:w  a   U$ US-  nU[        U 5      :  a  M\  U$ )Nr   )r   rK  r-  rs   )r  r`  rk  sublistnext_prioritys        rz   _get_sublistPoolsManager._get_sublist`  sy     c%j !L11M,1G1G1I1Iu|,. QJE c%j  r   c                   SnU H.  nUR                  5       (       a  X$R                  :X  a    O	US-  nM0     / nU(       d>  U[        U5      :  a/  U R                  XU5      nUS-  nU(       d  U[        U5      :  a  M/  U R	                  U5      $ )Nr   r   )r-  rK  r   r  r  )r   r  rk  r`  r  subpools         rz   _get_next_poolPoolsManager._get_next_poolo  s     D~~LMM$AQJE  ec%j0''lCGQJE ec%j0 $$W--r   c                    Uc  U (       a  U S   R                   $ U  H(  nUR                  5       (       d  M  UR                   nUs  $    U S   R                   $ )Nr   )rK  r-  )r  rk  t_pools      rz   _get_next_priorityPoolsManager._get_next_priority}  sV     E8$$$F!!%##  Qx   r   c                   U R                  U5      nU Hj  nUR                  5       (       a  M  UR                  5       u  pVU(       a  Un[        R                  " 5       U[        US9-   :  d  MZ  UR                  5         Ml     g )N)seconds)r  r-  r  r   ri  r   r  )r   rH  reviver  r  r  timeout_stamps          rz   _check_unavailable_pools%PoolsManager._check_unavailable_pools  si     )D~~%)%;%;%="G ||~71K!KL""$ r   c           	       ^
 SU
4S jjnU R                  U5      nUR                  SS5      n/ nU R                  U5        U R                  X45      nUc  [	        S5      eXAS'   U R                  X45      m
[        R                  " 5       nT
Gb   T
R                  5       S:  ax  U    T
R                  ST
R                  S9n UR                  5       (       a  T
R                  5         UR                  (       d  UR                  5         U" U5        UsSSS5        $ T
R0                  T
R2                  :  a6  [+        T
5      nT
R-                  U5        UR/                  5         U" U5        U$ U    T
R                  ST
R                  S9nUR                  5         U" U5        UsSSS5        $ [	        S5      e! [        R                   a    [	        S5      Sef = f! [         ["        [$        4 Gah     UR'                  5         O! [         ["        [$        4 a     Of = fT
R)                  U5        O! T
R)                  U5        f = fT
R                  5       S:  a   T
R                  ST
R                  S9n UR'                  5         O! [         ["        [$        4 a     Of = fT
R)                  U5        O0! T
R)                  U5        f = f! [        R                   a     Of = fT
R                  5       S:  a  M   [+        T
5      nT
R-                  U5        UR/                  5         U" U5        O! [         ["        [$        4 a     Of = fT
R                  5       S:  an   T
R                  ST
R                  S9nUR'                  5         T
R)                  U5        O! [         ["        [$        4 a     Of = fT
R                  5       S:  a  Mn   GN! T
R                  5       S:  ao   T
R                  ST
R                  S9nUR'                  5         T
R)                  U5        O! [         ["        [$        4 a     Of = fT
R                  5       S:  a  Mn  f f = ff = f! , (       d  f       GO= f! [        R                   a    [	        S	5      Sef = f! , (       d  f       O= f! [$        [4        [        4 a  nUR7                  S
T
 SU 35        [9        U[        5      (       a  T
R;                  S5        OU R=                  T
U5        U R                  U5        U R                  X45      m
T
cJ  U R                  X45      nXAS'   U R                  X45      m
T
c!  SR?                  U5      n	[	        SU	 S35      Ue SnAGM  SnAff = fT
b  GM  GN)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                <  > U R                  [        5      R                  5       R                  5       S   S   n[	        S UR                  S5      S   R                  S5       5       5      S:  a-  U R                  STR                   35      R                  5         g g )Nr   c              3  6   #    U H  n[        U5      v   M     g 7fr   r  r  s     rz   r  OPoolsManager.get_connection.<locals>.set_mysqlx_wait_timeout.<locals>.<genexpr>  r  r  r  r  r  r  )r  r  r  r  r  r  rb  )ry  r  r  s     rz   set_mysqlx_wait_timeout<PoolsManager.get_connection.<locals>.set_mysqlx_wait_timeout  s    ''/088:DDFqI!LCBSYYs^A%6%<%<S%ABB F 
 4T5G5G4HIJRRTr   rk  NzBUnable to connect to any of the target hosts. No pool is availabler   Tr}  z)Failed getting connection; pool exhaustedzpool max size has been reachedzpool: z error: rh  z
  z2Unable to connect to any of the target hosts: [
  z
]r  r  ) r  r/  r  r  r-   r  	threadingRLockr  rc  rl  r  r  r  rz  rW  r   r   r*   r  rz  r  r  r   ru  rk  r/   rs   r}   r6  r  rv   )r   rH  r  r  rk  
error_listlockry  r   r  r  s             @rz   get_connectionPoolsManager.get_connection  s(   	U )||ND9
%%h/..uCT  $0 ""57 j::<!#("&((t?Q?Q("RC
5-"99;; $ 7 7 9 $'== #		3C8\  #{ | **T-?-??*40C))#.KKM+C0J X"&((t?Q?Q("RCIIK3C8#& B FGGK  %{{ ("+ K##'(( !-g~F ,-< # 4 4 6$0'>#J % $% !% 6 6s ; 6 6s ; #'**,"2!D*.((.2D<N<N +3 +&C%D(+(<(<(>,8'>+R %-(,%- )-(>(>s(C(>(>s(C (-{{ !)$(!) #'**,"2-&6t&< $ 5 5c : # 7 <$0'>#J % $%
 '+jjlQ&6%-.2hh26484F4F /7 /* ),(<(<(>(,(>(>s(C,8'>+R %-(,%- '+jjlQ&6djjlQ&6%-.2hh26484F4F /7 /* ),(<(<(>(,(>(>s(C,8'>+R %-(,%- '+jjlQ&6G,-! Z  %{{ X"+,L"MSWWX  #L)< !!F4&">?c9-- ((+--dC8--h7**5?<#'#:#:5#OL/;^,..uCD|$kk*5'$$'5-  ## /i s  R" $Q&F6AGQ	R" AR" *R" ,R.3Q-!	R" 6!GQQ1HH/HH/HH/Q/IQK	5JJ3JJ3JJ3!Q3KQ	K QK  Q:4L/.O/MOMO
Q;NQN30Q2N33QQQ%;P! Q!P96Q8P99QQQQ
Q*%R" *R" -!RR
RR" R" "V7B?U==Vc                   U R                  U5      nU Hj  nUR                  5         UR                  SS5      c  M(  U R                  R                  UR                  S5      5      nX4;   d  MY  UR	                  U5        Ml     [        U5      $ )zRCloses the connections in the pools

Returns:
    int: The number of closed pools
rq   N)r  r   r/  r  r  r   )r   r  r  r  client_poolss        rz   
close_poolPoolsManager.close_pool+  sw     -DJJLT2>#||//0@0@0MN' ''-  5zr   c                &   Sn UR                   n[        U   nU(       d2  UR                  n[
        R                  5        H  u  pVXT;   d  M  UnM     U(       a  U R                  U5        gU R                  S5        g! [        [        4 a     Nvf = f)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 )errnor   r   ru   r  _TIMEOUT_PENALTIESitemsr6  )r  r   penaltyerr_noerr_msgry   r  s          rz   r  !PoolsManager.set_pool_unavailable;  s     	YYF26:G ggG0668
>#G 9   )   ( ) 		s   A= =BBr  )r   r  )rq   rt   rr  rt   r   r  )rH  rt  r   r   )rH  rt  r   z List[Tuple[str, Dict[str, Any]]])r  rt  r   r  )r  List[ConnectionPool]r   rK  )r  r  r`  r  rk  r  r   r  )r  r  rk  r  r   rK  r   )r  r  rk  Optional[int]r   r  )rH  rt  r  zOptional[bool]r   r  )rH  rt  r   r  )r  rt  r   r  )r  rK  r   z#Union[InterfaceError, TimeoutError]r   r  )r  r	  r
  r  r  r  __annotations__r  r  r  r  staticmethodr  r  r  r  r  r  r  r  r  r  r  r  r   rz   r  r    sH     $J# G^ ' . *$ *$	)*$ *$XA,    " #,/?B	 .).9<.	. CG
!#
!3@
!	
! 
! BF%&%0>%	%RHh  ))#F)	) )r   r  c                  0   \ rS rSrSrSS jrSS jr        SS jrSS jr\	SS j5       r
\
R                  S S j5       r
SS	 jrS!S
 jrS"S jrS#S jrS$S jrS%S jrS&S jrS$S jrSS jrSS jrSS jrS'S(S jjrS&S jrS&S jrSS jrSS jrSrg))Sessioni[  a  Enables interaction with a X Protocol enabled MySQL Product.

The functionality includes:

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

Args:
    settings (dict): Connection data used to connect to the database.
c                T   UR                  S[        R                  5      U l        Xl        UR                  S5      (       a  UR                  S5      (       a  [        (       d  [        S5      e [        R                  R                  US   S5      n/ U R                  S'   U H[  nU R                  S   R                  UR                  R                  S	S
9UR                  UR                  UR                   S.5        M]     SU R                  ;  d  U R                  S   SLa  0 U R                  S'   U R#                  5         SU;   aZ  US   (       aP  [%        5       R'                  U5        [%        5       R)                  U5      U l        U R*                  c  [-        S5      eO4[/        U R                  5      U l        U R*                  R1                  5         U R                  R                  S5      nU(       a-   U R3                  S[5        U5       35      R7                  5         g g ! [        R                  R                   a  n[        SUS    S35      UeS nAff = f! [8         a=  nUR:                  S:X  a  UR<                  OSU S3n[        XcR:                  5      UeS nAff = f)Nri   rc   rn   ztMySQL host configuration requested DNS SRV. This requires the Python dnspython module. Please refer to documentationSRVz Unable to locate any hosts for ''re   T)omit_final_dot)rc   rd   rK  r  rk   Fr  poolingz+Connection could not be retrieved from poolrb   zUSE i  Default schema '' does not exists)r/  r4   use_purerB  HAVE_DNSPYTHONr*   dnsresolverquery	exceptionDNSExceptionrs   targetto_textrd   rK  r  _init_attributesr  r  r  _connectionr-   r  r   r  rI   r  r,   r  r  )r   rH  srv_recordsr   srvrb   errmsgs          rz   r   Session.__init__h  sY   &ll:x7H7HI)1 <<HLL$;$;!>$< 
!ll00&1A5I
 )+DNN9%"y)00 #

 2 2$ 2 G #$'LL"%**	 # $4>>9~~56eC+-DNN<(!!# Xi%8N&&x0+7>+H+H+RD' MNN (  *$..9D$$&##H-	A4 0 89:;CCE C ==-- $6x7G6HJH $ A yyD( GG+F83DE 
 %VYY7S@As0   /#H' :+I  'III 
J'*8J""J'c                    U $ r   r  r   s    rz   	__enter__Session.__enter__      r   c                $    U R                  5         g r   r   r   exc_type	exc_value	tracebacks       rz   __exit__Session.__exit__       	

r   c                $   [         R                  S:X  ao  S[        R                  " 5       S   ;   a  SnO4S[        R                  " 5       S   ;   a  SnO[        R                  " 5       nS[        R                  " 5       S    3nOf[        R
                  " 5       n[        R                  " 5       S	:X  a  S
[        R                  " 5       S    3nOSR                  [        5       SS 5      n[        R                  " S5      nUS   S:X  a  SnOSn[        [         R                  " 5       5      UU[        R                  " 5       SSR                  [         SS  Vs/ sH  n[        U5      PM     sn5      US.nU R"                  S   R%                  U5        SU R"                  ;   a  U R"                  S    H  nU R"                  S   U   n['        U[        5      (       d  [)        SU S35      e[+        U5      S:  a  [)        SU S35      eUR-                  S5      (       a  [)        SU 35      e['        U[        5      (       d  [)        SU SU S35      e[+        U5      S:  a  [)        SU S U S!35      eXR"                  S   U'   M     g"g"s  snf )#z5Setup default and user defined connection-attributes.r   64r   x86_6432i386zWindows-r   DarwinzmacOS-r  rh   GPLv2zGPL-2.0
Commercialzmysql-connector-pythonr     )_pid	_platform_os_source_host_client_name_client_version_client_licenser  rk   Attribute name '' must be a string type    "' exceeds 32 characters limit sizerr   zHKey names in 'session-connect-attributes' cannot start with '_', found: z	' value 'z'  must be a string type   
' value: '$' exceeds 1024 characters limit sizeN)r   r   r  architecture	win32_vermachiner  mac_verrv   rS   rT   r  rt   getpidrf   gethostnamerU   rB  r   r}   r*   r   
startswith)	r   platform_archos_verlicense_chunksclient_licenserR  default_attributes	attr_name
attr_values	            rz   r  Session._init_attributes  s   77d?x,,.q11=E..033 & ( 5 5 7 2 2 4Q 789F$,,.M H,!("2"2"4Q"7!89"4"6q";< s+!'&N)N 		$&"..04"xx1(FAQ(FG-
  	|$++,>?"dnn4!^^,CD	!^^,CDYO
!)S11(*9+5LM  y>B&(*9+ 6% % 
 '',,(22;> 
 "*c22(*9+Yzl K1 1  z?T)(*9+Z
| L= = 
 ;E|,Y7C E 5 )Gs   Jc                "    [         R                  $ )z8bool: `True` to use pure Python Protobuf implementation.)r4   r  r   s    rz   r  Session.use_pure  s        r   c                p    [        U[        5      (       d  [        S5      e[        R                  " U5        g )Nz)'use_pure' option should be True or False)r}   r  r.   r4   set_use_pure)r   r  s     rz   r  rT   	  s)    %&&"#NOOe$r   c                J    U R                   R                  R                  5       $ )zbReturns `True` if the session is open.

Returns:
    bool: Returns `True` if the session is open.
)r  rx  r   r   s    rz   r   Session.is_open	  s     &&..00r   c                .    [        U R                  U5      $ rZ  )rG   r  r[  s     rz   r  Session.sql	  s     D,,c22r   c                    U R                   $ )zfReturns the underlying connection.

Returns:
    mysqlx.connection.Connection: The connection object.
)r  r   s    rz   r  Session.get_connection	  s     r   c                    U R                  S5      R                  5       nUR                  5        Vs/ sH  o"S   PM	     sn$ s  snf )zReturns the list of schemas in the current session.

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

.. versionadded:: 8.0.12
zSHOW DATABASESr   )r  r  r  )r   r"  rows      rz   get_schemasSession.get_schemas"	  sA     *+335"("2"2"45"43A"4555s   Ac                    [        X5      $ )zRetrieves 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(   r   r   s     rz   
get_schemaSession.get_schema-	  s     d!!r   c                ^   U R                   R                  R                  S5      nU(       ac  U R                  [        R                  [        U5      5      5      R                  5       R                  5       n US   S   U:X  a  [        X5      $  gg! [         a    [        SU S35      Sef = f)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.
rb   r   r  r  N)r  rH  r/  r  _SELECT_SCHEMA_NAME_QUERYformatr0   r  r  r)   r  r.   )r   rb   ress      rz   get_default_schemaSession.get_default_schema8	  s     !!**..x8299&.IJ 
q6!9&!$// ' 	  &&vh.?@s   7B B,c                v    U R                   R                  S[        R                  [	        U5      5      S5        g)zsDrops the schema with the specified name.

Args:
    name (string): The name of the Schema object to be retrieved.
r  TN)r  r  _DROP_DATABASE_QUERYrg  rI   rb  s     rz   drop_schemaSession.drop_schemaV	  s1     	))'../?/EF	
r   c                    U R                   R                  S[        R                  [	        U5      5      S5        [        X5      $ )zCreates a schema on the database and returns the corresponding
object.

Args:
    name (string): A string value indicating the schema name.
r  T)r  r  _CREATE_DATABASE_QUERYrg  rI   r)   rb  s     rz   create_schemaSession.create_schema`	  s>     	)))001A$1GH$	
 d!!r   c                >    U R                   R                  SSS5        g)z+Starts a transaction context on the server.r  zSTART TRANSACTIONTNr  r  r   s    rz   start_transactionSession.start_transactionl	  s    ))%1DdKr   c                >    U R                   R                  SSS5        g)zHCommits all the operations executed after a call to
startTransaction().
r  COMMITTNrt  r   s    rz   commitSession.commitp	  s     	))%4@r   c                >    U R                   R                  SSS5        g)zIDiscards all the operations executed after a call to
startTransaction().
r  ROLLBACKTNrt  r   s    rz   rollbackSession.rollbackv	  s     	))%TBr   Nc                   Uc  [         R                  " 5        nO=[        U[        5      (       a  [	        UR                  5       5      S:X  a  [        S5      eU R                  R                  SS[        U5       3S5        U$ )zCreates 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.
r   Invalid SAVEPOINT namer  z
SAVEPOINT T)
uuiduuid1r}   rt   r   stripr.   r  r  rI   rb  s     rz   set_savepointSession.set_savepoint|	  sq     <jjl^DD#&&#djjl*;q*@"#;<<))Z 0 678$	
 r   c                    [        U[        5      (       a  [        UR                  5       5      S:X  a  [	        S5      eU R
                  R                  SS[        U5       3S5        g)zgRollback to a transaction savepoint with the given name.

Args:
    name (string): The savepoint name.
r   r  r  zROLLBACK TO SAVEPOINT TNr}   rt   r   r  r.   r  r  rI   rb  s     rz   rollback_toSession.rollback_to	  sZ     $$$DJJL(9Q(>"#;<<))$%5d%;$<=	
r   c                    [        U[        5      (       a  [        UR                  5       5      S:X  a  [	        S5      eU R
                  R                  SS[        U5       3S5        g)zcRelease a transaction savepoint with the given name.

Args:
    name (string): The savepoint name.
r   r  r  zRELEASE SAVEPOINT TNr  rb  s     rz   release_savepointSession.release_savepoint	  sZ     $$$DJJL(9Q(>"#;<<)) !1$!7 89	
r   c                l    U R                   R                  5         [        U R                  5      U l         g)zCloses the session.N)r  r<  r  rB  r   s    rz   r   Session.close	  s%    &&(%dnn5r   c                8    U R                   R                  5         g)z8Closes all underliying connections as pooled connectionsN)r  r  r   s    rz   close_connectionsSession.close_connections	  s    ))+r   )r  rB  r  rE  r   r	  r&  zType[BaseException]r'  BaseExceptionr(  r   r   r  r   r  )r  r  r   r  r]  )r   r  )r   r  )r   rt   r   r)   )r   zOptional[Schema])r   rt   r   r  r   )r   rF  r   rt   )r  r	  r
  r  r  r   r!  r)  r  r  r  setterr   r  r  r_  rc  ri  rm  rq  ru  ry  r}  r  r  r  r   r  r  r  r   rz   r	  r	  [  s    
9Av% ! !	
 
KEZ ! ! __% %
1
3 	6	"<

"LAC*

6,r   r	  c                      \ rS rSrSr S     SS jjrSS jr        SS jrSS jrSS jr	SS	 jr
SS
 jrSS jrSS jrSrg)Clienti	  a  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                   Xl         Uc  0 n/ U l        [        R                  " 5       U l        U R                  UR                  SS5      5        U R                  UR                  SS5      5        U R                  UR                  SS5      5        U R                  UR                  SS5      5        U R                  U R                   S'   U R                  U R                   S'   U R                  U R                   S	'   g )
Nr`  ra  rb  r   rc  enabledTr  rq   )rH  sessionsr  uuid4rq   _set_pool_sizer/  _set_max_idle_time_set_queue_timeout_set_pool_enabledpooling_enabledr`  )r   connection_dictoptions_dicts      rz   r   Client.__init__	  s    
 )8L')$(JJLL,,Z<= 0 0! DE 0 0! DE|//	4@A#'#7#7i $(MMj!%)^^k"r   c                    U $ r   r  r   s    rz   r!  Client.__enter__	  r#  r   c                $    U R                  5         g r   r   r%  s       rz   r)  Client.__exit__	  r+  r   c                    [        U[        5      (       d  [        U[        5      (       a  US:  d  [        SU S35      eUS:X  a  [        U l        gUU l        g)aS  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   zGPool max_size value must be an integer greater than 0, the given value  is not validN)r}   r  r  r   _CNX_POOL_MAXSIZEr`  )r   	pool_sizes     rz   r  Client._set_pool_size	  sY     y$''i--q= (k8 
 .7!^)r   c                    [        U[        5      (       d  [        U[        5      (       a  US:  d  [        SU S35      eXl        US:X  a  [
        O[        US-  5      U R                  S'   g)a=  Set the max idle time.

This method sets the max idle time.

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

Raises:
    :class:`AttributeError`: If the max_idle_time value is not an
                             integer greater or equal to 0.
r  zYConnection max_idle_time value must be an integer greater or equal to 0, the given value r  r   r   rb  N)r}   r  r  r   rb  _CNX_POOL_MAX_IDLE_TIMErH  )r   rb  s     rz   r  Client._set_max_idle_time	  ss     }d++mS11 2% //<o]L 
 +'4'9#s=SWCW?X 	o&r   c                P    [        U[        5      (       d  [        S5      eXl        g)zSet 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}   r  r   r  )r   r  s     rz   r  Client._set_pool_enabled
  s#     '4(( !MNN&r   c                0   [        U[        5      (       d  [        U[        5      (       a  US:  d  [        SU S35      eXl        US:X  a  [
        O[        US-  5      U R                  S'   SU R                  ;  a  U R                  U R                  S'   gg)	a=  Set the queue timeout.

This method sets the queue timeout.

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

Raises:
    :class:`AttributeError`: If the queue_timeout value is not an
                             integer greater or equal to 0.
r  zYConnection queue_timeout value must be an integer greater or equal to 0, the given value r  r   r   rc  rj   N)r}   r  r  r   rc  _CNX_POOL_QUEUE_TIMEOUTrH  )r   rc  s     rz   r  Client._set_queue_timeout'
  s     }d++mS11 2% //<o]L 
 +'4'9#s=SWCW?X 	o&
 DMM1/3/A/ADMM+, 2r   c                f    [        U R                  5      nU R                  R                  U5        U$ )zfCreates a Session instance using the provided connection data.

Returns:
    Session: Session object.
)r	  rH  r  rs   r   sessions     rz   get_sessionClient.get_sessionG
  s)     $--(W%r   c                    [        5       R                  U R                  5        U R                   H  nUR	                  5         M     g)z*Closes the sessions opened by this client.N)r  r  rH  r  r  r  s     rz   r   Client.closeQ
  s0    !!$--0}}G%%' %r   )rq   rb  r`  r  rc  r  rH  r   )r  rt  r  rG  r   r  )r   r  r  )r  r  r   r  )rb  r  r   r  )r  r  r   r  )rc  r  r   r  r  r   )r  r	  r
  r  r  r   r!  r)  r  r  r  r  r  r   r  r  r   rz   r  r  	  s~     264'4 /4 
	4*% ! !	
 
K2
8'B@(r   r  c                   U R                  SS5      n SU ;  =(       a/    U R                  S5      S:  =(       a    U R                  S5      S:H  (       + =(       a)    U R                  S5      =(       a    U R                  S5      n/ n[        R                  U(       a  U SS OU 5      nS	nU H  n0 n[        R                  U5      nU(       a4  UR                  S5      n[        UR                  S
5      5      US'   US-  nO2[        R                  U5      nU(       a  UR                  S5      nSUS'   [        SU 35      nUR                  (       d  [        SU 35      e UR                  UR                  UR                  S9  UR%                  U5        M     S	Us=:  a  ['        U5      :  a  O  O[#        SS5      eU(       a  SU0$ US	   $ ! [          a  n[#        SU 3S5      UeSnAff = f)zParses a list of host, port pairs.

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

Returns:
    Returns a dict with parsed values of host, port and priority if
    specified.
r2   ,r   r   []r  r   rh  rK  rL  z//zInvalid address: rw  zInvalid URI: i  NrN  rO  re   )replacer   rJ  endswith	_SPLIT_REr  _PRIORITY_REmatchgroupr  
_ROUTER_REr   r   r*   r   rd   r   r.   rs   r   )	pathr  re   address_listrU  addressrV  r  r   s	            rz   _parse_address_listr  X
  s    <<R D_MC1!4MCA9MN 	OOC 	MM# 
 G??4":DALN""7+kk!nG!$U[[^!4F:aN$$W-E++a.%(z"2gY(~~ #4WI!>??	IMMu~~EJJM? 	v/  2 	>-C--*
 	
 $)Iw8gaj8  	I"]3%#8$?SH	Is   $G
G,G''G,c                h   SS0n[         R                  U 5      nU(       a  UR                  5       OSU 4u  p0US;  a  [        SU S35      eUS:X  a  SUS	'   U R	                  S
5      SSS2   u  pEUR	                  S5      SSS2   u  pgUR                  S5      nXhS R                  S5      S:X  a  US:  a  UR                  SS5      u  oaS'   UR                  S5      nU(       a  U(       a  SU;  a  [        SU  S35      eUR                  SS5      u  p[        U	5      [        U
5      sUS'   US'   UR                  S5      (       a  [        U5      US'   O;UR                  S5      (       a  [        S5      eUR                  [        U5      5        Sn[        US5       H  u  pUR                  SS5      R!                  5       nX;   a  [        S U S35      eU["        ;   a  [        UR                  S5      5      X'   Ma  UR!                  5       nUS!;   a  SX'   M}  US";   a  S#X'   M  XU'   M     U$ )$aM  Parses the connection string and returns a dictionary with the
connection settings.

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

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

Raises:
    :class:`mysqlx.InterfaceError`: If contains a invalid option.
rb   r  r!  )r!  
mysqlx+srvzScheme 'z' is not validr  Trn   @Nrh  ?/)r  r   r   z()r   zMalformed URI 'r  r`   ra   )r  rN   r  rf   z\.zWindows Pipe is not supported)r`   ra   rn   rr   r  zInvalid option: ')1true)0falseF)_URI_SCHEME_REr  groupsr*   	partitionrfindfindrsplitr  r  r   rJ  r   r  r   r  r  	_SSL_OPTS)urirH  r  schemeuserinfotmprc   	query_strposr`   ra   invalid_optionsry   valoptval_strs                   rz   _parse_connection_urir  
  s    !)"~H  %E$)%,,.#KF--xx~>??"MM#&ss+MHmmC(1-OD
**S/CDzsr!cAg#';;sA#6 x ::dDx3h#6se1566^^C+ND-4T]GH<M*HVhz*'(($T]			<==+D125Oi.kk#s#))+! #4SE!;<<)#CIIdO4HMiikG-' $N* % ' / Or   c                Z	   [        U R                  5       5      R                  [        5      nU(       a   SR	                  U5      n[        SU S35      eSU ;   a  U S    H  n[        US5        M     OSU ;   a  [        U 5        SU ;   a  U S   n [        [        U[        5      (       a  UR                  5       R                  5       OU5      U S'   S
U ;  a2  U S   [        R                  [        R                  4;   a  [        S5      eSU ;   a  S
U ;  a  [        S5      eSU ;   a  SU ;  a  [        S5      eS
U ;   aM  U R!                  S5      [        R                  [        R                  [        R"                  4;  a  [        S5      eSU ;   aG  U S   n [%        [        U[        5      (       a  UR                  5       R                  5       OU5      U S'   SU ;   aG  U S   n ['        [        U[        5      (       a  UR                  5       R                  5       OU5      U S'   SU ;   a  [        U S   [        5      (       aD  U S   R                  5       R                  S5      nU(       a  UR)                  S5      U S'   O/S	U S'   O)[        U S   [*        [,        45      (       d  [        S5      eU R!                  S5      [&        R"                  :X  a  S	U S'   SU ;   a  [/        U 5        SU ;   aR   [        U S   [        5      (       a  [1        U S   5      U S'   [        U S   [0        5      (       a	  U S   S:  a  [        e SU ;   a  [        U S   [4        5      (       d  [        S 5      eU R!                  S!5      (       a  [        S"5      eU R!                  S#5      (       a  [        S$5      eU R!                  S5      (       a  [        S%5      eO!SU ;   a  U R!                  S#5      (       d  SU S#'   S&U ;   a  [7        U 5        S'U ;   a  [9        U 5        g	g	! [        [        4 a  n[        SU S    S35      UeS	nAff = f! [        [        4 a  n[        SU S    S35      UeS	nAff = f! [        [        4 a  n[        SU S    S35      UeS	nAff = f! [         a    [3        S5      S	ef = f)(aN  Validates the settings to be passed to a Session object
the port values are converted to int if specified or set to 33060
otherwise. The priority values for each router is converted to int
if specified.

Args:
    settings: dict containing connection settings.

Raises:
    :class:`mysqlx.InterfaceError`: On any configuration issue.
z', 'zInvalid option(s): 'r  re   rg  rc   rg   zInvalid SSL Mode 'Nr[   zCannot verify Server without CAr]   zCA Certificate not providedr\   rZ   zClient Certificate not providedz$Must verify Server if CA is providedrh   zInvalid Auth 'rl   zpThe connection property 'compression' acceptable values are: 'preferred', 'required', or 'disabled'. The value 'z' is not acceptablerm   z[]r  z@Invalid type of the connection property 'compression-algorithms'rk   rj   r   zEThe connection timeout value must be a positive integer (including 0)rn   z(The value of 'dns-srv' must be a booleanrf   z<Using Unix domain sockets with DNS SRV lookup is not allowedrd   z;Specifying a port number with DNS SRV lookup is not allowedzASpecifying multiple hostnames with DNS SRV look up is not allowedr^   r_   )setkeys
difference
_SESS_OPTSrv   r*   _validate_hostsr'   r}   rt   r  r  r   r   r   	VERIFY_CAr/  r  r%   r&   r  listr  _validate_connection_attributesr  	TypeErrorr  _validate_tls_versions_validate_tls_ciphersuites)	rH  invalid_optsinvalid_opts_listrV  r   r   rh   rl   compression_algorithmss	            rz   _validate_settingsr  
  s    x}}'22:>L"KK534E3FaHIIHy)FFE* *	8	!XJ'	X#*,6x,E,E &&(8$HZ 
 8#(<##A
 )
 !!BCCH!9:;;H8!;>??8Z 8A !
 CDD	P#(24(=(=

""$4 HV  }-	&1k3// !!#))+ 'H]#  8+h78#>>1288:@@F # &5K5Q5QRU5V125912H%=>uNN R  <<&+*>*>>15H-.(*'1H$	(#45s;;.1(;L2M.N*+x(9:C@@-.2   3 H(9-t44 !KLL<<!! N  << M  <<	"" S  # 
8	HLL$8$8 !x(X%"8, &I 
+ 	X #5hz6J5K1!MNTWW	X6 
+ 	P >(62B1C1!EFCO	P 
+ 	 ]+,,?A 		F  	( 	sX   AP AP= #AQ( /AR P:"P55P:=Q%Q  Q%(R8RRR*c                   SU ;   a;  U S   (       a1   [        U S   5      U S'   U S   S:  d	  U S   S:  a  [        SS5      e S	U ;   a  U S	   (       a   [        U S	   5      U S	'   gSU ;   a  U(       a  XS	'   ggg! [         a    [        SS5      Se[         a    [        SU S    3S5      Sef = f! [         a    [	        S
5      Sef = f)zValidate hosts.

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

Raises:
    :class:`mysqlx.InterfaceError`: If priority or port are invalid.
rK  r   rL  z1Invalid priority value, must be between 0 and 100rM  zInvalid priorityNzInvalid priority: rd   zInvalid portrc   )r  r.   	NameErrorr   r*   )rH  default_ports     rz   r  r  S  s    X(:"6	#&x
';#<HZ 
#a'8J+?#+E&G  ,F hv.	;"8F#34HV 
8	' !-	  	G"#5t<$F 	"$Xj%9$:;T	  	; 0d:	;s   /A9 B0 94B-0Cc                   0 nSU ;  a  gU S   n[        U[        5      (       a  US:X  a  0 U S'   gUR                  S5      (       a  UR                  S5      (       d  US;  a  [	        SU S35      eUS;   a  US	;   a  S
U S'   g0 U S'   gUSS R                  S5      nU HO  nUS:X  a  M  UR                  S5      nUS   n[        U5      S:  a  US   OSnXa;   a  [	        SU S35      eXqU'   MQ     GO'[        U[        5      (       a2  U H+  nX&   n[        U[        5      (       d  [        U5      nXU'   M-     O[        U[        5      (       d  US;   a  U(       a  0 U S'   gS
U S'   g[        U[        5      (       a  U H  nSX'   M	     O[        U[        5      (       aV  U HO  nUS:X  a  M  UR                  S5      nUS   n[        U5      S:  a  US   OSnXa;   a  [	        SU S35      eXqU'   MQ     O$[        U[        5      (       d  [	        SU S35      eU(       a  UR                  5        H  u  ph[        U[        5      (       d  [	        SU S35      e[        U5      S:  a  [	        SU S35      eUR                  S5      (       a  [	        SU S35      e[        U[        5      (       d  [	        SU SU S35      e[        U5      S:  d  M  [	        SU SU S35      e   XS'   g)zValidate connection-attributes.

Args:
    settings (dict): Settings dictionary.

Raises:
    :class:`mysqlx.InterfaceError`: If attribute name or value exceeds size.
rk   Nr  r  r  )Falser  Truer  z]The value of 'connection-attributes' must be a boolean or a list of key-value pairs, found: 'r  )r  r  Fr   r  r  =r   zDuplicate key 'z' used in connection-attributes)r   r   zLconnection-attributes must be Boolean or a list of key-value pairs, found: 'r=  r>  r?  r@  rr   zBKey names in connection-attributes cannot start with '_', found: 'zAttribute 'rB  rA  rC  )r}   rt   rJ  r  r*   r  r   r~   reprr  r  r  r  )	rH  r  r  conn_attributesattrattr_name_valrP  attr_valrQ  s	            rz   r  r  w  s    Jh.12J*c""02H,-!!#&&:+>+>s+C+C BB 44><qB  ;;//4901  5701$Qr*005#Drz JJsOM%a(I+.}+=+A}Q'rH&$%i[0OP  %-y! $ 
J	%	%#I#.Jj#..!*-
$.y!	 $
 
J	%	%v)=02H,- 	 16H,-	J	$	$#I$&J! $	J	%	%Drz JJsOM%a(I+.}+=+A}Q'rH&$%i[0OP  %-y!  
D))(\,
 	

 %/%5%5%7!Ii--$&yk1HI  9~"$&yk1ST  ##C(($$$-;a1  j#..$!)Jzl C$ $ 
 :%$!)Jzl C1 1 5 &8> )3$%r   c                ,   / nSU ;  a  gU S   n[        U[        5      (       a  UR                  S5      (       a  UR                  S5      (       d  [	        SU S35      eUSS R                  S	5      nU HO  nUR                  5       nUS
:X  a  M  XQ;   a  [	        [        R                  " SUS95      eUR                  U5        MQ     O[        U[        5      (       aP  U(       d  [	        S5      eU H7  nXA;   a  [	        [        R                  " SUS95      eUR                  U5        M9     OU[        U[        5      (       a  U H  nUR                  U5        M     O%[	        SSR                  [        5       SU S35      eU(       d  [	        S5      e/ n/ n/ nU HL  nU[        ;   a  UR                  U5        U[        ;   a  UR                  U5        M;  UR                  U5        MN     U(       aK  US/:X  a/  [        (       d$  [!        ["        R                  " U[        5      5      eUR%                  5         X`S'   gU(       a$  [!        [&        R                  " U[        5      5      eU(       a$  [	        [(        R                  " W[        5      5      eg)zValidate tls-versions.

Args:
    settings (dict): Settings dictionary.

Raises:
    :class:`mysqlx.InterfaceError`: If tls-versions name is not valid.
r^   Nr  r  z%tls-versions must be a list, found: 'r  r   r  r  r  tls_versionsr  r  zKAt least one TLS protocol version must be specified in 'tls-versions' list.z>tls-versions should be a list with one or more of versions in r   z
. found: 'r	   )r}   rt   rJ  r  r*   r  r  rO   rg  rs   r  r  rv   r#   r!   r   r+   rP   r   rQ   rR   )	rH  r  tls_versions_settingstls_verstls_verr   use_tls_versionsdeprecated_tls_versionsnot_tls_versionss	            rz   r  r    s    LX%$^4'--!,,S11%..s33 78M7NaP  )2.44S9G!--/Kb *$,33+; 
 ,   
)4	0	0$ 4  -G&$,33wW  ( - 
)3	/	/,G( - Lyy/01L>L
 	

 #
 	

  ,,##G,--#**73##G,   	{*3E3E#$++L:PQ  	#3 	 (//')?
 	

 
.55g?UVWW 
r   c                ^   / nSU ;  a  gU S   n[        U[        5      (       a  UR                  S5      (       a  UR                  S5      (       d  [	        SU S35      eUSS R                  S	5      nU(       d  [	        S
5      eU H;  nUR                  5       R                  5       nU(       d  M*  UR                  U5        M=     OD[        U[        [        45      (       a  U Vs/ sH  oD(       d  M  UPM     nnO[	        SU S35      eU R                  SS5      c	  [        SS OU S   SS nUR                  SS9  US   n/ n0 n/ n	[        S[        R                  " U5      S-     H3  n
UR                  [         U
   5        U	R#                  [$        U
   5        M5     U Hm  nSU;   a  X;   a  UR                  U5        M!  X;   a:  X   nX;   a  ['        [(        R*                  " SUS95      eUR                  U5        M`  [	        SU S35      e   U(       d  [	        S
5      eXpS'   gs  snf )zValidate tls-ciphersuites.

Args:
    settings (dict): Settings dictionary.

Raises:
    :class:`mysqlx.InterfaceError`: If tls-ciphersuites name is not valid.
r_   Nr  r  z)tls-ciphersuites must be a list, found: 'r  r   r  r  z:No valid cipher suite found in the 'tls-ciphersuites' listzItls-ciphersuites should be a list with one or more ciphersuites. Found: 'r^   Tr   r   r  tls_ciphersuitesr  zThe value 'z.' in cipher suites is not a valid cipher suite)r}   rt   rJ  r  r*   r  r  upperrs   r  r  r/  r#   r   r`  r   r$   r   r"   r   rO   rg  )rH  r  tls_ciphersuites_settingstls_csstls_csr  newer_tls_vertranslated_namesiani_cipher_suites_namesossl_cipher_suites_namesr	  r   translated_names                rz   r  r  B  sw    ) (); <+S11%0055)22377 -.a1  ,Ab177< L  F\\^))+Fv ''/  
-c{	;	;1JU1JvfF1JU014
 	
 <<-5 	q!n%a(  d# OM!*, *9
 
&
&}
5
9 	!''(9'(BC ''(8(AB	 !$;4;##D)-6<O2$,33/ 
 ##O4 dV#QR  !" H
 	
 $4 i Vs   &	H*3H*c                    0 nU (       ap  [        U S   [        5      (       a  [        U S   5      nO}[        U S   [        5      (       a0  U S   R	                  5        H  u  p4XBUR                  SS5      '   M     O4U(       a-  UR	                  5        H  u  p4XBUR                  SS5      '   M     U(       d  [        S5      e[        U5        U$ )a&  Parses the connection string and returns a dictionary with the
connection settings.

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

Returns:
    mysqlx.Session: Session object.

Raises:
    TypeError: If connection timeout is not a positive integer.
    :class:`mysqlx.InterfaceError`: If settings not provided.
r   rr   r  zSettings not provided)r}   rt   r  r~   r  r  r*   r  )r!  rw   rH  ry   r  s        rz   _get_connection_settingsr    s    $ Hd1gs##,T!W5HQ&& GMMO25S#./ ,	HC.1S[[c*+ ' 455x Or   c                 .    [        U 0 UD6n[        U5      $ )a  Creates a Session instance using the provided connection data.

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

Returns:
    mysqlx.Session: Session object.
)r  r	  )r!  rw   rH  s      rz   r  r    s     (88H8r   c                   [        U [        [        45      (       d  [        S5      e[	        U 5      n[        U[        [        45      (       d  [        S5      e[        U[        5      (       a   [
        R                  " U5      nO/0 nUR                  5        H  u  pVXcUR                  SS5      '   M     [        U[        5      (       d  [        S5      e0 nSU;   a  UR                  S5      n[        U[        5      (       d  [        S5      eUR                  S	S
5      US	'   UR                  SS5      US'   UR                  SS5      US'   UR                  SS5      US'   [        U5      S:  a  [        SU 35      e[        U5      S:  a  [        SUR                  5        35      e[        X'5      $ ! [         a  n[        S5      UeSnAff = f)a  Creates a Client instance with the provided connection data and settings.

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

        The string must have the following uri format::

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

        And the dictionary::

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

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

        Current options include::

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

Returns:
    mysqlx.Client: Client object.

.. versionadded:: 8.0.13
z(connection_data must be a string or dictz+connection_options must be a string or dictzA'pooling' options must be given in the form of a document or dictNr  rr   r  z<'pooling' options must be given in the form document or dictr  Tr`  ra  rb  r   rc  zUnrecognized pooling options: z!Unrecognized connection options: )r}   rt   r~   r*   r  jsonloadsr   r  r  r  r   r  r  )	connection_stringoptions_stringsettings_dictr  r   ry   r  pooling_options_dictpooling_optionss	            rz   
get_clientr#    s   j '#t55GHH,->?MnsDk22JKK.#&&	::n5L (..0JC27S#./ 1 lD))O
 	
 L &**95/D22 N  +:*=*=i*NY'+:+>+>z2+NZ(0?0C0COUV0W_-0?0C0COUV0W_- !# #A/AR!STT|q  3L4E4E4G3HI  -66G  	 S	s   .F4 4
G>G

G)rw   r   r   rt   )r   r;  r   r  )r&  r   r   r   )r  rt   r   z"Union[Dict[str, List[Dict]], Dict])r  rt   r   rt  rE  r   )rH  rt  r  r  r   r  )r!  r   rw   r   r   rt  )r!  r   rw   r   r   r	  )r  Union[str, Dict[str, Any]]r  r$  r   r  )r  
__future__r   typesr   r   r   PROTOCOL_TLSv1PROTOCOL_TLSv1_1PROTOCOL_TLSv1_2r   hasattrr   PROTOCOL_SSLv23r
   r   ImportErrorr  r   r  rl  r]  rerf   r  r  r  r   typingr   r   r   r   r   r   r   r   r   dns.exceptionr  dns.resolverr  r   r   	functoolsr   json.decoderr   urllib.parser   r   r   authenticationr   r   r   	constantsr    r!   r"   r#   r$   r%   r&   r'   crudr)   errorsr*   r+   r,   r-   r.   r/   helpersr0   r1   r2   r3   protobufr4   ry  r5   r6   r7   r8   r9   r"  r:   r;   r<   r=   r>   r  r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   r  rs   mysql.connector.abstractsrO   rP   rQ   rR   mysql.connector.utilsrS   mysql.connector.versionrT   rU   r  r  rl  rp  rf  r  r  rq  compilerp  r  r  _PENALTY_SERVER_OFFLINE_PENALTY_MAXED_OUT_PENALTY_NO_ADD_INFO_PENALTY_CONN_TIMEOUT_PENALTY_WRONG_PASSW_PENALTY_RESTARTINGr  r   r  VERBOSEr  r  r  r  r  r{   r   r   r)  r~   r+  r?  r  r  rm  rK  r  r	  r  r  r  r  r  r  r  r  r  r  r#  r  r   rz   <module>rE     s  > ; " M##''''L 3'' 	   
 !m4H  	    	  
    S S S N (  ( 5 5 V V	 	 	   G F   Q Q G G    J I    5 4 I   3 ; R  +   zz"9: ! !  "    #   +$/*-)&)  !%&9: JJ)*	zz>

KZZ12::>
AB	   
&8:q( q(h;|!,T !,HA' A'HW WtF'z F'RT#U[[ T#nE) E)PZ, Z,z
]( ](@49n<~B-L =A!(!(,9!(	!(Hm3`XXvV4r!H"c71c7.c7 c7wd  ML,  Ns$   A/L L+ L('L(+L76L7