U
    e~                  	   @  s  U d Z ddlmZ ddlZddlZddlZddlZddlmZm	Z	 ddl
mZm
Z
mZmZ ddlmZ ddlmZ 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Z"z ddl#Z#e$e#dre#j%rdZ"W n e&k
r   Y nX ddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7m8Z8 ddl9m:Z: ddlm;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA eB ZCdeDd< dZEdZFdZGdZHdZIeeJee
eKeLeMeef	ZNG dd deZOG dd deZPdS )z+Module gathering all abstract base classes.    )annotationsN)ABCabstractmethod)datedatetimetime	timedelta)Decimal)	signature)sleep)TracebackType)AnyBinaryIOCallableDict	GeneratorListMappingOptionalSequenceTupleTypeUnionFHAS_TLSv1_3T   )CONN_ATTRS_DNDEFAULT_CONFIGURATIONDEPRECATED_TLS_VERSIONSOPENSSL_CS_NAMESTLS_CIPHER_SUITESTLS_VERSIONSCharacterSet
ClientFlag)MySQLConverterMySQLConverterBase)ErrorInterfaceErrorNotSupportedErrorOperationalErrorProgrammingError)read_option_files)ConnAttrsTypeDescriptionTypeHandShakeTypeQueryAttrType
StrOrBytes!SupportedMysqlBinaryProtocolTypesWarningTypez%weakref.WeakValueDictionary[Any, Any]NAMED_TUPLE_CACHEzVThe '{list}' list must not contain repeated values, the value '{value}' is duplicated.zdThe given tls_version: '{}' is not recognized as a valid TLS protocol version (should be one of {}).zHThe given tls_version: '{}' are no longer allowed (should be one of {}).zINo supported TLS protocol version found in the 'tls-versions' list '{}'. a  Option "krb_service_principal" {error}, must be a string in the form "primary/instance@realm" e.g "ldap/ldapauth@MYSQL.COM" where "@realm" is optional and if it is not given will be assumed to belong to the default realm, as configured in the krb5.conf file.c                   @  s
  e Zd ZU dZddddZd dddZdd	d
ddddZd dddZeddddZ	eddddZ
eddddZdddddZddddZddddZddd d!Zed"dd#d$Zed"dd%d&Zed'dd(d)Zed*dd+d,Zeed"dd-d.Zejd"ddd/d.Zeddd0d1Zejdddd2d1Zed3dd4d5Zejd3ddd6d5Zd3dd7d8d9Zd3dd:d;Zed<d=d>d?d@Zd=ddAdBZd*ddCdDZeed3ddEdFZdGd'dHdIdJZ d'ddKdLdMZ!ed"ddNdOZ"e"jd"dddPdOZ"ed"ddQdRZ#e#jdSdddTdRZ#ed3d3dUdVdWZ$dd*d*ddYdZd[Z%ddddd]d^Z&eddd_d`Z'e'jddddad`Z'edddbdcZ(e(jddddddcZ(edddedfZ)e)jddddgdfZ)edddhdiZ*e*jddddjdiZ*ed"ddkdlZ+ed"ddmdnZ,ddod*ddpdqdrZ-ed"ddsdtZ.ed3ddudvZ/ed3ddwdxZ0dddydzZ1ed3dd{d|Z2e2Z3d}e4d~< d3dd7ddZ5dd'd'ddddZ6ed3dddZ7eddd'd'd3dddZ8ed3dddZ9edddddddddddZ:ed3d3dUddZ;ed3dddZ<ddd*dddddZ=dddddddZ>dddddZ?edddddd3ddddZ@d"ddddZAdd3dddddddZBd3ddddZCd'ddddZDd3dddZEddddddZFddddZGed3dddZHd'ddddZIddddĄZJddddƄZKdd"d"d"d'd"d"d"d"ddɜ	dd˄ZLd3dd̜dd΄ZMdd3ddd'd3dќddӄZNd3d3dԜddքZOd3d'dd3d؜ddڄZPd3d3dԜdd܄ZQd3dddބZRdXS )MySQLConnectionAbstractz7Abstract class for classes connecting to a MySQL serverNonereturnc                 C  s8  t  | _d| _d| _d| _d| _d| _d| _i | _	d| _
d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _i | _td | _d| _d| _d| _d| _d	| _d| _d| _td
 | _d| _ d| _!d| _"d| _#d| _$td | _%td | _&d| _'g | _(d| _)d| _*d| _+d| _,d| _-d| _.d| _/d| _0d| _1d| _2dS )Z
Initialize-   NF z	127.0.0.1i  r   ssl_disabledTconnect_timeoutallow_local_infileallow_local_infile_in_path)3r"   get_default_client_flags_charset_id	_sql_mode
_time_zone_autocommit_server_version
_handshake_conn_attrs_user	_passwordZ
_password1Z
_password2Z
_password3	_database_host_port_unix_socketZ_client_hostZ_client_port_sslr   _ssl_disabledZ_force_ipv6Z_oci_config_file_fido_callback_krb_service_principal_use_unicode_get_warnings_raise_on_warningsZ_connection_timeoutZ	_buffered_unread_result_have_next_result_rawZ_in_transaction_allow_local_infile_allow_local_infile_in_pathZ_prepared_statements_query_attrs_ssl_active_auth_plugin_auth_plugin_class_pool_config_version	converter_converter_class_converter_str_fallback	_compress_consume_results_init_commandself re   Z/var/www/html/assets/scripts/venv/lib/python3.8/site-packages/mysql/connector/abstracts.py__init__   sh    


