
    vd                        d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
Z
ddlZddlZ	 ddlmZmZmZ ddlZddlmZ n!# e$ r ddlmZmZmZ ddlmZ ddlmZ Y nw xY wej        d         dk    r	 dd	lmZ d
Zn$# e$ r dZY nw xY w	 dd	lmZ d
Zn# e$ r dZY nw xY wddlZddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1 ddl0m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl0m8Z8 ddl9m:Z:m;Z;m<Z< e1j=        e1j>        fZ?e1j=        e1j@        e1jA        e1jB        e1jC        fZDg aEdZFdddZGi ZHdZIdZJdZKdZLdZMdZNdZOdZPdZQdZRdZSdZTdZUdZVeWfd df eXeYeWej        ejZ        g e[e<          z             d!dfeXe[fd"dfeYfd#eOfeWfd$dfeWfd%dfeWfd&eUfeYfd'eLfeYfd(eKfd)	Z\ e
j]        d*          Z^ G d+ d,e_          Z` G d- d.e_          Za G d/ d0e_          Zb G d1 d2eb          Zc G d3 d4e_          Zd G d5 d6ed          Zed7 Zfd8 Zgd9 Zhd: Zier G d; d<ejj                  Zk G d= d>e          Zl G d? d@e_          Zm G dA dBe_          Zn G dC dDen          Zo G dE dFen          Zp G dG dHe_          ZqdS )Iz,Implementing communication with MySQL Fabric    N)	b16decode)bisect)md5)FaultServerProxy	Transport)BadStatusLine   )HTTPSConnectionTF)MySQLConnection)MySQLConverter)MySQLConnectionPool)ErrorInterfaceErrorNotSupportedErrorMySQLFabricErrorInternalErrorDatabaseError)MySQLCursorMySQLCursorBufferedMySQLCursorRawMySQLCursorBufferedRaw)	errorcode   )FabricMySQLServerFabricShard)FabricCache)WeightedRoundRobinversion)PY2	isunicodeUNICODE_TYPESxmlrpci~  i~  )r$   mysql   GLOBALLOCALFAULTYzName of group of serverszSharding keyzList of tables in queryz#Read-Only, Write-Only or Read-Writez+Identity of the shard for direct connection z+GLOBAL for accessing Global Group, or LOCALzAttempts for getting connectionz$Seconds to wait between each attempt)	groupkeytablesmodeshardmappingscopeattemptsattempt_delayzmyconnpy-fabricc                   8    e Zd ZdZd Zd Zd Zd	dZd Zd Z	dS )
MySQLRPCProtocolz0Class using MySQL protocol to query Fabric.
    c                     t                      | _        t          |||||          | _        | j                                         d S N)r   	converterFabricMySQLConnectionhandlerconnectselffabrichostportconnect_attemptsconnect_delays         ]/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/mysql/connector/fabric/connection.py__init__zMySQLRPCProtocol.__init__   sH    ')),VT4-=-:< < 	    c           	         	 g }t          |                                          D ]\  }}|}| j                            |          }| j                            |          }| j                            |          }|                    d                    |t          |                               	 |S # t          $ r,}t          j        j                            d|z            d}~ww xY w)z,Process query parameters given as dictionaryz{0}={1}z)Failed processing pyformat-parameters; %sN)listitemsr8   to_mysqlescapequoteappendformatstr	Exceptionr%   	connectorerrorsProgrammingError)r=   paramsresr,   valueconverrs          rC   _process_params_dictz%MySQLRPCProtocol._process_params_dict   s    	C"6<<>>22 = =
U~..t44~,,T22~++D11

9++CT;;<<<<= J	  	C 	C 	C/(99;cAC C C	Cs   B/B4 4
C*>'C%%C*c                     	 |} fd|D             } fd|D             } fd|D             }d |D             }t          |          S # t          $ r,}t          j        j                            d|z            d}~ww xY w)zProcess query parameters.c                 D    g | ]}j                             |          S  )r8   rI   .0ir=   s     rC   
<listcomp>z4MySQLRPCProtocol._process_params.<locals>.<listcomp>   s)    ;;;!4>**1--;;;rE   c                 D    g | ]}j                             |          S r[   )r8   rJ   r\   s     rC   r_   z4MySQLRPCProtocol._process_params.<locals>.<listcomp>   s)    9994>((++999rE   c                 D    g | ]}j                             |          S r[   )r8   rK   r\   s     rC   r_   z4MySQLRPCProtocol._process_params.<locals>.<listcomp>   s)    888q4>''**888rE   c                 ,    g | ]}t          |          S r[   )rN   )r]   r^   s     rC   r_   z4MySQLRPCProtocol._process_params.<locals>.<listcomp>   s    '''a3q66'''rE   z'Failed processing format-parameters; %sN)tuplerO   r%   rP   rQ   rR   )r=   rS   rT   rW   s   `   rC   _process_paramsz MySQLRPCProtocol._process_params   s    
	C;;;;s;;;C9999S999C8888C888C''3'''C
 ::	  	A 	A 	A/(999C?A A A	As   8A
 

B 'A;;B Nc                     |sd}| j         j                            d          }g }|                    ||d          D ])}|                    |                                           *|S )zYExecutes the given query

        Returns a list containing response from Fabric
        r[   T)
dictionary)multi)r:   
connectioncursorexecuterL   fetchall)r=   stmtrS   curresultsrT   s         rC   _execute_cmdzMySQLRPCProtocol._execute_cmd   st    
  	Fl%,,,==;;tV4;88 	+ 	+CNN3<<>>****rE   c                     g }|r*|                      |          }|                    |           |r*|                     |          }|                    |           d                    |          }|S )z6Process arguments to create query parameters.
        z, )rd   extendrX   join)r=   argskwargsrS   s       rC   create_paramszMySQLRPCProtocol.create_params   sy      	 ''--DMM$ 	"..v66FMM&!!!6""rE   c                 N    | j         |i |}d                    |||          }d}	 |                     |          }t          |          }nX# t          t
          j        t          f$ r9}	d                    ||t          |	                    }
t          |
          d}	~	ww xY w|S )zExecutes the given command with MySQL protocol

        Executes the given command with the given parameters.

        Returns an iterator to navigate to navigate through the result set
        returned by Fabric
        zCALL {0}.{1}({2})N+Executing {group}.{command} failed: {error}r+   commanderror)	ru   rM   ro   FabricMySQLSetr   socketrz   r   rN   )r=   r+   ry   rs   rt   rS   cmdfab_setdataexcmsgs              rC   rj   zMySQLRPCProtocol.execute   s     $#T4V44!((@@	&$$S))D$T**GGv|^4 	& 	& 	&?FFWCHH G > >C %%%	&
 s   $A B")4BB"r7   )
__name__
__module____qualname____doc__rD   rX   rd   ro   ru   rj   r[   rE   rC   r5   r5      s}                         rE   r5   c                       e Zd ZdZd Zd ZdS )XMLRPCProtocolz2Class using XML-RPC protocol to query Fabric.
    c                 h    t          |||||          | _        | j                                         d S r7   )FabricXMLRPCConnectionr:   r;   r<   s         rC   rD   zXMLRPCProtocol.__init__   s:    -fdD.>O OrE   c           
         	 t          | j        j        |          }t          ||          }nD# t          $ r7}t	          d                    ||t          |                              d}~ww xY wd}	  ||i |}	t          |	          }nX# t          t          j
        t          f$ r9}d                    ||t          |                    }
t          |
          d}~ww xY w|S )zExecutes the given command with XML-RPC protocol

        Executes the given command with the given parameters

        Returns an iterator to navigate to navigate through the result set
        returned by Fabric
        z'{group}.{command} not available ({err}))r+   ry   rW   Nrw   rx   )getattrr:   proxyAttributeError
ValueErrorrM   rN   	FabricSetr   r|   rz   r   )r=   r+   ry   rs   rt   grpr}   r   r~   r   r   s              rC   rj   zXMLRPCProtocol.execute   s   	=$,,e44C#w''CC 	= 	= 	=FMMW#c(( N < < = = =	= 	&3'''DooGGv|^4 	& 	& 	&?FFWCHH G > >C %%%	&
 s,   *- 
