a
    còf+  ã                   @   s|  d Z zddlZddlmZ W n ey2   dZY n0 dZzddlZddlZW n eyb   dZ	Y n0 d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mZmZmZmZmZmZmZmZmZmZmZmZ ddlmZm Z m!Z!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5 i Z6dZ7dd„ Z8dd„ Z9dd„ Z:e:Z;ej<Z=ej>Z?g d¢Z@dS )z9
MySQL Connector/Python - MySQL driver written in Python
é    Né   )ÚCMySQLConnectionFT)Úversion)ÚMySQLConnection)ÚDEFAULT_CONFIGURATION)ÚErrorÚWarningÚInterfaceErrorÚDatabaseErrorÚNotSupportedErrorÚ	DataErrorÚIntegrityErrorÚProgrammingErrorÚOperationalErrorÚInternalErrorÚcustom_error_exceptionÚ	PoolError)Ú	FieldFlagÚ	FieldTypeÚCharacterSetÚRefreshOptionÚ
ClientFlag)ÚDateÚTimeÚ	TimestampÚBinaryÚDateFromTicksÚTimestampFromTicksÚTimeFromTicksÚSTRINGÚBINARYÚNUMBERÚDATETIMEÚROWIDÚapilevelÚthreadsafetyÚ
paramstyle)Úread_option_filesz0MySQL Connector/Python C Extension not availablec                  K   s  ddl m}m}m} z| d }W n  ty@   |f i | ¤Ž}Y n0 d| v r^| d s^ts^ttƒ‚|�` |tvr€|f i | ¤Žt|< n4t	t| |ƒr´t| j
}d| v r´| d |kr´tdƒ‚W d  ƒ n1 sÈ0    Y  zt|  ¡ W S  t�y   td |¡ƒ‚Y n0 dS )	z Return a pooled MySQL connectionr   )ÚMySQLConnectionPoolÚgenerate_pool_nameÚCONNECTION_POOL_LOCKÚ	pool_nameÚuse_pureÚ	pool_sizez)Size can not be changed for active pools.Nz)Failed getting connection from pool '{0}')Zpoolingr(   r)   r*   ÚKeyErrorÚ	HAVE_CEXTÚImportErrorÚERROR_NO_CEXTÚ_CONNECTION_POOLSÚ
isinstancer-   r   Úget_connectionÚAttributeErrorr	   Úformat)Úkwargsr(   r)   r*   r+   Z
check_size© r8   úU/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/mysql/connector/__init__.pyÚ_get_pooled_connectionJ   s.    

ÿ&ÿr:   c               
   K   s$  |   ¡ }z|d }W n ty.   tdƒ‚Y n0 |d= tg d¢ƒ}d}|D ]ª}t| ¡ ƒ| }|rˆtd t|ƒdkrxdndd	 |¡¡ƒ‚t|d
ƒrš|d7 }| 	d
d¡|d
< |d
 dk sÂ|d
 dkrÔt
d |d
 ¡ƒ‚t|d
 tƒsJt
d |d
 ¡ƒ‚qJd|  k �rt|ƒk �rn ntdƒ‚|jdd„ dd� i }g }|D ]D}|d
 |v�rl|g||d
 < | |d
 ¡ n||d
   |¡ �q<|D ]�}	||	 }
tt|
ƒƒD ]t}t|
ƒd }t d|¡}|
 |¡}|  ¡ }| |¡ | d
d¡ ztf i |¤ŽW     S  t�y   Y n0 �qž�q†t
dƒ‚dS )a©  Return a MySQL connection and try to failover if needed

    An InterfaceError is raise when no MySQL is available. ValueError is
    raised when the failover server configuration contains an illegal
    connection argument. Supported arguments are user, password, host, port,
    unix_socket and database. ValueError is also raised when the failover
    argument was not provided.

    Returns MySQLConnection instance.
    Úfailoverzfailover argument not provided)	ÚuserÚpasswordÚhostÚportÚunix_socketZdatabaser+   r-   Úpriorityr   z4Unsupported connection argument {0} in failover: {1}r   ÚsÚ z, rA   éd   z;Priority value should be in the range of 0 to 100, got : {}zFPriority value should be an integer in the range of 0 to 100, got : {}z\You must either assign no priority to any of the routers or give a priority for every routerc                 S   s   | d S )NrA   r8   ©Úxr8   r8   r9   Ú<lambda>Ÿ   ó    z*_get_failover_connection.<locals>.<lambda>T)ÚkeyÚreverseNz,Unable to connect to any of the target hosts)Úcopyr.   Ú
ValueErrorÚsetÚkeysr6   ÚlenÚjoinÚhasattrÚgetr	   r3   Úintr   ÚsortÚappendÚrangeÚrandomÚrandintÚpopÚupdateÚconnectr   )r7   Úconfigr;   Zsupport_cnx_argsZpriority_countÚserverÚdiffZserver_directoryZserver_priority_listrA   Zfailover_listÚ_ÚlastÚindexÚ
new_configr8   r8   r9   Ú_get_failover_connectionn   st    ÿþÿ
ÿÿÿÿ 

rc   c            	         s  dˆ v rˆ   d¡nd}t|tƒs(tdƒ‚|�rts:tdƒ‚dˆ v rJtdƒ‚dˆ v rZtdƒ‚d	ˆ v rjtd
ƒ‚dˆ vr~td ˆ d< ztj ˆ d d¡}W n( tj	j
y¼   td ˆ d ¡ƒ‚Y n0 g }|D ](}| |jjdd�|j|j|jdœ¡ qÆ|jdd„ d� dd„ |D ƒˆ d	< dˆ v �r2ˆ d ˆ d< ˆ   d¡ dˆ v �rXtf i ˆ ¤Ž}tf i |¤ŽS d	ˆ v �rptf i ˆ ¤ŽS z8ddlm} t‡ fdd„|D ƒƒ�r¦tf i ˆ ¤ŽW S W n t�y¼   Y n0 ˆ  dd¡}dˆ v �rîˆ d= |�sît�sîttƒ‚t�r|�st| i ˆ ¤ŽS t | i ˆ ¤ŽS )aŽ  Create or get a MySQL connection object

    In its simpliest form, Connect() will open a connection to a
    MySQL server and return a MySQLConnection object.

    When any connection pooling arguments are given, for example pool_name
    or pool_size, a pool is created or a previously one is used to return
    a PooledMySQLConnection.

    Returns MySQLConnection or PooledMySQLConnection.
    Údns_srvFz(The value of 'dns-srv' must be a booleanztMySQL host configuration requested DNS SRV. This requires the Python dnspython module. Please refer to documentationr@   z<Using Unix domain sockets with DNS SRV lookup is not allowedr?   z;Specifying a port number with DNS SRV lookup is not allowedr;   zASpecifying multiple hostnames with DNS SRV look up is not allowedr>   ZSRVz$Unable to locate any hosts for '{0}'T)Zomit_final_dot)r>   r?   rA   Úweightc                 S   s   | d | d  fS )NrA   re   r8   rE   r8   r8   r9   rG   î   rH   zconnect.<locals>.<lambda>)rI   c                 S   s   g | ]}|d  |d dœ‘qS )r>   r?   )r>   r?   r8   )Ú.0Úsrvr8   r8   r9   Ú
<listcomp>ï   s   ÿÿzconnect.<locals>.<listcomp>Zread_default_fileZoption_filesr   )ÚCNX_POOL_ARGSc                    s   g | ]}|ˆ v ‘qS r8   r8   )rf   rI   ©r7   r8   r9   rh     rH   r,   )!rY   r3   Úboolr	   ÚHAVE_DNSPYTHONr   ÚdnsÚresolverÚqueryÚ	exceptionZDNSExceptionr6   rU   ÚtargetZto_textr?   rA   re   rT   r'   r[   rc   Ú	constantsri   Úanyr:   Ú	NameErrorrR   r/   r0   r1   r   r   )	Úargsr7   rd   Zsrv_recordsr;   rg   rb   ri   r,   r8   rj   r9   r[   ¼   sl    
ÿü
ÿ





r[   )%r   ÚConnectr   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   )AÚ__doc__Z_mysql_connectorZconnection_cextr   r0   r/   Zdns.resolverrm   Zdns.exceptionrl   rW   ÚwarningsrC   r   Ú
connectionr   rr   r   Úerrorsr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   Zdbapir   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   Zoptionfilesr'   r2   r1   r:   rc   r[   rv   ÚVERSIONÚ__version_info__ZVERSION_TEXTÚ__version__Ú__all__r8   r8   r8   r9   Ú<module>   s<   

8D$NV