z MySQLConnectionAbstract.__init__c                 C  s   | S Nre   rc   re   re   rf   	__enter__   s    z!MySQLConnectionAbstract.__enter__Type[BaseException]BaseExceptionr   exc_type	exc_value	tracebackr6   c                 C  s   |    d S rh   closerd   rm   rn   ro   re   re   rf   __exit__   s    z MySQLConnectionAbstract.__exit__c                 C  s   | S )zReturn self for weakref.proxy

        This method is used when the original object is needed when using
        weakref.proxy.
        re   rc   re   re   rf   get_self   s    z MySQLConnectionAbstract.get_selfboolc                 C  s   | j p| jdk	otjdkS )z&Return True if is a secure connection.Nposix)rY   rK   osnamerc   re   re   rf   	is_secure   s    z!MySQLConnectionAbstract.is_securec                 C  s   | j S )zReturn if have next result.)rT   rc   re   re   rf   have_next_result   s    z(MySQLConnectionAbstract.have_next_resultr.   c                 C  s   | j S )zReturn query attributes list.rX   rc   re   re   rf   query_attrs   s    z#MySQLConnectionAbstract.query_attrsz-Tuple[str, SupportedMysqlBinaryProtocolTypes])valuer6   c                 C  s   | j | dS )z)Add element to the query attributes list.N)rX   appendrd   r}   re   re   rf   query_attrs_append   s    z*MySQLConnectionAbstract.query_attrs_appendc                 C  s   | j dd= dS )zClear query attributes list.Nr{   rc   re   re   rf   query_attrs_clear   s    z)MySQLConnectionAbstract.query_attrs_clearc                 C  s@  g }| j d }t|tr|dr,|ds<td| d|dd d}|sZtd	|D ]}|  }|r^|	| q^n.t|t
tfrd
d |D }ntd| d| j dddkrtdd n| j d dd }|jdd |d }g g g}i }g }	tdt|d  D ]"}
|t|
  |	t|
  q|D ]}d|kr||	kr|td krv|d 	| n|d 	| nt||kr|| }||krttjd|d|td kr|d 	||  n|d 	||  ntd| dq@|d s|d stdd|d d|d g| j d< dS )z&Validates the tls_ciphersuites option.tls_ciphersuites[]z)tls_ciphersuites must be a list, found: ''r   ,z6No valid cipher suite found in 'tls_ciphersuites' listc                 S  s   g | ]}|r|qS re   re   ).0tls_csre   re   rf   
<listcomp>  s      zFMySQLConnectionAbstract._validate_tls_ciphersuites.<locals>.<listcomp>zItls_ciphersuites should be a list with one or more ciphersuites. Found: 'tls_versionsNT)reverser   -TLSv1.3listr}   zThe value 'z1' in tls_ciphersuites is not a valid cipher suitez:No valid cipher suite found in the 'tls_ciphersuites' list:)rL   
isinstancestr
startswithendswithAttributeErrorsplitstripupperr~   r   setgetr    sortindexupdater   extendr   DUPLICATED_IN_LIST_ERRORformatjoin)rd   r   r   Ztls_cssZ_tls_csr   Znewer_tls_verZtranslated_namesZiani_cipher_suites_namesZossl_cipher_suites_namestls_verrx   Ztranslated_namere   re   rf   _validate_tls_ciphersuites   sx    





 
z2MySQLConnectionAbstract._validate_tls_ciphersuitesc                 C  s  g }| j d }t|tr|dr,|ds<td| d|dd d}|D ]:}| }|d	krhqR||krttj	d|d
|
| qR|dgkrtstt	|tnt|tr|std|D ](}||krttj	d|d
|
| qn@t|tr|D ]}|
| qntddt d| d|sBtdg }g }g }|D ]:}|tkrj|
| |tkr|
| n
|
| qR|r|dgkrtstt	|t|  || j d< n.|rtt	|tn|rtt	|tdS )z"Validates the tls_versions option.r   r   r   z%tls_versions must be a list, found: 'r   r   r   r   r8   r   r   zJAt least one TLS protocol version must be specified in 'tls_versions' listz>tls_versions should be a list with one or more of versions in z, z
. found: 'zdAt least one TLS protocol version must be specified in 'tls_versions' list when this option is givenN)rL   r   r   r   r   r   r   r   r   r   r~   TLS_V1_3_SUPPORTEDTLS_VER_NO_SUPPORTEDr    r   r   r   r   r'   r   TLS_VERSION_DEPRECATED_ERRORTLS_VERSION_ERROR)rd   r   Ztls_versionZtls_versr   Zuse_tls_versionsZdeprecated_tls_versionsZinvalid_tls_versionsre   re   rf   _validate_tls_versionsL  s    


 

 



 z.MySQLConnectionAbstract._validate_tls_versionsr   c                 C  s   | j S )z#User used while connecting to MySQL)rF   rc   re   re   rf   user  s    zMySQLConnectionAbstract.userc                 C  s   | j S )zMySQL server IP address or name)rI   rc   re   re   rf   server_host  s    z#MySQLConnectionAbstract.server_hostintc                 C  s   | j S )zMySQL server TCP/IP port)rJ   rc   re   re   rf   server_port  s    z#MySQLConnectionAbstract.server_portzOptional[str]c                 C  s   | j S )zMySQL Unix socket file location)rK   rc   re   re   rf   unix_socket  s    z#MySQLConnectionAbstract.unix_socketc                 C  s   dS )zGet the current databaseNre   rc   re   re   rf   database  s    z MySQLConnectionAbstract.databasec                 C  s   |  d|  dS )zSet the current databasezUSE N)	cmd_queryr   re   re   rf   r     s    c                 C  s   | j S )z"Returns whether to consume results)ra   rc   re   re   rf   can_consume_results  s    z+MySQLConnectionAbstract.can_consume_resultsc                 C  s   t |tst|| _dS )zSet if can consume results.N)r   ru   AssertionErrorra   r   re   re   rf   r     s    r   c                 C  s   | j S )z%Return the pool configuration versionr\   rc   re   re   rf   pool_config_version  s    z+MySQLConnectionAbstract.pool_config_versionc                 C  s
   || _ dS )z"Set the pool configuration versionNr   r   re   re   rf   r     s    )kwargsr6   c              
   K  s\	  |  }d|krtdtf |}z|d | _|d= W n tk