A.2A))A.4B C!(4CC!N)r   r   r   r   rD   rj   r[   rE   rC   r   r      s<           
    rE   r   c                       e Zd ZdZd ZdS )FabricMySQLResponsezHClass used to parse a response got from Fabric with MySQL protocol.
    c                     |d         d         }|d         |d         |d         }}}|rt          |          || _        || _        |d         | _        d S )Nr   fabric_uuidttlmessager   )r   fabric_uuid_strr   
coded_rows)r=   r   infor   r   rz   s         rC   rD   zFabricMySQLResponse.__init__  sa    Awqz)-m)<d5k)-i  %# 	( '''.q'rE   N)r   r   r   r   rD   r[   rE   rC   r   r     s-         	" 	" 	" 	" 	"rE   r   c                   4     e Zd ZdZ fdZd Zd Zd Z xZS )r{   z^Iterator to navigate through the result set returned from Fabric
    with MySQL Protocol.
    c                     t          t          |                               |           | j        d                                         | _        | j        | _        t          j        d| j                  | _	        dS ))Initialize the FabricSet object.
        r   	ResultSetN)
superr{   rD   r   keys_FabricMySQLSet__names_FabricMySQLSet__rowscollections
namedtuple_FabricMySQLSet__resultr=   r   	__class__s     rC   rD   zFabricMySQLSet.__init__(  s`     	nd##,,T222q)..00o#.{DLIIrE   c                 *    t          | j                  S z.The number of rows in the result set.
        )lenr   r=   s    rC   rowcountzFabricMySQLSet.rowcount0       4;rE   c              #   <   K   | j         D ]} | j        di |V  dS )UIterate over the rows of the result set.

        Each row is a named tuple.
        Nr[   )r   r   r=   rows     rC   rowszFabricMySQLSet.rows5  sD      
 ; 	' 	'C$-&&#&&&&&&	' 	'rE   c                 2     | j         di | j        |         S )GIndexing method for a row.

        Each row is a named tuple.
        r[   )r   r   r=   indexs     rC   r   zFabricMySQLSet.row=  s#    
 t}22t{51222rE   	r   r   r   r   rD   r   r   r   __classcell__r   s   @rC   r{   r{   $  st         J J J J J     
' ' '3 3 3 3 3 3 3rE   r{   c                       e Zd ZdZdZd ZdS )FabricResponsez4Class used to parse a response got from Fabric.
    r   c                     |\  }}}}}|rt          |          |t          j        k    r.t          d                    t          j        |                    || _        || _        || _        || _        dS )z-Initialize the FabricResponse object
        zdSupported protocol has version {sversion}. Got a response from MySQL Fabric with version {gversion}.)sversiongversionN)r   r   SUPPORTED_VERSIONrM   format_versionr   r   r   )r=   r   r   r   r   rz   r   s          rC   rD   zFabricResponse.__init__K  s     ?C;#ud 	( '''^=== ==CV+=+ >D >- >-   -.rE   N)r   r   r   r   r   rD   r[   rE   rC   r   r   E  s5              rE   r   c                   4     e Zd ZdZ fdZd Zd Zd Z xZS )r   zEIterator to navigate through the result set returned from Fabric
    c                     t          t                                         |           t           j                  dk    sJ  j        d         d         d          _         j        d         d          _        t           fd j        D                       st           j                  dk    sJ t          j	        d j                   _
        dS )	r   r   r   r   namesr   c              3   b   K   | ])}t          j                  t          |          k    V  *d S r7   )r   _FabricSet__names)r]   r   r=   s     rC   	<genexpr>z%FabricSet.__init__.<locals>.<genexpr>h  s8      HHS3t|$$C0HHHHHHrE   r   N)r   r   rD   r   r   r   _FabricSet__rowsallr   r   _FabricSet__resultr   s   ` rC   rD   zFabricSet.__init__a  s     	i''---4?##q((((q)&1':oa(0HHHHDKHHHHH 	%4;1$$$$#.{DLIIrE   c                 *    t          | j                  S r   )r   r   r   s    rC   r   zFabricSet.rowcountl  r   rE   c              #   6   K   | j         D ]} | j        | V  dS )r   N)r   r   r   s     rC   r   zFabricSet.rowsq  s;      
 ; 	& 	&C$-%%%%%	& 	&rE   c                 ,     | j         | j        |          S )r   )r   r   r   s     rC   r   zFabricSet.rowy  s    
 t}dk%011rE   r   r   s   @rC   r   r   ^  st         	J 	J 	J 	J 	J     
& & &2 2 2 2 2 2 2rE   r   c                     | sg a t          | t          t          f          s| g} | D ]L}t          |t                    r|dk    r|dk     st          d          t                               |           MdS )ax  Add MySQL error to be reported to Fabric

    This function adds error_codes to the error list to be reported to
    Fabric. To reset the custom error reporting list, pass None or empty
    list.

    The error_codes argument can be either a MySQL error code defined in the
    errorcode module, or list of error codes.

    Raises AttributeError when code is not an int.
    i  i  zUnknown or invalid error code.N)REPORT_ERRORS_EXTRA
isinstancerG   rc   intr   rL   )error_codescodes     rC   extra_failure_reportr     s      ! kD%=11 $"m ) )$$$ 	CTT\\dTkk !ABBB""4(((() )rE   c                 0    d                     | |          S )zCreate an XMLRPC URI for connecting to Fabric

    This method will create a URI using the host and TCP/IP
    port suitable for connecting to a MySQL Fabric instance.

    Returns a URI.
    zhttp://{host}:{port}r?   r@   )rM   r   s     rC   _fabric_xmlrpc_urir     s     "((d(>>>rE   c                 \    t          j        t           j        t          | |                    S )z!Create a UUID using host and port)uuiduuid3NAMESPACE_URLr   r   s     rC   _fabric_server_uuidr     s"    :d(*<T4*H*HIIIrE   c                     t           st          d          t          | ||g          r.| st          d          |s|r|r|st          d          | ||dS dS )zvValidate the SSL argument.

    Raises AttributeError is required argument is not set.

    Returns dict or None.
    Python does not support SSLzMissing ssl_ca argument.z;ssl_key and ssl_cert need to be both specified, or neither.)car,   certN)HAVE_SSLr   anyr   )ssl_cassl_keyssl_certs      rC   _validate_ssl_argsr     s      <:;;;