rJ   Y nX z|d | _|d= W n tk
rt   Y nX z$t }| |d p| |d= W n tk
r   Y nX z |d rd| _	| tj
g W n tk
r   Y nX |dtd | _|d	td	 | _d
}| jr\tj| j}|rFtj|rFtj|rTtj|r\td| jsl| jr|| tjg n| tj g z|d sd| _nd| _W n tk
r   d| _Y nX z|d | _|d= W n tk
r   d| _Y nX d|ksd|krzz|d }|d= W n tk
r8   d
}Y nX z|d }|d= W n tk
rf   d
}Y nX t||d | _z| |d  W nB tk
r   Y n. tk
r } ztd|W 5 d
}~X Y nX dddddg}|D ]B\}	}
z |
|kr||	 ||
< ||	= W n tk
r    Y nX qd|ks:d|krz|d }|d= W n tk
rh   | j}Y nX z|d }|d= W n tk
r   | j}Y nX |  || d|kr|d r|d | _!zt"|d | _#|d= W nB tk
r   Y n. t$k
r } zt%d|W 5 d
}~X Y nX d|kr6|&d| _'d |krP|d  | _(|d = d}|) D ]\}}zt|  W n( tk
r   td!| d"d
Y nX |*d#rd}| j+,|-d#d|i nb|*d$rd}| j+,||i n@d%| }zt.| ||/  W n" tk
r$   t.| || Y nX q\| j0rDtj1d&krDd| _'| j'r`| jd'kr`t%d(|r~d)| j+krtd* | j+d)< d+| j+krtd, | j+d+< d-| j+ks| j+d- d
krd| j+d-< t2d.| j+kt2d/| j+kkrtd0t3d1t3| j+ksd
| j+d.< d
| j+d/< n&| j+d. d
k| j+d/ d
kkr6td2d3| j+krZ| j+d3 d
k	rZ| 4  d4| j+kr~| j+d4 d
k	r~| 5  | j6d
kri | _6nt7| j6t8st%d5n| j6) D ]\}}|t9krʐqt7|t:st%d6| d7| j6 d"t;|d8krt%d9| d:|*d%r t%d;t7|t:sBt%d<| d=| d>t;|d?krt%d<| d=| d@q| j<tj=@ r| >  dA|kr|dA d
k	rt7|dA t:st%dB|dA ? }|dCkrtj1dDkrt%dEdF| _@n|dGkrdH| _@nt%dIdJ|krt|dJ d
k	rt|dJ | _At7| jAt:s<t%tBjCdKdL| jAdkrXt%tBjCdMdLdN| jAkrtt%tBjCdOdL| jD	rXt7| jDt:	rz| jDEdPdQ\}}W n* t$k
r   tFdR| jD d"d
Y nX ztGH|}tI||| _DW n4 ttJfk
	r } ztF| |W 5 d
}~X Y nX tK| jD	s0tFdSt;tL| jDjM}|dQk	rXtFdT| d
S )UzConfigure the MySQL Connection

        This method allows you to configure the MySQLConnection instance.

        Raises on errors.
        Zdsnz!Data source name is not supportedget_warningsraise_on_warningsZclient_flagscompressTr;   r<   Nz.allow_local_infile_in_path must be a directoryZconsume_resultsFZauth_pluginr8   charset	collationr   Zconverter_classzEConverter class should be a subclass of conversion.MySQLConverterBase)dbr   )usernamer   )passwdpassword)r:   Zconnection_timeout)Zread_default_fileZoption_filesr   r   hostportz'TCP/IP port number should be an integerr9   Zinit_commandzUnsupported argument 'r   ssl_Ztls__rv   Zmysql_clear_passwordzEClear password authentication is not supported over insecure channelsZverify_certZssl_verify_certZverify_identityZssl_verify_identitycakeycertz:ssl_key and ssl_cert need to be both specified, or neither)r   r   z4ssl_key and ssl_cert need to be both set, or neitherr   r   zconn_attrs must be of type dictz+Attribute name should be a string, found: 'z' in '    zAttribute name 'z"' exceeds 32 characters limit sizezNKey names in connection attributes cannot start with '_', found: '{attr_name}'zAttribute 'z
' value: 'z' must be a string typei   z$' exceeds 1024 characters limit sizekerberos_auth_modez('kerberos_auth_mode' must be of type strZsspintz6'kerberos_auth_mode=SSPI' is only available on WindowsZMySQLSSPIKerberosAuthPluginZgssapiZMySQLKerberosAuthPluginz@Invalid 'kerberos_auth_mode' mode. Please use 'SSPI' or 'GSSAPI'Zkrb_service_principalzis not a string)errorzcan not be an empty string/zis incorrectly formatted.r   zNo callable named 'z'Expected a callable for 'fido_callback'zN'fido_callback' requires 1 positional argument, but the callback provided has )Ncopyr'   r*   r   KeyErrorr   r"   r=   set_client_flagsr`   ZCOMPRESSr   r   rV   rW   rw   pathabspathexistsisdirislinkr   ZLOCAL_FILESra   rZ   r!   get_charset_infor?   set_converter_class	TypeErrorrF   rG   	set_loginrI   r   rJ   
ValueErrorr&   poprM   rb   itemsr   rL   r   replacesetattrr   rK   rx   ru   r   r   r   rE   r   dictr   r   lenr>   ZCONNECT_ARGS_add_default_conn_attrslowerr[   rO   KRB_SERVICE_PINCIPAL_ERRORr   rN   rsplitr)   	importlibimport_modulegetattrModuleNotFoundErrorcallabler
   
parameters)rd   r   configdefaultZinfile_in_pathr   r   errZ
compat_mapcompat	translater   r   Zset_ssl_flagr   r}   	attribute	attr_nameZ
attr_valuer   modulecallbackparamsre   re   rf   r     s    





 


