FGX&'' 
 	= !;<<< 	x 	' 	h 	 )  
 
 
 	
 4rE   c                   0     e Zd ZdZ fdZd ZddZ xZS )FabricHTTPSHandlerz Class handling HTTPS connectionsc                     t           r t          j                            |            n t	                                                       || _        dS 
InitializeN)r!   urllib2HTTPSHandlerrD   r   _ssl_config)r=   
ssl_configr   s     rC   rD   zFabricHTTPSHandler.__init__  sI     #$--d3333  """)DrE   c                 8    |                      | j        |          S )zOpen HTTPS connection)do_openget_https_connection)r=   reqs     rC   
https_openzFabricHTTPSHandler.https_open  s    << 93???rE   ,  c                 R    t          || j        d         | j        d                   S )zReturns a HTTPSConnectionr,   r   )key_file	cert_file)r   r   )r=   r?   timeouts      rC   r   z'FabricHTTPSHandler.get_https_connection  s2    ")%0*62   rE   )r   )r   r   r   r   rD   r   r   r   r   s   @rC   r   r     sd        ..	* 	* 	* 	* 	*	@ 	@ 	@	 	 	 	 	 	 	 	rE   r   c                   b     e Zd ZdZd                    ej                  Z	 d fd	Zd	dZ	 xZ
S )
FabricTransportz"Custom XMLRPC Transport for FabriczMySQL Connector Python/{0}r   FNc                 6   t           rt          j        | d           n"t                                          d           || _        || _        || _        || _        || _        || _        g | _        | j        r>| j        r7t          j
                    | _        t          j        | j                  | _        nd| _        d| _        |r"| j                            |           d| _        nd| _        | j        r!| j                            | j                   dS dS )r   F)use_datetimeNhttpshttp)r!   r   rD   r   	_username	_password_use_datetimeverbose	_handlersr   HTTPPasswordMgrWithDefaultRealm_passmgrHTTPDigestAuthHandler_auth_handlerrL   _scheme)r=   usernamepasswordr  r   https_handlerr   s         rC   rD   zFabricTransport.__init__  s     	1t%88888GG%000!!)!!> 	!dn 	!#CEEDM!(!>t}!M!MD!%D DM 	"N!!-000"DLL!DL 	6N!!$"455555	6 	6rE   c                 (   d                     | j        ||          }| j        r'| j                            d|| j        | j                   | j        r-t                              d                     |                     t          j
        | j         }d| j        d}t          j        |||          }	 |                     |                    |                    S # t          j        t          j        f$ r}		 d}
|	j        d	k    r
d
}|	j        }
n|	j        }d                     ||
          }n3# t(          $ r& dt+          |	          v rd}nt+          |	          }Y nw xY wt-          d|z             d}	~	wt.          $ r t-          d          w xY w)zSend XMLRPC requestz{scheme}://{host}{handler})schemer?   r:   NzFabricTransport: {0}ztext/xml)zContent-Typez
User-Agent)headersi  zPermission deniedz{reason} ({code}))reasonr   SSLz	SSL errorzConnection with Fabric failed: z(Connection with Fabric failed: check SSL)rM   r  r  add_passwordr   r   r  _LOGGERdebugr   build_openerr  
user_agentRequestparse_responseopenURLError	HTTPErrorr   r  r   rN   r   r	   )r=   r?   r:   request_bodyr  uriopenerr  r   r   r   r  r   s                rC   requestzFabricTransport.request  s   *117;W 2 N N = 	7M&&tS$.'+~7 7 7< 	>MM077<<===%t~6 '/
 
 oc<AAA	M&&v{{3'7'7888 '"34 	J 	J 	J#8s??0F8DD ZF)00T0JJ! # # #CHH$$%CCc((C	#
 !!BS!HIII 	M 	M 	M !KLLL	Ms6   5'C F95D/.E4/-EE4EE44F)r   FN)r   )r   r   r   r   rM   r    VERSION_TEXTr  rD   r  r   r   s   @rC   r   r     s|        ,,-44W5IJJJ ?C6 6 6 6 6 6@%M %M %M %M %M %M %M %MrE   r   c                       e Zd ZdZdddeedddddefdZed             Z	ed             Z
ed             ZddZdd	Zd
 Zd ZddZddZddZddZedfdZd ZdS )Fabricz%Class managing MySQL Fabric instancesNFc                    |dk    rt           | _        n5|dk    rt          | _        n"t          d                    |                    |st
          |         }i | _        d| _        d| _        d| _	        || _
        || _        t                      | _        i | _        || _        || _        t#          ||	|
          | _        || _        || _        |r|rt+          d          |p|| _        || _        dS )r   r$   r%   z0Protocol not supported by MySQL Fabric, was '{}'N<   z&can not specify both user and username)r   _protocol_classr5   r   rM   MYSQL_FABRIC_PORT_fabric_instances_fabric_uuid_ttl_version_token_connect_attempts_connect_delayr   _cache_group_balancers
_init_host
_init_portr   _ssl_report_errors	_protocolr   r   r   )r=   r?   r  r	  r@   rA   rB   report_errorsr   r   r   userprotocols                rC   rD   zFabric.__init__1  s    x#1D    #3D   "F8,,. . .  	/$X.D!# 	"!1+!mm "&vwAA	+! 	GH 	GEFFF)!rE   c                     | j         S )z0Return username used to authenticate with Fabric)r   r   s    rC   r  zFabric.usernameW       ~rE   c                     | j         S )z0Return password used to authenticate with Fabric)r   r   s    rC   r	  zFabric.password\  r7  rE   c                     | j         S )zReturn the SSL configuration)r0  r   s    rC   r   zFabric.ssl_configa  s     yrE   c                    |p| j         }|p| j        }|                     | ||| j        | j                  }|                     |          \  }}}}|st          d          | j        |k    rdS t          	                    d
                    |                     || _        || _        |dk    r|| _        |D ]}|                     | |d         |d         | j        | j                  }	|	j        j        }