zMySQLConnectionAbstract.configc                 C  s   dS )z&Add the default connection attributes.Nre   rc   re   re   rf   r     s    z/MySQLConnectionAbstract._add_default_conn_attrsr/   zTuple[int, ...])server_versionr6   c                 C  sp   t | ttfr|  } td}|| }|s6tdtdd |	 dd D }|dk rltd|  d	|S )
a7  Check the MySQL version

        This method will check the MySQL version and raise an InterfaceError
        when it is not supported or invalid. It will return the version
        as a tuple with major, minor and patch.

        Raises InterfaceError if invalid server version.

        Returns tuple
        z$^(\d{1,2})\.(\d{1,2})\.(\d{1,3})(.*)zFailed parsing MySQL versionc                 s  s   | ]}t |V  qd S rh   )r   )r   vre   re   rf   	<genexpr>'  s     z@MySQLConnectionAbstract._check_server_version.<locals>.<genexpr>r      )   r   zMySQL Version 'z' is not supported)
r   	bytearraybytesdecoderecompilematchr&   tuplegroups)r   Z	regex_verr   versionre   re   rf   _check_server_version  s    

z-MySQLConnectionAbstract._check_server_versionc                 C  s   | j S )zGet the MySQL version

        This method returns the MySQL server version as a tuple. If not
        previously connected, it will return None.

        Returns a tuple or None.
        )rC   rc   re   re   rf   get_server_version-  s    z*MySQLConnectionAbstract.get_server_versionc              	   C  s,   z| j d W S  ttfk
r&   Y dS X dS )zGet the original MySQL version information

        This method returns the original MySQL server as text. If not
        previously connected, it will return None.

        Returns a string or None.
        Zserver_version_originalN)rD   r   r   rc   re   re   rf   get_server_info7  s    z'MySQLConnectionAbstract.get_server_infoc                 C  s   dS )z'MySQL session has started a transactionNre   rc   re   re   rf   in_transactionD  s    z&MySQLConnectionAbstract.in_transactionzUnion[int, Sequence[int]])flagsr6   c                 C  sn   t |tr|dkr|| _nNt |ttfr`|D ]0}|dk rN|  jt| M  _q,|  j|O  _q,ntd| jS )a   Set the client flags

        The flags-argument can be either an int or a list (or tuple) of
        ClientFlag-values. If it is an integer, it will set client_flags
        to flags as is.
        If flags is a list (or tuple), each flag will be set or unset
        when it's negative.

        set_client_flags([ClientFlag.FOUND_ROWS,-ClientFlag.LONG_FLAG])

        Raises ProgrammingError when the flags argument is not a set or
        an integer bigger than 0.

        Returns self.client_flags
        r   z+set_client_flags expect integer (>0) or set)r   r   r>   r   r   absr)   )rd   r  flagre   re   rf   r   I  s    z(MySQLConnectionAbstract.set_client_flags)r  r6   c                 C  s   | j |@ dkrdS dS )zCheck if a client flag is setr   TF)r>   )rd   r  re   re   rf   isset_client_flage  s    z)MySQLConnectionAbstract.isset_client_flagc                 C  s   |  dd S )zGet the current time zonezSELECT @@session.time_zoner   
info_queryrc   re   re   rf   	time_zonek  s    z!MySQLConnectionAbstract.time_zonec                 C  s   |  d| d || _dS )zSet the time zonezSET @@session.time_zone = 'r   N)r   rA   r   re   re   rf   r  p  s    c                 C  s   |  dd S )zGet the SQL modezSELECT @@session.sql_moder   r	  rc   re   re   rf   sql_modev  s    z MySQLConnectionAbstract.sql_modezUnion[str, Sequence[int]]c                 C  s4   t |ttfrd|}| d| d || _dS )a  Set the SQL mode

        This method sets the SQL Mode for the current connection. The value
        argument can be either a string with comma separate mode names, or
        a sequence of mode names.

        It is good practice to use the constants class SQLMode:
          from mysql.connector.constants import SQLMode
          cnx.sql_mode = [SQLMode.NO_ZERO_DATE, SQLMode.REAL_AS_FLOAT]
        r   zSET @@session.sql_mode = 'r   N)r   r   r   r   r   r@   r   re   re   rf   r  {  s    
)queryr6   c                 C  s   dS )z%Send a query which only returns 1 rowNre   rd   r  re   re   rf   r
    s    z"MySQLConnectionAbstract.info_queryN)r   r   r6   c                 C  s4   |dk	r|  | _nd| _|dk	r*|| _nd| _dS )zSet login information for MySQL

        Set the username and/or password for the user connecting to
        the MySQL Server.
        Nr8   )r   rF   rG   )rd   r   r   re   re   rf   r     s    z!MySQLConnectionAbstract.set_loginTc                 C  s   || _ | jr| j| dS )zuToggle unicode mode

        Set whether we return string fields as unicode or not.
        Default is True.
        N)rP   r]   set_unicoder   re   re   rf   r    s    z#MySQLConnectionAbstract.set_unicodec                 C  s   |  dd }|dkS )z#Get whether autocommit is on or offzSELECT @@session.autocommitr   r   r	  r   re   re   rf   
autocommit  s    z"MySQLConnectionAbstract.autocommitc                 C  s&   |rdnd}|  d|  || _dS )zToggle autocommitONZOFFzSET @@session.autocommit = N)r   rB   )rd   r}   switchre   re   rf   r    s    c                 C  s   | j S )zGet whether this connection retrieves warnings automatically

        This method returns whether this connection retrieves warnings
        automatically.

        Returns True, or False when warnings are not retrieved.
        )rQ   rc   re   re   rf   r     s    	z$MySQLConnectionAbstract.get_warningsc                 C  s   t |tstd|| _dS )zSet whether warnings should be automatically retrieved

        The toggle-argument must be a boolean. When True, cursors for this
        connection will retrieve information about warnings (if any).

        Raises ValueError on error.
        Expected a boolean typeN)r   ru   r   rQ   r   re   re   rf   r     s    	
c                 C  s   | j S )zGet whether this connection raises an error on warnings

        This method returns whether this connection will raise errors when
        MySQL reports warnings.

        Returns True or False.
        )rR   rc   re   re   rf   r     s    	z)MySQLConnectionAbstract.raise_on_warningsc                 C  s&   t |tstd|| _|r"|| _dS )a  Set whether warnings raise an error

        The toggle-argument must be a boolean. When True, cursors for this
        connection will raise an error when MySQL reports warnings.

        Raising on warnings implies retrieving warnings automatically. In
        other words: warnings will be set to True. If set to False, warnings
        will be also set to False.

        Raises ValueError on error.
        r  N)r   ru   r   rR   rQ   r   re   re   rf   r     s
    
c                 C  s   | j S )zGet whether there is an unread result

        This method is used by cursors to check whether another cursor still
        needs to retrieve its result set.

        Returns True, or False when there is no unread result.
        )rS   rc   re   re   rf   unread_result  s    	z%MySQLConnectionAbstract.unread_resultc                 C  s   t |tstd|| _dS )zSet whether there is an unread result

        This method is used by cursors to let other cursors know there is
        still a result set that needs to be retrieved.

        Raises ValueError on errors.
        r  N)r   ru   r   rS   r   re   re   rf   r    s    	
c                 C  s   t | jd S )a+  Returns the character set for current connection

        This property returns the character set name of the current connection.
        The server is queried when the connection is active. If not connected,
        the configured character set name is returned.

        Returns a string.
        r   r!   get_infor?   rc   re   re   rf   r     s    
zMySQLConnectionAbstract.charsetc                 C  s    t | jd }|dkrdS |S )ay  Returns the Python character set for current connection

        This property returns the character set name of the current connection.
        Note that, unlike property charset, this checks if the previously set
        character set is supported by Python and if not, it returns the
        equivalent character set that Python supports.

        Returns a string.
        r   )Zutf8mb4Zutf8mb3binaryutf8r  )rd   encodingre   re   rf   python_charset  s    z&MySQLConnectionAbstract.python_charsetzOptional[Union[int, str]])r   r   r6   c                 C  s"  d}t |ttfs(|dk	r(t|dt |tsB|dk	rBtd|rt |trdt|\| _}}qt |trt||\| _}}qt|dn8|rtj|d\| _}}ntd }tj|dd\| _}}| 	d| d| d z| 
| W n tk
r   Y nX | jr| j| dS )	aV  Sets the character set and collation for the current connection

        This method sets the character set and collation to be used for
        the current connection. The charset argument can be either the
        name of a character set as a string, or the numerical equivalent
        as defined in constants.CharacterSet.

        When the collation is not given, the default will be looked up and
        used.

        For example, the following will set the collation for the latin1
        character set to latin1_general_ci:

           set_charset('latin1','latin1_general_ci')

        z+{} should be either integer, string or NoneNr   z)collation should be either string or None)r   zSET NAMES 'z' COLLATE 'r   )r   r   r   r   r   r!   r   r?   r   _execute_queryZset_character_set_namer   r]   set_charset)rd   r   r   err_msgcharset_nameZcollation_namere   re   rf   set_charset_collation#  sR    



z-MySQLConnectionAbstract.set_charset_collationc                 C  s   t | jd S )a  Returns the collation for current connection

        This property returns the collation name of the current connection.
        The server is queried when the connection is active. If not connected,
        the configured collation name is returned.

        Returns a string.
           )r!   r   r?   rc   re   re   rf   r   e  s    
z!MySQLConnectionAbstract.collationc                 C  s   dS )z<Gather information of the MySQL server before authenticationNre   rc   re   re   rf   _do_handshakeq  s    z%MySQLConnectionAbstract._do_handshakec                 C  s   dS )z'Open the connection to the MySQL serverNre   rc   re   re   rf   _open_connectionu  s    z(MySQLConnectionAbstract._open_connectionc                 C  sF   |  | j | j| _| jr"| j| _| jr0| j| _| jrB| 	| j dS )zExecutes commands after connection has been established

        This method executes commands after the connection has been
        established. Some setting like autocommit, character set, and SQL mode
        are set using this method.
        N)
r  r?   rB   r  rA   r  r@   r  rb   r  rc   re   re   rf   _post_connectiony  s    z(MySQLConnectionAbstract._post_connectionc                 C  s   dS )z Disconnect from the MySQL serverNre   rc   re   re   rf   
disconnect  s    z"MySQLConnectionAbstract.disconnectzCallable[[], Any]rq   c                 K  s8   |r| j f | |   |   | jtj@ s4|   dS )zConnect to the MySQL server

        This method sets up the connection to the MySQL server. If no
        arguments are given, it will use the already configured or default
        values.
        N)r   r$  r"  r>   r"   ZCAN_HANDLE_EXPIRED_PASSWORDSr#  )rd   r   re   re   rf   connect  s    zMySQLConnectionAbstract.connectr   r   )attemptsdelayr6   c              
   C  s   d}||kr|d }z |    |   |  r2W qW nH ttfk
r| } z&||krld| d| }t||W 5 d}~X Y nX |dkrt| qdS )a  Attempt to reconnect to the MySQL server

        The argument attempts should be the number of times a reconnect
        is tried. The delay argument is the number of seconds to wait between
        each retry.

        You may want to set the number of attempts higher and use delay when
        you expect the MySQL server to be down for maintenance or when you
        expect the network to be temporary unavailable.

        Raises InterfaceError on errors.
        r   r   z!Can not reconnect to MySQL after z attempt(s): N)r$  r%  is_connectedr%   IOErrorr&   r   )rd   r&  r'  counterr   msgre   re   rf   	reconnect  s    z!MySQLConnectionAbstract.reconnectc                 C  s   dS )z;Reports whether the connection to MySQL Server is availableNre   rc   re   re   rf   r(    s    z$MySQLConnectionAbstract.is_connectedF)r,  r&  r'  r6   c                 C  s   dS )z&Check availability of the MySQL serverNre   )rd   r,  r&  r'  re   re   rf   ping  s    zMySQLConnectionAbstract.pingc                 C  s   dS )zCommit current transactionNre   rc   re   re   rf   commit  s    zMySQLConnectionAbstract.commitzOptional[bool]zOptional[type]z'MySQLCursorAbstract')bufferedrawpreparedcursor_class
dictionarynamed_tupler6   c                 C  s   dS )z!Instantiates and returns a cursorNre   )rd   r/  r0  r1  r2  r3  r4  re   re   rf   cursor  s    
zMySQLConnectionAbstract.cursorc                 C  s   dS )zExecute a queryNre   r  re   re   rf   r    s    z&MySQLConnectionAbstract._execute_queryc                 C  s   dS )zRollback current transactionNre   rc   re   re   rf   rollback  s    z MySQLConnectionAbstract.rollback)consistent_snapshotisolation_levelreadonlyr6   c                 C  s   | j rtd|rZ| dd }ddddg}||krJtd| d	| d
|  |dk	r| jdk r~td| j d|rd}nd}| d|  d}|r|d7 }| | dS )a  Start a transaction

        This method explicitly starts a transaction sending the
        START TRANSACTION statement to the MySQL server. You can optionally
        set whether there should be a consistent snapshot, which
        isolation level you need or which access mode i.e. READ ONLY or
        READ WRITE.

        For example, to start a transaction with isolation level SERIALIZABLE,
        you would do the following:
            >>> cnx = mysql.connector.connect(..)
            >>> cnx.start_transaction(isolation_level='SERIALIZABLE')

        Raises ProgrammingError when a transaction is already in progress
        and when ValueError when isolation_level specifies an Unknown
        level.
        zTransaction already in progressr    zREAD UNCOMMITTEDzREAD COMMITTEDzREPEATABLE READZSERIALIZABLEzUnknown isolation level ""z SET TRANSACTION ISOLATION LEVEL N)      r<  zMySQL server version z does not support this featurez	READ ONLYz
READ WRITEzSET TRANSACTION zSTART TRANSACTIONz WITH CONSISTENT SNAPSHOT)	r  r)   r   r   r   r   r  rC   r   )rd   r7  r8  r9  levelZlevelsZaccess_moder  re   re   rf   start_transaction  s2    
z)MySQLConnectionAbstract.start_transactionzOptional[Dict[str, Any]])user_variablessession_variablesr6   c              	   C  s   |   stdz|   W n@ ttfk
r\   | jr@tdd| | j| j| j	| j
 Y nX |sf|r|  }|r| D ]\}}|d| d|  qz|r| D ]\}}|d| d|  q|  dS )a  Clears the current active session

        This method resets the session state, if the MySQL server is 5.7.3
        or later active session will be reset without re-authenticating.
        For other server versions session will be reset by re-authenticating.

        It is possible to provide a sequence of variables and their values to
        be set after clearing the session. This is possible for both user
        defined variables and session variables.
        This method takes two arguments user_variables and session_variables
        which are dictionaries.

        Raises OperationalError if not connected, InternalError if there are
        unread results and InterfaceError on errors.
        zMySQL Connection not availablezYReset session is not supported with compression for MySQL server version 5.7.2 or earlierNzSET @`z` = zSET SESSION `)r(  r(   cmd_reset_connectionr'   NotImplementedErrorr`   cmd_change_userrF   rG   rH   r?   r5  r   executerq   )rd   r@  rA  curr   r}   re   re   rf   reset_session  s4    
z%MySQLConnectionAbstract.reset_sessionzOptional[Type[MySQLConverter]])	convclassr6   c                 C  sJ   |r>t |tr>t| jd }|| _||| j| _| j| j_	nt
ddS )z
        Set the converter class to be used. This should be a class overloading
        methods and members of conversion.MySQLConverter.
        r   zFConverter class should be a subclass of conversion.MySQLConverterBase.N)