|
| j        vrM|	| j        |
<   t                              d	
                    |	j        j        |	j        j        
                     dS )zGet MySQL Fabric Instances

        This method uses host and port to connect to a MySQL Fabric server
        and get all the instances managing the same metadata.

        Raises InterfaceError on errors.
        )rA   rB   z%Failed getting list of Fabric serversNz.Loading Fabric configuration version {version}r   r   r?   r@   z%Added new Fabric server {host}:{port}r   )r.  r/  r$  r*  r+  get_fabric_serversr   r)  r  r   rM   r'  r(  r:   r   r&  r  r?   r@   )r=   r?   r@   fabinstr   fabric_versionr   fabricsr>   inst	inst_uuids              rC   seedzFabric.seedf  s    &t&t&&tT48<8N595H ' J J 594K4K5 51^S'  	J !HIII.00F<CC& D ( (	) 	) 	) (,77DI  		I 		IF''fVnfVn9=9O6:6I ( K KD )I 66648&y1;BB!\.T\5F C H HI I I		I 		IrE   c                     |rGt                               d                    |                     |                     |d           dS t                               d           t	                      | _        dS )zWReset cached information

        This method destroys all cached information.
        z#Resetting cache for group '{group}'r+   F	use_cachezResetting cacheN)r  r  rM   get_group_serversr   r,  r=   r+   s     rC   reset_cachezFabric.reset_cache  s    
  	(MM?FF G     ""5E":::::MM+,,,%--DKKKrE   c                 <   d}d}| j         st          |dz             t          r-| j                                         }| j         ||                  }n%| j         t	          | j                   |                  }|j        j        s|j                                         |S )zGet a MySQL Fabric Instance

        This method will get the next available MySQL Fabric Instance.

        Raises InterfaceError when no instance is available or connected.
        r   z"No MySQL Fabric instance availablez (not seeded?))r&  r   r!   r   rG   r:   is_connectedr;   )r=   nxterrmsginstance_listr?  s        rC   get_instancezFabric.get_instance  s     5% 	< *:!:;;; 	M 27799M)-*<=DD)$t/E*F*Fs*KLD|( 	#L  """rE   c                    | j         sdS t          |          }t          j                    }|t          v s	|t
          v rt                              d||           |                                 }	 |	                    dd|||          }t          |           dS # t          t          j        f$ r3}t                              dt          |                     Y d}~dS d}~ww xY wdS )z{Report failure to Fabric

        This method sets the status of a MySQL server identified by
        server_uuid.
        NzReporting error %d of server %sthreatreport_failurez&Failed reporting server to Fabric (%s))r1  r   r|   getfqdnREPORT_ERRORSr   r  r  rN  rj   r   r   rz   rN   )r=   server_uuiderrnocurrent_hostr?  r   r   s          rC   rQ  zFabric.report_failure  s    " 	FE

~''M!!U.A%A%AMM;U%' ' '$$&&D(||H.>$/uF Ft$$$$$6<( ( ( (F!#hh( ( ( ( ( ( ( ( (( &B%As   /(B C"/(CC"c                    |p|                                  }g }d}	 |                    ddd| j        z             }|                                D ]$}|                    |j        |j        d           %n# t          t          j	        f$ rM}|
                    t          |          |j        j        |j        j                  }t          |          d}~wt          t          f$ rS}|
                    d
                    |          |j        j        |j        j                  }t          |          d}~ww xY w	 t!          j        |j                  }	n## t          $ r t!          j                    }	Y nw xY wd	}
|	|
|j        |fS )
a  Get all MySQL Fabric instances

        This method looks up the other MySQL Fabric instances which uses
        the same metadata. The returned list contains dictionaries with
        connection information such ass host and port. For example:

        [
            {'host': 'fabric_prod_1.example.com', 'port': 32274 },
            {'host': 'fabric_prod_2.example.com', 'port': 32274 },
        ]

        Returns a list of dictionaries
        z;Looking up Fabric servers failed using {host}:{port}: {err}dumpfabric_nodesz	protocol.r   )rW   r?   r@   Nz No Fabric server available ({0})r   )rN  rj   r2  r   rL   r?   r@   r   r|   rz   rM   rN   r:   r   	TypeErrorr   r   UUIDr   uuid4r   )r=   