issubclassr$   r!   r  r?   r^   rP   r]   r_   Zstr_fallbackr   )rd   rH  r  re   re   rf   r   I  s    z+MySQLConnectionAbstract.set_converter_classOptional[int]Optional[List[DescriptionType]]z-Tuple[List[Any], Optional[Mapping[str, Any]]])countr  columnsr0  	prep_stmtr6   c                 C  s   dS )z)Get all rows returned by the MySQL serverNre   )rd   rL  r  rM  r0  rN  re   re   rf   get_rowsX  s    	z MySQLConnectionAbstract.get_rowszOptional[Mapping[str, Any]])r   r6   c                 C  s   t dS )zChange the current databaseNrC  )rd   r   re   re   rf   cmd_init_dbc  s    z#MySQLConnectionAbstract.cmd_init_db)r  r0  r/  raw_as_stringr6   c                 C  s   t dS )z Send a query to the MySQL serverNrP  )rd   r  r0  r/  rR  re   re   rf   r   g  s    z!MySQLConnectionAbstract.cmd_queryz(Generator[Mapping[str, Any], None, None])
statementsr6   c                 C  s   t dS )z/Send one or more statements to the MySQL serverNrP  )rd   rS  re   re   rf   cmd_query_iterq  s    z&MySQLConnectionAbstract.cmd_query_iter)optionsr6   c                 C  s   t dS )z,Send the Refresh command to the MySQL serverNrP  )rd   rU  re   re   rf   cmd_refreshw  s    z#MySQLConnectionAbstract.cmd_refreshc                 C  s   t dS )z,Close the current connection with the serverNrP  rc   re   re   rf   cmd_quit{  s    z MySQLConnectionAbstract.cmd_quit)shutdown_typer6   c                 C  s   t dS )zShut down the MySQL ServerNrP  )rd   rX  re   re   rf   cmd_shutdown  s    z$MySQLConnectionAbstract.cmd_shutdownc                 C  s   t dS )z/Send the statistics command to the MySQL ServerNrP  rc   re   re   rf   cmd_statistics  s    z&MySQLConnectionAbstract.cmd_statisticsc                   C  s   t ddS )ak  Get the process list of the MySQL Server

        This method is a placeholder to notify that the PROCESS_INFO command
        is not supported by raising the NotSupportedError. The command
        "SHOW PROCESSLIST" should be send using the cmd_query()-method or
        using the INFORMATION_SCHEMA database.

        Raises NotSupportedError exception
        z;Not implemented. Use SHOW PROCESSLIST or INFORMATION_SCHEMAN)r'   re   re   re   rf   cmd_process_info  s    z(MySQLConnectionAbstract.cmd_process_info)	mysql_pidr6   c                 C  s   t dS )zKill a MySQL processNrP  )rd   r\  re   re   rf   cmd_process_kill  s    z(MySQLConnectionAbstract.cmd_process_killc                 C  s   t dS )zSend the DEBUG commandNrP  rc   re   re   rf   	cmd_debug  s    z!MySQLConnectionAbstract.cmd_debugc                 C  s   t dS )zSend the PING commandNrP  rc   re   re   rf   cmd_ping  s    z MySQLConnectionAbstract.cmd_pingr8   r7   )	r   r   r   r   	password1	password2	password3oci_config_filer6   c	           	      C  s   t dS )z!Change the current logged in userNrP  )	rd   r   r   r   r   r`  ra  rb  rc  re   re   rf   rD    s    z'MySQLConnectionAbstract.cmd_change_user)	statementr6   c                 C  s   t dS )zPrepare a MySQL statementNrP  )rd   rd  re   re   rf   cmd_stmt_prepare  s    z(MySQLConnectionAbstract.cmd_stmt_preparere   Sequence[Any])statement_iddatar   r  r6   c                 C  s   t dS )z"Execute a prepared MySQL statementNrP  )rd   rg  rh  r   r  re   re   rf   cmd_stmt_execute  s    z(MySQLConnectionAbstract.cmd_stmt_execute)rg  r6   c                 C  s   t dS )z%Deallocate a prepared MySQL statementNrP  rd   rg  re   re   rf   cmd_stmt_close  s    z&MySQLConnectionAbstract.cmd_stmt_closer   )rg  param_idrh  r6   c                 C  s   t dS )zSend data for a columnNrP  )rd   rg  rl  rh  re   re   rf   cmd_stmt_send_long_data  s    z/MySQLConnectionAbstract.cmd_stmt_send_long_datac                 C  s   t dS )z3Reset data for prepared statement sent as long dataNrP  rj  re   re   rf   cmd_stmt_reset  s    z&MySQLConnectionAbstract.cmd_stmt_resetc                 C  s   t dS )z2Resets the session state without re-authenticatingNrP  rc   re   re   rf   rB    s    z,MySQLConnectionAbstract.cmd_reset_connection)NN)T)NN)r   r   )Fr   r   )NNNNNN)FNN)NN)NFNNN)FFF)N)r8   r8   r8   r7   r8   r8   r8   r8   )re   re   r   )S__name__