fabric_cnxr?  resulterr_msgfsetr   r   r   r   r=  s              rC   r;  zFabric.get_fabric_servers  s    0T..00O	&<< +dn <> >D yy{{ D DsxBBCCCCDv|$ 	& 	& 	&..SXXDL4E&*l&7 ! 9 9C %%%>* 	& 	& 	&..6==cBB\&T\-> ! @ @C !%%%		&	')D$899KK 	' 	' 	'*,,KKK	' NDHf<<s8   AA5 5D:ACD:'AD55D:>E E87E8Tc           
         |r#| j                             |          }|r|j        S |                                 }g }	 |                    dd| j        |          }nQ# t          t          j        f$ r8}d	                    t          |          |          }t          |          d}~ww xY wg }	|                                D ]}
|
j        |k    r~t          |
j        |
j        |
j        |
j        |
j        |
j        |
j                  }|                    |           |j        t,          k    r!|	                    |j        |j        f           | j                             ||           |	rt3          |	 | j        |<   |S )a?  Get all MySQL servers in a group

        This method returns information about all MySQL part of the
        given high-availability group. When use_cache is set to
        True, the cached information will be used.

        Raises InterfaceError on errors.

        Returns list of FabricMySQLServer objects.
        rX  serversz:Looking up MySQL servers failed for group {group}: {error})rz   r+   N)r,  group_searchrb  rN  rj   r)  r   r|   rz   rM   rN   r   r   group_idr   rT  r?   r@   r.   statusweightrL   STATUS_SECONDARYr   cache_groupr   r-  )r=   r+   rE  entryr?  r^  r`  r   r   weightsr   mysqlservers               rC   rF  zFabric.get_group_servers  s     	%K,,U33E %}$  ""	&<<	43FNNDDv|$ 	& 	& 	&&'-vCHHEv'J'J  %%%	&
 99;; 		K 		KC|u$$/OS\38SXHcj#*  k***%)999NNK$4k6H#IJJJv... 	H+=w+GD!%(s   A B)13B$$B)c                    |r|rt          d          d}|                     |d          }|s#t          |                    |                    d}g }|D ]:}|j        t
          k    r|                    |           (|j        t          k    r|};|t          t          fv s|t          k    rH|sD| 
                    |           t          |dz                       |rdnd	||p|
                    |S |s|r|S || j        v r9| j        |                                         d         }	|D ]}
|	|
j        k    r|
c S | 
                    |           t          |                    ||                    )a  Get a MySQL server from a group

        The method uses MySQL Fabric to get the correct MySQL server
        for the specified group. You can specify mode or status, but
        not both.

        The mode argument will decide whether the primary or a secondary
        server is returned. When no secondary server is available, the
        primary is returned.

        Status is used to force getting either a primary or a secondary.

        The returned tuple contains host, port and uuid.

        Raises InterfaceError on errors; ValueError when both mode
        and status are given.

        Returns a FabricMySQLServer object.
        z-Either mode or status must be given, not bothz-No MySQL server available for group '{group}'TrD  rC  Nz {query}={value}re  r.   )queryr+   rU   r   )r+   r.   )r   rF  r   rM   re  rg  rL   STATUS_PRIMARYMODE_WRITEONLYMODE_READWRITErH  r-  get_nextr   )r=   r+   r.   re  rL  rb  primary	secondaryservernext_secondaryrk  s              rC   get_group_serverzFabric.get_group_server$  s   (  	AF 	A?A A A A(($(?? 	= U!;!;<<< 	 	! 	!F} 000  ((((.00 NN333v7O7O +  u ---$f/A&A%I%I&,8((& .D &J &* &* + + + N  	'W 	'Nd+++!259BBDDQGN( ' '![%555&&&& 6 	u%%%V]]T]BBCCCrE   c                    t          |t          t          f          st          d          g }|D ]}t          |t          t          f          s$|s"t          d                    |                    t          |t          t          f          r|d         }|d         }n|}|}|                    d                    ||                     |                                 }	 |                    dd| j        d	                    |                    }nP# t          t          j        f$ r7}	d	                    t          |	          
          }
t          |
          d}	~	ww xY w|                                D ]X}| j                            t%          |j        |j        |j        |j        |j        |j        |j        |j                             YdS )a  Get and cache the sharding information for given tables

        This method is fetching sharding information from MySQL Fabric
        and caches the result. The tables argument must be sequence
        of sequences contain the name of the database and table. If no
        database is given, the value for the database argument will
        be used.

        Examples:
          tables = [('salary',), ('employees',)]
          get_sharding_information(tables, database='employees')

          tables = [('salary', 'employees'), ('employees', employees)]
          get_sharding_information(tables)

        Raises InterfaceError on errors; ValueError when something is wrong
        with the tables argument.
        tables should be a sequencez#No database specified for table {0}r   r   z{0}.{1}rX  sharding_information,z0Looking up sharding information failed : {error}rz   N)r   rG   rc   r   rM   rL   rN  rj   r)  rr   r   r|   rz   rN   r   r   r,  sharding_cache_tabler   schema_name
table_namecolumn_namelower_boundshard_id	type_namerd  global_group)r=   r-   databasepatternstabledbasetblr?  r`  r   r   r   s               rC   get_sharding_informationzFabric.get_sharding_information`  s   & &4-00 	<:;;; 	: 	:EedE]33 H  !F!M!M" "    %$// aAh OOI,,UC889999  ""		&<<.0C"" DD v|$ 	& 	& 	&DKK#hh L    C %%%	&
 99;; 	 	CK,,COS^S_OS\3=L#*:< <   	 	s   "0D E )2EE c                 >   t          |t          t          f          st          d          g |D ]O}	 |                    d          \  }}n0# t          $ r# t          d                    |                    w xY w| j                            ||          }|sd|                     |f|           | j                            ||          }|s0t          t          j        d                    ||                    |dk    r|                     |j        |          c S |j        d	k    r]	 t          |          }	n# t          $ r t          d
          w xY w|j        }
|
t#          |
|	          dz
           }|j        |         }n|j        dk    rt          |t&          j        t&          j        f          st          d          d}|j        D ]}||k    r|} n	 |j        |         }nJ# t,          $ r# t          d                    |                    w xY w|j        dk    rst/          |          st          d          d}|j        D ]}||k    r|} n	 |j        |         }n# t,          $ r# t          d                    |                    w xY w|j        dk    rjt1          t3          |                    }|j        d         }|j        D ]+}|                                t7          |          k    r|} n,|j        |         }n't9          d                    |j                                                |d                    t=          fdD                       st          d          Q|                     d         |          S )a"  Get MySQL server information for a particular shard

        Raises DatabaseError when the table is unknown or when tables are not
        on the same shard. ValueError is raised when there is a problem
        with the methods arguments. InterfaceError is raised for other errors.
        rx  .z5tables should be given as <database>.<table>, was {0}z"Unknown table '{database}.{table}')r  r  )rU  r   r'   r.   RANGEz Key must be an integer for RANGEr   RANGE_DATETIMEzAKey must be datetime.date or datetime.datetime for RANGE_DATETIMENzKey invalid; was '{0}'RANGE_STRINGzKey must be a unicode valueHASHr  zUnsupported sharding type {0}r+   c              3   0   K   | ]}|d          k    V  dS )r   Nr[   )r]   r+   groupss     rC   r   z*Fabric.get_shard_server.<locals>.<genexpr>  s,      >>euq	)>>>>>>rE   z'Tables are located in different shards.r   )r   rG   rc   r   splitrM   r,  sharding_searchr  r   r   ER_BAD_TABLE_ERRORrv  r  
shard_typer   r   r   partitioningdatetimedatekeys_reversedKeyErrorr"   r   rN   digestr   r   rL   r   )r=   r-   r,   r1   r.   dbobjr  r  ri  	range_key
partitionsr   	partitionpartkeymd5keyr  s                  @rC   get_shard_serverzFabric.get_shard_server  sb    &4-00 	<:;;; F	? F	?E-"'++c"2"2%% - - - $fUmm- - --
 K//%@@E =--uhAAA33HeDD ='':@GG%-U H < <= = = =
   ,,U-?d,KKKKK7**I #CII! I I I$%GHHHI"Z
"6*i#@#@1#DE!.u5		!%555!#x7H'IJJ *$)* * * $2  Gg~~ ' &K % 25 9II K K K$%=%D%DS%I%IJJJK!^33 ~~ D$%BCCC$2  Gg~~ ' &K % 25 9II K K K$%=%D%DS%I%IJJJK!V++SXX+B/$2  G}})G*<*<<< ' = ".u5		$3::5;KLLN N N MM)G,--->>>>v>>>>> ?#=? ? ?? $$VAYT$:::s/   A-A;/D??E"G11-H!I//-Jc                 N    |                                  } |j        ||g|R i |S )ai  Execute a Fabric command from given group

        This method will execute the given Fabric command from the given group
        using the given arguments. It returns an instance of FabricSet.

        Raises ValueError when group.command is not valid and raises
        InterfaceError when an error occurs while executing.

        Returns FabricSet.
        )rN  rj   )r=   r+   ry   rs   rt   r?  s         rC   rj   zFabric.execute  s9       ""t|E7<T<<<V<<<rE   )NNr7   )T)r   r   r   r   _CNX_ATTEMPT_MAX_CNX_ATTEMPT_DELAYDEFAULT_FABRIC_PROTOCOLrD   propertyr  r	  r   rA  rH  rN  rQ  r;  rF  rv  r  SCOPE_LOCALr  rj   r[   rE   rC   r!  r!  -  so       //&*T"21$dT1$" $" $" $"L   X   X   X+I +I +I +IZ( ( ( (  (( ( (2(= (= (= (=T+ + + +Z:D :D :D :Dx5 5 5 5n 3>D T; T; T; T;l= = = = =rE   r!  c                       e Zd ZdZee         eefdZe	d             Z
e	d             Ze	d             Zd Ze	d             Zd Zd	S )
FabricConnectionzIBase Class for a class holding a connection to a MySQL Fabric server
    c                     t          |t                    st          d          || _        || _        || _        || _        || _        dS )r   z'fabric must be instance of class FabricN)r   r!  r   _fabric_host_portr*  r+  r<   s         rC   rD   zFabricConnection.__init__  sQ    
 &&)) 	HFGGG

!1+rE   c                     | j         S )z6Returns server IP or name of current Fabric connection)r  r   s    rC   r?   zFabricConnection.host       zrE   c                     | j         S )z0Returns TCP/IP port of current Fabric connection)r  r   s    rC   r@   zFabricConnection.port  r  rE   c                 6    t          | j        | j                  S )z7Returns UUID of the Fabric server we are connected with)r   r  r  r   s    rC   r   zFabricConnection.uuid  s     #4:tz:::rE   c                     dS zConnect with MySQL FabricNr[   r   s    rC   r;   zFabricConnection.connect  s    rE   c                     dS )Check whether connection with Fabric is valid

        Return True if we can still interact with the Fabric server; False
        if Not.

        Returns True or False.
        Nr[   r   s    rC   rJ  zFabricConnection.is_connected  s	     	rE   c                 P    d                     | j        | j        | j                  S )Nz"{class_}(host={host}, port={port}))class_r?   r@   )rM   r   r  r  r   s    rC   __repr__zFabricConnection.__repr__*  s.    3::> ; 
 
 	
rE   N)r   r   r   r   r%  r  r  r  rD   r  r?   r@   r   r;   rJ  r  r[   rE   rC   r  r    s          ((?@"21, , , ,   X   X ; ; X;     X
 
 
 
 
rE   r  c                        e Zd ZdZed         eef fd	Zed             Z	ed             Z
d Zd Zed             Z xZS )	r   zCClass holding a connection to a MySQL Fabric server through XML-RPCr$   c                 n    t          t          |                               |||||           d| _        dS r   )r   r   rD   _proxyr=   r>   r?   r@   rA   rB   r   s         rC   rD   zFabricXMLRPCConnection.__init__6  sA     	$d++44D$ 0-	
 	
 	
 rE   c                     | j         S )z5Returns the XMLRPC Proxy of current Fabric connection)r  r   s    rC   r   zFabricXMLRPCConnection.proxy?  s     {rE   c                 6    t          | j        | j                  S )z4Returns the XMLRPC URI for current Fabric connection)r   r  r  r   s    rC   r  zFabricXMLRPCConnection.uriD  s     "$*dj999rE   c                    | j         r| j        S | j        }| j        }d}d}||k    rE|dz  }	 | j        j        r0t          st          d          t          | j        j                  }nd}t          | j        j
        | j        j        d|          }t          | j        |d          }|                                 n# t          $ r |cY S t           j        $ rl}||k    r"t          d                    |                    t&                              d                    | j        | j        |	                     Y d}~nd}~ww xY w|dk    rt/          j        |           ||k    CdS dS )
zReturn the XMLRPC server proxy instance to MySQL Fabric

        This method tries to get a valid connection to a MySQL Fabric
        server.

        Returns a XMLRPC ServerProxy instance.
        Nr   r   r   )r  r
  )	transportr  'Connection to MySQL Fabric failed ({0})*Retrying {host}:{port}, attempts {counter}r?   r@   counter)rJ  r  r*  r+  r  r   r   r   r   r   r  r	  r   r  _some_nonexisting_methodr   r|   rz   rM   r  r  r?   r@   timesleep)r=   r2   delayr   r  r
  r  r   s           rC   _xmlrpc_get_proxyz(FabricXMLRPCConnection._xmlrpc_get_proxyI  s     	;)#!!qLGJ<* )# L,-JKKK$6t|7N$O$OMM$(M+DL,A,0L,A45:GI I I	 $DH	1MMM..0000   < J J Jh&&(AHHMMO O O@GG!YTY H I IJ J J J J J J J	J qyy
5!!!7 !!!!!!s   BB? ?EEA"EEc                 8    |                                  | _        dS r  )r  r  r   s    rC   r;   zFabricXMLRPCConnection.connectv  s    ,,..rE   c                     	 | j                                          dS # t          $ r Y dS t          t          f$ r Y dS w xY w)r  FT)r  r  r   rZ  r   r   s    rC   rJ  z#FabricXMLRPCConnection.is_connectedz  sd    	K00222 5  	 	 	44>* 	 	 	55	s    
>>>)r   r   r   r   r%  r  r  rD   r  r   r  r  r;   rJ  r   r   s   @rC   r   r   2  s        MM*;H*E"21        X : : X:+" +" +"Z/ / /   X    rE   r   c                   n     e Zd ZdZed         eef fd	Zed             Z	d Z
d Zed             Z xZS )r9   zT
    Class holding a connection to a MySQL Fabric server through MySQL protocol
    r%   c                 p    t          t          |                               |||||           d| _        dS )r   )r@   rA   rB   N)r   r9   rD   _connectionr  s         rC   rD   zFabricMySQLConnection.__init__  sI     	#T**33Dt-] 	4 	
 	
 	
  rE   c                     | j         S )z*Returns the MySQL RPC Connection to Fabric)r  r   s    rC   rh   z FabricMySQLConnection.connection  s     rE   c                    | j         r| j        S | j        }| j        }d}||k    r|dz  }	 | j        | j        | j        j        | j        j        d}| j        j	        r@t          st          d          | j        j	        d         |d<   | j        j	        d         |d<   t          di |S # t          $ rl}||k    r"t          d	                    |                    t                              d
                    | j        | j        |                     Y d}~nd}~ww xY w|dk    rt'          j        |           ||k    dS dS )zReturn the connection instance to MySQL Fabric through MySQL RPC

        This method tries to get a valid connection to a MySQL Fabric
        server.

        Returns a MySQLConnection instance.
        r   r   )r?   r@   r4  r	  r   r,   r   r   r   r  r  r  Nr[   )rJ  r  r*  r+  r  r  r  r  r	  r   r   r   r   r   rM   r  r  r?   r@   r  r  )r=   r2   r  r  dbconfigr   s         rC   _get_connectionz%FabricMySQLConnection._get_connection  s     	$##)#!!qLGJ J J L1 $ 5	  <* K# L,-JKKK*.,*A%*HHY'+/<+B6+JHZ(&22222! J J Jh&&(AHHMMO O O@GG!YTY H I IJ J J J J J J J	J qyy
5!!!3 !!!!!!s   A<B) )
D3A"DDc                 8    |                                  | _        dS r  )r  r  r   s    rC   r;   zFabricMySQLConnection.connect  s    //11rE   c                 X    	 | j                                         S # t          $ r Y dS w xY w)r  F)r  rJ  r   r   s    rC   rJ  z"FabricMySQLConnection.is_connected  s>    	#00222 	 	 	55	s    
)))r   r   r   r   r%  r  r  rD   r  rh   r  r;   rJ  r   r   s   @rC   r9   r9     s          +<G*D"21                X )" )" )"V2 2 2   X    rE   r9   c                       e Zd ZdZd Zd Zed             Zed             ZddZ	d Z
d	 Zd
 Zd Zd Zd Zd ZeZddZd Zd Zd Zd Zd ZdS )MySQLFabricConnectionz1Connection to a MySQL server through MySQL Fabricc                     d| _         d| _        d| _        d| _        i | _        |                                  d|vrt          d          |r | j        di | dS dS )r   Nr>   z+Configuration parameters for Fabric missingr[   )
_mysql_cnxr  _fabric_mysql_server_mysql_config_cnx_propertiesreset_propertiesr   store_config)r=   rt   s     rC   rD   zMySQLFabricConnection.__init__  s    $(!!! 6!!JKKK 	(D'''''''	( 	(rE   c                     |                     d          r#t          d                    |                    t          | j        |          S )z7Return the return value of the MySQLConnection instancecmd_zHCalling {attr} is not supported for connections managed by MySQL Fabric.)attr)
startswithr   rM   r   r  )r=   r  s     rC   __getattr__z!MySQLFabricConnection.__getattr__  sP    ??6"" 	3#  &D 1 13 3 3 t---rE   c                 ,    | j         r| j         j        S dS )z+Returns the Fabric UUID of the MySQL serverN)r  r   r   s    rC   r   z!MySQLFabricConnection.fabric_uuid  s      $ 	2,11trE   c                     | j         S )zReturns connection properties)r  r   s    rC   
propertiesz MySQLFabricConnection.properties  s     ##rE   Nc                 f    |s| j         r| j         j        }| j                            |           dS )z'Reset cache for this connection's grouprC  N)r  r+   r  rH  rG  s     rC   rH  z!MySQLFabricConnection.reset_cache  s>     	42 	4-3E  u -----rE   c                     | j         duS )z\Check whether we are connected with the MySQL server

        Returns True or False
        N)r  r   s    rC   rJ  z"MySQLFabricConnection.is_connected  s    
 d**rE   c                 r    i | _         t                                          D ]\  }}|d         | j         |<   dS )zResets the connection properties

        This method can be called to reset the connection properties to
        their default values.
        r
   N)r  _CNX_PROPERTIESrH   )r=   r,   r  s      rC   r  z&MySQLFabricConnection.reset_properties  sI      "(..00 	0 	0IC(,QD %%	0 	0rE   c                 6   	 |                                   n# t          $ r Y nw xY w| j        }|                                D ]U\  }}|t          vr"t          d                    |                    |rut          |t          |         d                   sTd                    d t          |         d         D                       }t          d                    ||                    |dk    r!|r|d         s|d	         rt          d
          |dv r|r|d         rt          d          |dk    r|t          t          fvrt          d          |dk    r|t          t          fvrt          d          |t          |         d         ||<   P|||<   WdS )at  Set one or more connection properties

        Arguments to the set_property() method will be used as properties.
        They are validated against the _CNX_PROPERTIES constant.

        Raise ValueError in case an invalid property is being set. TypeError
        is raised when the type of the value is not correct.

        To unset a property, set it to None.
        zInvalid property connection {0}r   z or c                     g | ]	}|j         
S r[   )r   )r]   atypes     rC   r_   z6MySQLFabricConnection.set_property.<locals>.<listcomp>6  s    JJJU^JJJrE   z({name} is not valid, excepted {typename})nametypenamer+   r,   r-   z>'group' property can not be set when 'key' or 'tables' are set)r,   r-   z@'key' and 'tables' property can not be set together with 'group'r1   zInvalid value for 'scope'r.   zInvalid value for 'mode'Nr
   )closer   r  rH   r  r   rM   r   rr   rZ  r  SCOPE_GLOBALrp  MODE_READONLY)r=   r  propsr  rU   valid_types_strs         rC   set_propertyz"MySQLFabricConnection.set_property  s
   	JJLLLL 	 	 	D	 $%++-- 	$ 	$KD%?** 5<<TBBD D D >z%1Fq1IJJ >"(++JJ1Fq1IJJJ#L #L>EE!O F = => > > E5\  %*8_   '( ( ( ***u*w* 01 1 1 U;2M%M%M !<===E"M23 %3 %3 !;<<<}-d3A6d#d=	$ 	$s    
$$c                    t          |t                    r	|| _        dS dg}|D ])}||vr#t          d                    |                    *|d         }|                    dt                    }	 |                    dt          |                   }n0# t          $ r# t          d                    |                    w xY wt          ||          }	 t          |         | _        dS # t          $ rW t                              d           t          d	i || _        | j                                         | j        t          |<   Y dS w xY w)
zConfigure the Fabric connection

        The config argument can be either a dictionary containing the
        necessary information to setup the connection. Or config can
        be an instance of Fabric.
        r?   z8Missing configuration parameter '{parameter}' for fabric)	parameterr5  r@   z{0} protocol is not availablezNew Fabric connectionNr[   )r   r!  r  r   rM   getr  r%  r  r   r   FABRICSr  r  rA  )r=   configrequired_keysrequired_keyr?   r5  r@   rT  s           rC   _configure_fabricz'MySQLFabricConnection._configure_fabricP  s    ff%% 	4!DLLL#HM - E Ev--$%%+VlV%C%CE E E . &>Dzz*.EFFHFzz&*;H*EFF F F F$3::8DDF F FF .dD99K4&{3 4 4 45666%////!!###'+|$$$$4s   2!B -CC) )AE
	E
c                    |                                 }d|v r|                     |d                    |d= d|v rt                              d           d|d<   |                                 }d|v r|d= d|v r|d= d|v r|d= 	 t	          t          t          j                                        } |j        d
i | n4# t          $ r'}t          d	
                    |                    d}~ww xY w|| _        dS )a  Store configuration of MySQL connections to use with Fabric

        The configuration found in the dictionary kwargs is used
        when instanciating a MySQLConnection object. The host and port
        entries are used to connect to MySQL Fabric.

        Raises ValueError when the Fabric configuration parameter
        is not correct or missing; AttributeError is raised when
        when a paramater is not valid.
        r>   unix_socketz'MySQL Fabric does not use UNIX sockets.N	pool_name	pool_sizepool_reset_session)r  z'Connection configuration not valid: {0}r[   )copyr  r  warningr   rN   r   r\  
set_configr   rM   r  )r=   rt   r  test_configpoolrW   s         rC   r  z"MySQLFabricConnection.store_configq  sH     v""6(#3444x F""OOEFFF$(F=! kkmm+%%K(+%%K(;..01	G&TZ\\1B1BCCCDDO**k**** 	G 	G 	G 9@@EEG G G	G $s   ;C   
C1
"C,,C1c                    |                                  rdS | j        }|d         }|d         }| j                                        }d}||k    r4|dz  }	 d}|d         rZ|d         dk    r|d	         st	          d
          | j                            |d         |d	         |d         |d                   }nB|d         r+|d         }| j                            ||d                   }nt	          d          n# t          $ r}t          
                    d                    ||                     ||k    r"t          d                    |                    |dk    rAt          
                    d                    |                     t          j        |           Y d}~ad}~ww xY w|j        |d<   |j        |d<   	 t!          j        j        di || _        || _        dS # t*          $ r}||k    ra|                     |j                   | j                            |j        |j                   t          d                    |                    |dk    rt          j        |           Y d}~3d}~ww xY wdS )a  Get a MySQL server based on properties and connect

        This method gets a MySQL server from MySQL Fabric using already
        properties set using the set_property() method. You can specify how
        many times and the delay between trying using attempts and
        attempt_delay.

        Raises ValueError when there are problems with arguments or
        properties; InterfaceError on connectivity errors.
        Nr2   r3   r   r   r-   r1   r(   r,   z*Scope 'LOCAL' needs key property to be setr.   )r1   r.   r+   r  z*Missing group or key and tables propertiesz-Trying to get MySQL server (attempt {0}; {1})zError getting connection: {0}zWaiting {0}r?   r@   z&Reported faulty server to Fabric ({0})r[   )rJ  r  r  r  r   r  r  rv  r   r  r  rM   r  r  r?   r@   r%   rP   r;   r  r  r   rH  r+   rQ  r   rU  )	r=   r  r2   r3   r  r  r+   rk  r   s	            rC   _connectzMySQLFabricConnection._connect  s	     	F$$o.%**,,!!qLG? FW~00u0(HJ J J"&,"?"?hu#Gn"6] #@ #, #,KK 7^ F!'NE"&,"?"?E&M #@ #3 #3KK %DF F F! 
 
 
CJJ& &' ' ' h&&()H)O)O* *    1$$MM-"6"6}"E"EFFFJ}---
  +/HV*/HV"'/"9"E"EH"E"E -8)    h&&$$[%6777L//0@#)LLL(@GGLLN N N 1$$J}---I "!s3   B&C= =
F/BF**F/G+ +
J5BI<<Jc                     	 |                                   | j                                         n# t          $ r Y nt          $ r  w xY wd| _        d| _        dS # d| _        d| _        w xY w)z Close connection to MySQL serverN)rollbackr  r  r   r   r  r   s    rC   
disconnectz MySQLFabricConnection.disconnect  s    		-MMOOOO!!#### 	 	 	D 	 	 		 #DO(,D%%% #DO(,D%,,,,s$   -0 A 
AA AA A*c                 @   |                                   |rt          d          |rt          d          | j        du rt          d          |p| j        }|p| j        }d}|du r|dz  }|du r|dz  }t          t          t          t          f} ||         |           S )ai  Instantiates and returns a cursor

        This method is similar to MySQLConnection.cursor() except that
        it checks whether the connection is available and raises
        an InterfaceError when not.

        cursor_class argument is not supported and will raise a
        NotSupportedError exception.

        Returns a MySQLCursor or subclass.
        z.Custom cursors not supported with MySQL Fabricz7Prepared Statements are not supported with MySQL FabricTzUnread result found.r   r   r
   )
r
  r   _unread_resultr   	_buffered_rawr   r   r   r   )r=   bufferedrawpreparedcursor_classcursor_typetypess          rC   ri   zMySQLFabricConnection.cursor  s     	 	B#@B B B  	K#IK K K $&& 6777-t~TYt1K$;;1K "	
 #k"D)))rE   c                     |j         t          v rX|                                  |                                  t	          d                    t          |                              |)zHandles MySQL errors

        This method takes a mysql.connector.errors.Error exception
        and checks the error code. Based on the value, it takes
        certain actions such as clearing the cache.
        z,Temporary error ({error}); retry transactionr{  )rU  RESET_CACHE_ON_ERRORrH  r  r   rM   rN   r=   r   s     rC   handle_mysql_errorz(MySQLFabricConnection.handle_mysql_error  sg     9,,,OO"$$*FSF$:$:< < < 	rE   c                     	 | j                                          dS # t          $ r }|                     |           Y d}~dS d}~ww xY w)zCommit current transaction

        Raises whatever MySQLConnection.commit() raises, but
        raises MySQLFabricError when MySQL returns error
        ER_OPTION_PREVENTS_STATEMENT.
        N)r  commitr   r  r  s     rC   r  zMySQLFabricConnection.commit#  sf    	)O""$$$$$ 	) 	) 	)##C(((((((((	)    
AAAc                     	 | j                                          dS # t          $ r }|                     |           Y d}~dS d}~ww xY w)zRollback current transaction

        Raises whatever MySQLConnection.rollback() raises, but
        raises MySQLFabricError when MySQL returns error
        ER_OPTION_PREVENTS_STATEMENT.
        N)r  r  r   r  r  s     rC   r  zMySQLFabricConnection.rollback/  sf    	)O$$&&&&& 	) 	) 	)##C(((((((((	)r  c                     |                                   	 | j                            |          S # t          $ r }|                     |           Y d}~dS d}~ww xY w)zSend a statement to the MySQL server

        Raises whatever MySQLConnection.cmd_query() raises, but
        raises MySQLFabricError when MySQL returns error
        ER_OPTION_PREVENTS_STATEMENT.

        Returns a dictionary.
        N)r
  r  	cmd_queryr   r  )r=   	statementr   s      rC   r!  zMySQLFabricConnection.cmd_query;  sq     		)?,,Y777 	) 	) 	)##C(((((((((	)   0 
AAAc                     |                                   	 | j                            |          S # t          $ r }|                     |           Y d}~dS d}~ww xY w)zSend one or more statements to the MySQL server

        Raises whatever MySQLConnection.cmd_query_iter() raises, but
        raises MySQLFabricError when MySQL returns error
        ER_OPTION_PREVENTS_STATEMENT.

        Returns a dictionary.
        N)r
  r  cmd_query_iterr   r  )r=   
statementsr   s      rC   r%  z$MySQLFabricConnection.cmd_query_iterJ  sq     		)?11*=== 	) 	) 	)##C(((((((((	)r#  r7   )NNNN)r   r   r   r   rD   r  r  r   r  rH  rJ  r  r  r  r  r
  r  r  ri   r  r  r  r!  r%  r[   rE   rC   r  r    sY       ;;( ( ( . . .   X $ $ X$. . . .+ + +0 0 01$ 1$ 1$f4 4 4B%$ %$ %$NB B BH- - - E'* '* '* '*R   
) 
) 
)
) 
) 
)) ) )) ) ) ) )rE   r  )rr   sysr  r  r   base64r   r   hashlibr   loggingr|   r   	xmlrpclibr   r   r   r   httplibr	   ImportErrorxmlrpc.clienturllib.requestr  http.clientversion_infor   r   mysql.connectorr%   rh   r   
conversionr   poolingr   rQ   r   r   r   r   r   r   ri   r   r   r   r   r*   r   r   r   cachingr   	balancingr   r    catch23r!   r"   r#   CR_SERVER_LOSTER_OPTION_PREVENTS_STATEMENTr  CR_SERVER_GONE_ERRORCR_CONN_HOST_ERRORCR_CONNECTION_ERRORCR_IPSOCK_ERRORrS  r   r  r%  r  r  r  _GETCNX_ATTEMPT_DELAY_GETCNX_ATTEMPT_MAXr  ro  rp  STATUS_FAULTYSTATUS_SPARErg  rn  r  r  _SERVER_STATUS_FAULTYrN   rc   r   r  rG   r  	getLoggerr  objectr5   r   r   r{   r   r   r   r   r   r   r   r   r   r!  r  r   r9   r  r[   rE   rC   <module>rE     sb  0 3 2 



                           *7777777777NNN%%%%%%% * * *;;;;;;;;;;$$$$$$))))))))	* A!++++++     
//////          ( ( ( ( ( ( ' ' ' ' ' ' ) ) ) ) ) )                                 , , , , , , , ,             ) ) ) ) ) )       3 3 3 3 3 3 3 3 3 3 *  " !  "    
          f0$7E3X.="$(D$7$78 9 9D" t}7>V:NKfCTJD!fC:$&fD+- $ '
-
.
.Y Y Y Y Yv Y Y Yx         V      F" " " " "& " " "3 3 3 3 3( 3 3 3B    V   2 2  2  2  2  2  2  2  2F) ) )4? ? ?J J J
  4      W1   2KM KM KM KM KMi KM KM KM\L= L= L= L= L=V L= L= L=^3
 3
 3
 3
 3
v 3
 3
 3
lX X X X X- X X XvN N N N N, N N Nby) y) y) y) y)F y) y) y) y) y)s5   A A%$A%:B BBB B$#B$