__module____qualname____doc__rg   ri   rs   rt   propertyry   rz   r|   r   r   r   r   r   r   r   r   r   r   setterr   r   r   r   staticmethodr  r  r  r  r   r  r  r  r
  r   r  r  r   r   r  r   r  r  r   r!  r"  r#  r$  rq   __annotations__r%  r,  r(  r-  r.  r5  r  r6  r?  rG  r   rO  rQ  r   rT  rV  rW  rY  rZ  r[  r]  r^  r_  rD  re  ri  rk  rm  rn  rB  re   re   re   rf   r3      sJ  
<SR  A
   



   B         <  0     
   
             
r3   c                   @  s  e Zd ZdZddddZd dddZdd	d
ddddZedPddddddZeddddZ	edQdddddddZ
edddddd Zed!dd"d#ZedRd%d&d'd(d)Zeddd*d+Zddd,d-Zddd.d/d0ZdSdddd2d3d4ZdTddd6d7d8Zeed9dd:d;Zeed%dd<d=Zed>dd?d@ZedAddBdCZed%ddDdEZdAddFdGZdHddIdJZddddKdLdMZdddNdOZd1S )UMySQLCursorAbstractzAbstract cursor class

    Abstract class defining cursor class with method and members
    required by the Python Database API Specification v2.0.
    r4   r5   c                 C  s:   d| _ d| _d| _d| _d| _d| _g | _g | _d| _dS )ZInitializationNr   r   r   )	_description	_rowcount_last_insert_id	_warnings_warning_countZ	_executedZ_executed_listZ_stored_resultsZ	arraysizerc   re   re   rf   rg     s    zMySQLCursorAbstract.__init__c                 C  s   | S rh   re   rc   re   re   rf   ri     s    zMySQLCursorAbstract.__enter__rj   rk   r   rl   c                 C  s   |    d S rh   rp   rr   re   re   rf   rs     s    zMySQLCursorAbstract.__exit__re   r   rf  r   )procnameargsr6   c                 C  s   dS )a  Calls a stored procedure with the given arguments

        The arguments will be set during this session, meaning
        they will be called like  _<procname>__arg<nr> where
        <nr> is an enumeration (+1) of the arguments.

        Coding Example:
          1) Defining the Stored Routine in MySQL:
          CREATE PROCEDURE multiply(IN pFac1 INT, IN pFac2 INT, OUT pProd INT)
          BEGIN
            SET pProd := pFac1 * pFac2;
          END

          2) Executing in Python:
          args = (5,5,0) # 0 is to hold pprod
          cursor.callproc('multiply', args)
          print(cursor.fetchone())

        Does not return a value, but a result set will be
        available when the CALL-statement execute successfully.
        Raises exceptions when something is wrong.
        Nre   )rd   r}  r~  re   re   rf   callproc  s    zMySQLCursorAbstract.callprocc                 C  s   dS )zClose the cursor.Nre   rc   re   re   rf   rq   
  s    zMySQLCursorAbstract.closeFz$Union[Sequence[Any], Dict[str, Any]]ru   )	operationr   multir6   c                 C  s   dS )a  Executes the given operation

        Executes the given operation substituting any markers with
        the given parameters.

        For example, getting all rows where id is 5:
          cursor.execute("SELECT * FROM t1 WHERE id = %s", (5,))

        The multi argument should be set to True when executing multiple
        statements in one operation. If not set and multiple results are
        found, an InterfaceError will be raised.

        If warnings where generated, and connection.get_warnings is True, then
        self._warnings will be a list containing these warnings.

        Returns an iterator when multi is True, otherwise None.
        Nre   )rd   r  r   r  re   re   rf   rE    s    zMySQLCursorAbstract.executez.Sequence[Union[Sequence[Any], Dict[str, Any]]])r  
seq_paramsr6   c                 C  s   dS )a  Execute the given operation multiple times

        The executemany() method will execute the operation iterating
        over the list of parameters in seq_params.

        Example: Inserting 3 new employees and their phone number

        data = [
            ('Jane','555-001'),
            ('Joe', '555-001'),
            ('John', '555-003')
            ]
        stmt = "INSERT INTO employees (name, phone) VALUES ('%s','%s')"
        cursor.executemany(stmt, data)

        INSERT statements are optimized by batching the data, that is
        using the MySQL multiple rows syntax.

        Results are discarded. If they are needed, consider looping over
        data using the execute() method.
        Nre   )rd   r  r  re   re   rf   executemany'  s    zMySQLCursorAbstract.executemanyzOptional[Sequence[Any]]c                 C  s   dS )zQReturns next row of a query result set

        Returns a tuple or None.
        Nre   rc   re   re   rf   fetchoneA  s    zMySQLCursorAbstract.fetchoner   r   zList[Sequence[Any]])sizer6   c                 C  s   dS )a  Returns the next set of rows of a query result, returning a
        list of tuples. When no more rows are available, it returns an
        empty list.

        The number of rows returned can be specified using the size argument,
        which defaults to one
        Nre   )rd   r  re   re   rf   	fetchmanyH  s    zMySQLCursorAbstract.fetchmanyc                 C  s   dS )zRReturns all rows of a query result set

        Returns a list of tuples.
        Nre   rc   re   re   rf   fetchallR  s    zMySQLCursorAbstract.fetchallc                 C  s   dS zNot Implemented.Nre   rc   re   re   rf   nextsetY  s    zMySQLCursorAbstract.nextset)sizesr6   c                 C  s   dS r  re   )rd   r  re   re   rf   setinputsizes\  s    z!MySQLCursorAbstract.setinputsizesN)r  columnr6   c                 C  s   dS r  re   )rd   r  r  re   re   rf   setoutputsize_  s    z!MySQLCursorAbstract.setoutputsizeT)freer6   c                 C  s   dS )zReset the cursor to defaultNre   )rd   r  re   re   rf   resetb  s    zMySQLCursorAbstract.resetrK  c                 C  s   | j S )a  Returns description of columns in a result

        This property returns a list of tuples describing the columns in
        in a result set. A tuple is described as follows::

                (column_name,
                 type,
                 None,
                 None,
                 None,
                 None,
                 null_ok,
                 column_flags)  # Addition to PEP-249 specs

        Returns a list of tuples.
        )rx  rc   re   re   rf   descriptione  s    zMySQLCursorAbstract.descriptionc                 C  s   | j S )a   Returns the number of rows produced or affected

        This property returns the number of rows produced by queries
        such as a SELECT, or affected rows when executing DML statements
        like INSERT or UPDATE.

        Note that for non-buffered cursors it is impossible to know the
        number of rows produced before having fetched them all. For those,
        the number of rows will be -1 right after execution, and
        incremented when fetching rows.

        Returns an integer.
        )ry  rc   re   re   rf   rowcount|  s    zMySQLCursorAbstract.rowcountrJ  c                 C  s   | j S )a  Returns the value generated for an AUTO_INCREMENT column

        Returns the value generated for an AUTO_INCREMENT column by
        the previous INSERT or UPDATE statement or None when there is
        no such value available.

        Returns a long value or None.
        )rz  rc   re   re   rf   	lastrowid  s    
zMySQLCursorAbstract.lastrowidzOptional[List[WarningType]]c                 C  s   | j S )zReturn warnings.r{  rc   re   re   rf   warnings  s    zMySQLCursorAbstract.warningsc                 C  s   | j S )zReturns the number of warnings

        This property returns the number of warnings generated by the
        previously executed operation.

        Returns an integer value.
        )r|  rc   re   re   rf   warning_count  s    	z!MySQLCursorAbstract.warning_countc                 C  s   | j S )zReturns Warnings.r  rc   re   re   rf   fetchwarnings  s    z!MySQLCursorAbstract.fetchwarningszOptional[List[Tuple[Any, Any]]]c                 C  s(   t | dr| jjS t | dr$| jjS dS )z&Get the added query attributes so far._cnx_connectionN)hasattrr  r|   r  rc   re   re   rf   get_attributes  s
    

z"MySQLCursorAbstract.get_attributes)rx   r}   r6   c                 C  sn   t |tstd|dk	r4t |ts4td| dt| drP| j||f nt| drj| j||f dS )z$Add a query attribute and his value.z&Parameter `name` must be a string typeNzObject z$ cannot be converted to a MySQL typer  r  )r   r   r)   MYSQL_PY_TYPESr  r  r   r  )rd   rx   r}   re   re   rf   add_attribute  s    



z!MySQLCursorAbstract.add_attributec                 C  s.   t | dr| j  nt | dr*| j  dS )z Remove all the query attributes.r  r  N)r  r  r   r  rc   re   re   rf   clear_attributes  s    

z$MySQLCursorAbstract.clear_attributes)re   )re   F)r   )N)T)ro  rp  rq  rr  rg   ri   rs   r   r  rq   rE  r  r  r  r  r  r  r  r  rs  r  r  r  r  r  r  r  r  r  re   re   re   rf   rw    sP     	
rw  )Qrr  
__future__r   r   rw   r   weakrefabcr   r   r   r   r   r   decimalr	   inspectr
   r   typesr   typingr   r   r   r   r   r   r   r   r   r   r   r   r   sslr  r   ImportError	constantsr   r   r   r   r   r    r!   r"   
conversionr#   r$   errorsr%   r&   r'   r(   r)   Zoptionfilesr*   r+   r,   r-   r.   r/   r0   r1   WeakValueDictionaryr2   rv  r   r   r   r   r   r   floatr   r   r  r3   rw  re   re   re   rf   <module>   sr   8(
$
          Q