Current File : //lib/python3.9/site-packages/pymysql/__pycache__/connections.cpython-39.pyc
a

ۖX_r��	@sPddlmZddlmZmZmZmZmZmZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZddlmZmZddlmZmZmZmZmZddlmZdd	lmZdd
lm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)m*Z*dd
lm+Z+m,Z,zddl-Z-dZ.Wne/�y4dZ-dZ.Yn0zddl0Z0e0�1�Z2[0Wne/e3f�yhdZ2Yn0dZ4ej5dd�Z6e�r�n.e6dk�r�dd�e7d�D�Z8dd�Z9ndd�Z9e�r�e�s�ddl:m;Z;dd�Z<ndd�Z<ej=ej>ej?ej@ejAejBejCejDejEh	ZFdZGdZHdd�ZId d!�ZJGd"d#�d#eK�ZLGd$d%�d%eK�ZMGd&d'�d'eK�ZNdS)(�)�print_function�)�PY2�
range_type�	text_type�str_type�JYTHON�
IRONPYTHONN)�_auth)�charset_by_name�
charset_by_id)�CLIENT�COMMAND�CR�
FIELD_TYPE�
SERVER_STATUS)�
converters)�Cursor)�Parser)�dump_packet�MysqlPacket�FieldDescriptorPacket�OKPacketWrapper�EOFPacketWrapper�LoadLocalPacketWrapper)�byte2int�int2byte)�err�VERSION_STRINGTF�)��cCs(g|] }|dkrt|�n
t|d��qS)�i�)�chr)�.0�i�r&�7/usr/lib/python3.9/site-packages/pymysql/connections.py�
<listcomp>6�r(�cCs|�d��t�S)N�latin1)�decode�	translate�_surrogateescape_table��sr&r&r'�_fast_surrogateescape8sr1cCs|�dd�S)N�ascii�surrogateescape)r,r/r&r&r'r1;s)�SocketIOcCst�t||��S�N)�io�BufferedReaderr4��sock�moder&r&r'�	_makefileFsr;cCs
|�|�Sr5)Zmakefiler8r&r&r'r;JsZutf8mb4��cCst�d|�dd�S)N�<Ir )�struct�pack)�nr&r&r'�
pack_int24`srAcCs�|dkrtd|��np|dkr&t|�S|dkr>dt�d|�S|dkr^dt�d	|�dd
�S|dkrvdt�d
|�Std|df��dS)NrzFEncoding %d is less than 0 - no representation in LengthEncodedInteger�i���<H���r=r l��z<QzIEncoding %x is larger than %x - no representation in LengthEncodedInteger)�
ValueErrorrr>r?)r%r&r&r'�
lenenc_intesrIc @seZdZdZdZdZdZdZddddddddddddedddddddddddddddddddf dd	�Z	d
d�Z
dd
�Zedd��Z
dd�ZeZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd]d$d%�Zd&d'�Zd(d)�Zd*d+�Zd^d,d-�Zd_d.d/�Zd`d0d1�Zd2d3�Z d4d5�Z!dad7d8�Z"d9d:�Z#dbd;d<�Z$d=d>�Z%e&fd?d@�Z'dAdB�Z(dCdD�Z)dcdEdF�Z*dGdH�Z+dIdJ�Z,dKdL�Z-dMdN�Z.dOdP�Z/dQdR�Z0dSdT�Z1dUdV�Z2dWdX�Z3dYdZ�Z4d[d\�Z5e6j7Z7e6j8Z8e6j9Z9e6j:Z:e6j;Z;e6j<Z<e6j=Z=e6j>Z>e6j?Z?e6j@Z@dS)d�
Connectiona�

    Representation of a socket with a mysql server.

    The proper way to get an instance of this class is to call
    connect().

    Establish a connection to the MySQL database. Accepts several
    arguments:

    :param host: Host where the database server is located
    :param user: Username to log in as
    :param password: Password to use.
    :param database: Database to use, None to not use a particular one.
    :param port: MySQL port to use, default is usually OK. (default: 3306)
    :param bind_address: When the client has multiple network interfaces, specify
        the interface from which to connect to the host. Argument can be
        a hostname or an IP address.
    :param unix_socket: Optionally, you can use a unix socket rather than TCP/IP.
    :param read_timeout: The timeout for reading from the connection in seconds (default: None - no timeout)
    :param write_timeout: The timeout for writing to the connection in seconds (default: None - no timeout)
    :param charset: Charset you want to use.
    :param sql_mode: Default SQL_MODE to use.
    :param read_default_file:
        Specifies  my.cnf file to read these parameters from under the [client] section.
    :param conv:
        Conversion dictionary to use instead of the default one.
        This is used to provide custom marshalling and unmarshalling of types.
        See converters.
    :param use_unicode:
        Whether or not to default to unicode strings.
        This option defaults to true for Py3k.
    :param client_flag: Custom flags to send to MySQL. Find potential values in constants.CLIENT.
    :param cursorclass: Custom cursor class to use.
    :param init_command: Initial SQL statement to run when connection is established.
    :param connect_timeout: Timeout before throwing an exception when connecting.
        (default: 10, min: 1, max: 31536000)
    :param ssl:
        A dict of arguments similar to mysql_ssl_set()'s parameters.
    :param read_default_group: Group to read from in the configuration file.
    :param compress: Not supported
    :param named_pipe: Not supported
    :param autocommit: Autocommit mode. None means use server default. (default: False)
    :param local_infile: Boolean to enable the use of LOAD DATA LOCAL command. (default: False)
    :param max_allowed_packet: Max size of packet sent to server in bytes. (default: 16MB)
        Only used to limit size of "LOAD LOCAL INFILE" data packet smaller than default (16KB).
    :param defer_connect: Don't explicitly connect on construction - wait for connect call.
        (default: False)
    :param auth_plugin_map: A dict of plugin names to a class that processes that plugin.
        The class will take the Connection object as the argument to the constructor.
        The class needs an authenticate method taking an authentication packet as
        an argument.  For the dialog plugin, a prompt(echo, prompt) method can be used
        (if no authenticate method) for returning a string from the user. (experimental)
    :param server_public_key: SHA256 authentication plugin public key value. (default: None)
    :param db: Alias for database. (for compatibility to MySQLdb)
    :param passwd: Alias for password. (for compatibility to MySQLdb)
    :param binary_prefix: Add _binary prefix on bytes and bytearray. (default: False)

    See `Connection <https://www.python.org/dev/peps/pep-0249/#connection-objects>`_ in the
    specification.
    N�Fr�
rEc!$s�|durtjddkrd}|dur.|dur.|}|dur>|s>|}|sF|rNtd��t|�|_|jrh|tjO}�r�|	s�tj�d�r�d}	nd}	|	�rR�s�d�t	����
tj�
|	����fd	d
�}!|!d|�}|!d|�}|!d
|�}|!d|�}|!d|�}t|!d|��}|!d|�}|!d|�}|�si}t|t��rRdD](}"|!d|"|�|"��}#|#�r(|#||"<�q(d|_|�r�t�sltd��d|_|tjO}|�|�|_|�p�d|_|�p�d|_t|j�tu�r�td��|�p�t|_|�p�d|_t|jt��r�|j�d�|_||_ ||_!||_"d|k�rdk�s ntd��|�p(d|_#|du�rH|dk�rHtd��||_$|du�rj|dk�rjtd��||_%|�r�||_&d|_'nt(|_&d|_'|du�r�||_'t)|j&�j*|_*|tj+O}|j �r�|tj,O}||_-|
|_.d|_/d|_0d |_1||_2|
du�r�t3j4}
d!d"�|
�5�D�|_6d#d"�|
�5�D�|_7||_8||_9||_:|�p@i|_;||_<| |_=d$t>t�?��t@d%�|_A|�rv||jAd&<|�r�d|_Bn|�C�dS)'NrrTz3compress and named_pipe arguments are not supported�winz	c:\my.iniz/etc/my.cnfZclientcs2|r|Sz���|�WSty,|YS0dSr5)�get�	Exception)�key�arg�Zcfg�read_default_groupr&r'�_config�sz$Connection.__init__.<locals>._config�user�password�host�database�socket�portzbind-addresszdefault-character-set)�ca�capath�certrP�cipherzssl-Fzssl module not foundZ	localhosti�zport should be of type intr)r+i�3�z+connect_timeout should be >0 and <=31536000zread_timeout should be > 0zwrite_timeout should be > 0z
Not connectedcSs"i|]\}}t|�tur||�qSr&��type�int�r$�k�vr&r&r'�
<dictcomp>2r)z'Connection.__init__.<locals>.<dictcomp>cSs"i|]\}}t|�tur||�qSr&r_rbr&r&r're3r)Zpymysql)Z_client_nameZ_pidZ_client_version�program_name)D�sys�version_info�NotImplementedError�bool�
_local_infiler
ZLOCAL_FILES�platform�
startswithr�read�os�path�
expanduserra�
isinstance�dictrN�ssl�SSL_ENABLED�SSL�_create_ssl_ctx�ctxrWrZr`rH�DEFAULT_USERrUrVr�encode�db�unix_socket�bind_address�connect_timeout�
_read_timeout�_write_timeout�charset�use_unicode�DEFAULT_CHARSETr�encodingZCAPABILITIES�CONNECT_WITH_DB�client_flag�cursorclass�_result�_affected_rows�	host_info�autocommit_moderZconversions�items�encoders�decoders�sql_mode�init_command�max_allowed_packet�_auth_plugin_map�_binary_prefix�server_public_key�str�getpidr�_connect_attrs�_sock�connect)$�selfrWrUrVrXrZr|r�r�Zread_default_file�convr�r�r�r�r~rtrS�compressZ
named_pipe�
autocommitr{�passwdZlocal_infiler�Z
defer_connectZauth_plugin_mapZread_timeoutZ
write_timeoutr}Z
binary_prefixrfr�rTrP�valuer&rRr'�__init__�s�














�
zConnection.__init__cCs�t|tj�r|S|�d�}|�d�}|duo2|du}tj||d�}|oR|�dd�|_|r`tjntj|_d|vr�|j	|d|�d�d�d	|vr�|�
|d	�|jtjO_|jtj
O_|S)
Nr[r\)Zcafiler\�check_hostnameTr]rP)Zkeyfiler^)rrrtZ
SSLContextrNZcreate_default_contextr�Z	CERT_NONEZ
CERT_REQUIREDZverify_modeZload_cert_chainZset_ciphers�optionsZOP_NO_SSLv2ZOP_NO_SSLv3)r�Zsslpr[r\Zhasnocarxr&r&r'rwIs

zConnection._create_ssl_ctxcCsr|jrt�d��d|_|jdur$dSt�ddtj�}z.z|�|�Wnt	yVYn0W|�
�n
|�
�0dS)z�
        Send the quit message and close the socket.

        See `Connection.close() <https://www.python.org/dev/peps/pep-0249/#Connection.close>`_
        in the specification.

        :raise Error: If the connection is already closed.
        �Already closedTN�<iBr)�_closedr�Errorr�r>r?rZCOM_QUIT�_write_bytesrO�_force_close)r��	send_datar&r&r'�closeZs	

zConnection.closecCs
|jduS)z%Return True if the connection is openN)r��r�r&r&r'�openpszConnection.opencCs2|jr"z|j��WnYn0d|_d|_dS)z%Close connection without QUIT messageN)r�r��_rfiler�r&r&r'r�uszConnection._force_closecCs&t|�|_|��}||kr"|��dSr5)rjr��get_autocommit�_send_autocommit_mode)r�r��currentr&r&r'r��s
zConnection.autocommitcCst|jtj@�Sr5)rj�
server_statusrZSERVER_STATUS_AUTOCOMMITr�r&r&r'r��s�zConnection.get_autocommitcCs0|��}|��st�dd��t|�}|j|_|S)N��zCommand Out of Sync)�_read_packet�is_ok_packetr�OperationalErrorrr�)r��pkt�okr&r&r'�_read_ok_packet�szConnection._read_ok_packetcCs&|�tjd|�|j��|��dS)z2Set whether or not to commit after every execute()zSET AUTOCOMMIT = %sN)�_execute_commandr�	COM_QUERY�escaper�r�r�r&r&r'r��s

�z Connection._send_autocommit_modecCs|�tjd�|��dS)zBegin transaction.ZBEGINN�r�rr�r�r�r&r&r'�begin�szConnection.begincCs|�tjd�|��dS)z�
        Commit changes to stable storage.

        See `Connection.commit() <https://www.python.org/dev/peps/pep-0249/#commit>`_
        in the specification.
        ZCOMMITNr�r�r&r&r'�commit�szConnection.commitcCs|�tjd�|��dS)z�
        Roll back the current transaction.

        See `Connection.rollback() <https://www.python.org/dev/peps/pep-0249/#rollback>`_
        in the specification.
        ZROLLBACKNr�r�r&r&r'�rollback�szConnection.rollbackcCs$|�tjd�t|�}|��|jS)z%Send the "SHOW WARNINGS" SQL command.z
SHOW WARNINGS)r�rr��MySQLResultrn�rows)r��resultr&r&r'�
show_warnings�szConnection.show_warningscCs|�tj|�|��dS)zI
        Set current db.

        :param db: The name of the db.
        N)r�rZCOM_INIT_DBr�)r�r{r&r&r'�	select_db�szConnection.select_dbcCsXt|t�rd|�|�dSt|ttf�rF|�|�}|jrBd|}|Stj||j	|d�S)z}Escape whatever value you pass to it.

        Non-standard, for internal use; do not use this in your applications.
        �'Z_binary)�mapping)
rrr�
escape_string�bytes�	bytearray�_quote_bytesr�rZescape_itemr�)r��objr��retr&r&r'r��s

zConnection.escapecCs|�||j�S)zjAlias for escape()

        Non-standard, for internal use; do not use this in your applications.
        )r�r�)r�r�r&r&r'�literal�szConnection.literalcCs"|jtj@r|�dd�St�|�S)Nr�z'')r�r�"SERVER_STATUS_NO_BACKSLASH_ESCAPES�replacerr��r�r0r&r&r'r��s
�zConnection.escape_stringcCs,|jtj@r"dt|�dd��fSt�|�S)Nz'%s'�'s'')r�rr�r1r�rZescape_bytesr�r&r&r'r��s
�zConnection._quote_bytescCs|r||�S|�|�S)a	
        Create a new cursor to execute queries with.

        :param cursor: The type of cursor to create; one of :py:class:`Cursor`,
            :py:class:`SSCursor`, :py:class:`DictCursor`, or :py:class:`SSDictCursor`.
            None means use Cursor.
        )r�)r��cursorr&r&r'r��szConnection.cursorcCsTt|t�r2ts2ts2tr$|�|j�}n|�|jd�}|�tj	|�|j
|d�|_|jS)Nr3��
unbuffered)rrrrr	rrzr�r�rr��_read_query_resultr�)r��sqlr�r&r&r'�query�szConnection.querycCs|j|d�|_|jS)Nr�)r�r�)r�r�r&r&r'�next_result�szConnection.next_resultcCs|jSr5)r�r�r&r&r'�
affected_rowsszConnection.affected_rowscCs"t�d|�}|�tj|�|��S)Nr=)r>r?r�rZCOM_PROCESS_KILLr�)r��	thread_idrQr&r&r'�killszConnection.killTcCsr|jdur&|r|��d}n
t�d��z|�tjd�|��Wn,tyl|rf|��|�	d�n�Yn0dS)z�
        Check if the server is alive.

        :param reconnect: If the connection is closed, reconnect.
        :raise Error: If the connection is closed and reconnect=False.
        NFr�rK)
r�r�rr�r�rZCOM_PINGr�rO�ping)r�Z	reconnectr&r&r'r�s

zConnection.pingcCs:t|�j}|�tjd|�|��|��||_||_dS)NzSET NAMES %s)rr�r�rr�r�r�r�)r�r�r�r&r&r'�set_charsets

zConnection.set_charsetc
Csnd|_�z�|du�r2|jr\t�tjtj�}|�|j�|�|j�d|_d|_	t
rZtd�n�i}|jdurx|jdf|d<z&tj
|j|jf|jfi|��}Wq�Wqxttfy�}z&|jtjkr�WYd}~qx�WYd}~qxd}~00qxd|j|jf|_t
�rtd�|�tjtjd	�|�tjtjd	�|�d�||_t|d
�|_d|_|��|��|jdu�r~|� �}|�!d|jf�|j"du�r�|� �}|�!|j"�|�#�|�$�|j%du�r�|�&|j%�Wn�t'�yh}z�d|_|du�rz|�#�WnYn0t(|tttj)f��rRt*�+dd
|j|f�}||_,t-�.�|_-t
�rNt|j-�|��WYd}~n
d}~00dS)NFzLocalhost via UNIX socketTzconnected using unix_socketrZsource_addresszsocket %s:%dzconnected using socketr�rbzSET sql_mode=%si�z(Can't connect to MySQL server on %r (%s))/r�r|rYZAF_UNIXZSOCK_STREAM�
settimeoutr~r�r��_secure�DEBUG�printr}Zcreate_connectionrWrZ�OSError�IOError�errno�EINTRZ
setsockoptZIPPROTO_TCPZTCP_NODELAYZ
SOL_SOCKETZSO_KEEPALIVEr�r;r��_next_seq_id�_get_server_information�_request_authenticationr�r�Zexecuter�r�r�r�r��
BaseExceptionrr�errorrr�Zoriginal_exception�	traceback�
format_exc)r�r9�kwargs�e�c�excr&r&r'r�(s~

��

��
zConnection.connectcCsDtt|��t|j�|}tr&t|�|�|�|jdd|_dS)zvWrites an entire "mysql packet" in its entirety to the network
        adding its length and sequence number.
        rr*N)rA�lenrr�r�rr�)r�Zpayload�datar&r&r'�write_packetrs
zConnection.write_packetc
Cs�t�}|�d�}t�d|�\}}}||d>}||jkrj|��|dkrVt�tj	d��t�
d||jf��|jdd|_|�|�}tr�t|�||7}|d	kr�q|t
krq�q|t|�|j�}	|	��r�|jd
ur�|jjdur�d|j_|	��|	S)
a!Read an entire "mysql packet" in its entirety from the network
        and return a MysqlPacket type that represents the results.

        :raise OperationalError: If the connection to the MySQL server is lost.
        :raise InternalError: If the packet sequence number is wrong.
        �z<HBB�r�,Lost connection to MySQL server during queryz1Packet sequence number wrong - got %d expected %drr*r<NTF)r��_read_bytesr>�unpackr�r�rr�r�CR_SERVER_LOST�
InternalErrorr�r�MAX_PACKET_LENr�r�Zis_error_packetr��unbuffered_activeZraise_for_error)
r�Zpacket_typeZbuffZ
packet_headerZbtrlZbtrhZ
packet_numberZ
bytes_to_readZ	recv_data�packetr&r&r'r�}s<

���
zConnection._read_packetc
Cs�|j�|j�z|j�|�}Wq�Wqttfy~}z@|jtjkrNWYd}~q|�	�t
�tj
d|f��WYd}~qd}~0ty�|�	��Yq0qt|�|kr�|�	�t
�tj
d��|S)Nz1Lost connection to MySQL server during query (%s)r�)r�r�rr�rnr�r�r�r�r�rr�rr�r�r�)r�Z	num_bytesr�r�r&r&r'r��s*�
�zConnection._read_bytesc
Csd|j�|j�z|j�|�Wn@ty^}z(|��t�tj	d|f��WYd}~n
d}~00dS)NzMySQL server has gone away (%r))
r�r�r�Zsendallr�r�rr�rZCR_SERVER_GONE_ERROR)r�r�r�r&r&r'r��s�zConnection._write_bytescCsjd|_|r<zt|�}|��WqLd|_d|_�YqL0nt|�}|��||_|jdurd|j|_|jS�NF)r�r��init_unbuffered_queryr��
connectionrnr�r�)r�r�r�r&r&r'r��s

zConnection._read_query_resultcCs|jr|jjSdSdS�Nr)r��	insert_idr�r&r&r'r�szConnection.insert_idcCs|jst�dd��|jdurP|jjr8t�d�|j��|jjrJ|�	�q8d|_t
|t�rf|�|j
�}ttt|�d�}t�d||�}||d|d�}|�|�tr�t|�d|_|tkr�dS||dd�}ttt|��}|�|d|��||d�}|s�|tkrҐqq�dS)z~
        :raise InterfaceError: If the connection is closed.
        :raise ValueError: If no username was specified.
        rrKNz.Previous unbuffered result was left incompleterr�)r�r�InterfaceErrorr�r��warnings�warn�_finish_unbuffered_query�has_nextr�rrrrzr��minr�r�r>r?r�r�rr�r�)r�Zcommandr��packet_sizeZpreluder�r&r&r'r��s2





zConnection._execute_commandc
Cs�t|j�dd�d�dkr*|jtjO_|jdur<td��t|j	�j
}t|jt�rd|j�
|j�|_t�d|jt|d�}|jr�|jtj@r�|�|�|jj|j|jd�|_t|jd	�|_d
|_||jd}d}d}|jdkr�d}t�|j |j!�}n�|jd
k�rd}t�|j |j!�}n�|jdk�r^d}|j �rNt"�r<t#d�t�$|j |j!�}nt"�r�t#d�nD|jdk�r�d}|j�r�|jtj@�r�|j d}n|j �r�d}nd}|jtj%@�r�|t&t'|��|7}n4|jtj(@�r�|t�dt'|��|7}n||d7}|j)�r<|jtj*@�r<t|j)t��r.|j)�
|j�|_)||j)d7}|jtj+@�r\||�pTdd7}|jtj,@�r�d}|j-�.�D]N\}}|�
d�}|t�dt'|��|7}|�
d�}|t�dt'|��|7}�qx|t�dt'|��|7}|�|�|�/�}	|	�0��rht"�r
t#d�|	�1�|	�2�}|jtj+@�r@|du�r@|�3||	�}	n&t�4|j |j!�d}|�|�|�/�}	nZ|	�5��r�t"�r�t#d�|jdk�r�t�6||	�}	n(|jdk�r�t�7||	�}	nt8�9d|j��t"�r�t#d�dS)N�.rr�zDid not specify a usernamez<iIB23sr))Zserver_hostnamer�T�rKZmysql_native_password�mysql_native_passwordZcaching_sha2_password�caching_sha2_passwordzcaching_sha2: trying fast pathzcaching_sha2: empty passwordZsha256_password�sha256_password��B�utf-8zreceived auth switchzreceived extra dataz(Received extra packet for auth method %rzSucceed to auth):ra�server_version�splitr�r
Z
MULTI_RESULTSrUrHrr��idrrrrzr�r>r?r�rt�server_capabilitiesrvr�rxZwrap_socketr�rWr;r�r��_auth_plugin_namer
�scramble_native_passwordrV�saltr�r�Zscramble_caching_sha2ZPLUGIN_AUTH_LENENC_CLIENT_DATArIr�ZSECURE_CONNECTIONr{r��PLUGIN_AUTHZ
CONNECT_ATTRSr�r�r�Zis_auth_switch_request�
read_uint8Zread_string�
_process_auth�scramble_old_passwordZis_extra_auth_data�caching_sha2_password_auth�sha256_password_authrr�)
r�Z
charset_idZ	data_initr�Zauthresp�plugin_nameZ
connect_attrsrcrd�auth_packetr&r&r'r�
s�










z"Connection._request_authenticationcCs(|�|�}|rNz|�|�WStyL|dkrHt�dd|t|�f��Yn0|dkrbt�||�S|dkrvt�||�S|dkr�t�	|j
|���}�nv|dkr�t�|j
|���}�nX|dkr�t�
|j
|���d	}�n6|d
kr�|j
d	}�n |dk�r�|}|��}|d@dk}|d
@d
k}|��}	|	dk�r<|�|j
d	�n�|�r�d}
z|�||	�}
|�|
d	�WnRt�y�t�dd||f��Yn,t�y�t�dd|||
|	f��Yn0nt�dd||f��|��}|��|���s�|�r��q��q�|St�dd|��|�|�|��}|��|S)Nsdialog�zGAuthentication plugin '%s' not loaded: - %r missing authenticate methodrrrsclient_ed25519smysql_old_passwordr
smysql_clear_passwordr!rrs
Password: z3no response - TypeError within plugin.prompt methodzAAuthentication plugin '%s' not loaded: - %r missing prompt methodi
zTAuthentication plugin '%s' %r didn't respond with string. Returned '%r' to prompt %rz.Authentication plugin '%s' (%r) not configuredz)Authentication plugin '%s' not configured)�_get_auth_plugin_handlerZauthenticate�AttributeErrorrr�r`r
rr rrVZread_allZed25519_passwordrrr��prompt�	TypeErrorr�Zcheck_errorr�)r�r!r"�handlerr�r��flagZechoZlastr&Zrespr&r&r'rrsj

�

�

�
zConnection._process_authc	Csn|j�|�}|s,t|t�r,|j�|�d��}|rfz||�}Wqjtybt�dd||f��Yqj0nd}|S)Nr2r#zXAuthentication plugin '%s' not loaded: - %r cannot be constructed with connection object)r�rNrrr�r,r'rr�)r�r!Zplugin_classr(r&r&r'r$�s�z#Connection._get_auth_plugin_handlercCs
|jdSr)�server_thread_idr�r&r&r'r��szConnection.thread_idcCs|jSr5)r�r�r&r&r'�character_set_name�szConnection.character_set_namecCs|jSr5)r�r�r&r&r'�
get_host_info�szConnection.get_host_infocCs|jSr5)�protocol_versionr�r&r&r'�get_proto_info�szConnection.get_proto_infoc	Csd}|��}|��}t|||d��|_|d7}|�d|�}|||��d�|_|d}t�d|||d��|_	|d7}|||d�|_
|d7}t�d	|||d
��d|_|d
7}t|�|dk�rpt�d|||d��\}}}}|d7}||_
zt|�j|_Wnt�y&d|_Yn0||_t�r@td
|�|j|d>O_t�rbtd|�td|d�}|d7}t|�||k�r�|j
||||�7_
||7}|d7}|jtj@�rt|�|k�r|�d|�}|dk�r�||d��d�|_n|||��d�|_dS)Nrrr
r+r=r���	rDrr!z<BHHBzserver_status: %xr�z	salt_len:�rLr)r�Zget_all_datarr-�findr,rr>r�r*rrr�Zserver_languager�nameZserver_charset�KeyErrorr�r�r��maxr
rr)	r�r%r�r�Z
server_end�lang�statZcap_hZsalt_lenr&r&r'r��sJ 
z"Connection._get_server_informationcCs|jSr5)rr�r&r&r'�get_server_infoszConnection.get_server_info)N)N)F)F)T)N)F)A�__name__�
__module__�__qualname__�__doc__r�rr�r�rr�rwr��propertyr�r��__del__r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�rr�r�rr$r�r+r,r.r�r8r�Warningr�rZ
DatabaseErrorZ	DataErrorr�ZIntegrityErrorr�ZProgrammingErrorZNotSupportedErrorr&r&r&r'rJts�=�




	




	
J*

*h:?rJc@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)r�cCsF||_d|_d|_d|_d|_d|_d|_d|_d|_d|_	d|_
dS)z.
        :type connection: Connection
        NrF)rr�rr��
warning_count�message�field_count�descriptionr�rr�)r�rr&r&r'r�szMySQLResult.__init__cCs|jr|��dSr5)r�rr�r&r&r'r>'szMySQLResult.__del__cCsTzF|j��}|��r |�|�n|��r4|�|�n
|�|�Wd|_nd|_0dSr5)rr�r�r��is_load_local_packet�_read_load_local_packet�_read_result_packet�r��first_packetr&r&r'rn+s
zMySQLResult.readcCsld|_|j��}|��r0|�|�d|_d|_n8|��rP|�|�d|_d|_n|��|_|�	�d|_
dS)zw
        :raise OperationalError: If the connection to the MySQL server is lost.
        :raise InternalError:
        TFNl����)r�rr�r�r�rDrE�read_length_encoded_integerrB�_get_descriptionsr�rGr&r&r'r8s



z!MySQLResult.init_unbuffered_querycCs<t|�}|j|_|j|_|j|_|j|_|j|_|j|_dSr5)rr�rr�r@rAr)r�rH�	ok_packetr&r&r'r�QszMySQLResult._read_ok_packetcCsx|jjstd��t|�}t|j|j�}z|��Wn|j���Yn0|j��}|��sjt	�
dd��|�|�dS)NzF**WARN**: Received LOAD_LOCAL packet but local_infile option is false.r�zCommands Out of Sync)rrk�RuntimeErrorr�
LoadLocalFile�filenamer�r�r�rr�r�)r�rHZload_packetZsenderrKr&r&r'rEZs�

z#MySQLResult._read_load_local_packetcCs(|��sdSt|�}|j|_|j|_dS)NFT)�
is_eof_packetrr@r)r�r�Zwpr&r&r'�_check_packet_is_eofksz MySQLResult._check_packet_is_eofcCs|��|_|��|��dSr5)rIrBrJ�_read_rowdata_packetrGr&r&r'rFws
zMySQLResult._read_result_packetcCsP|js
dS|j��}|�|�r4d|_d|_d|_dS|�|�}d|_|f|_|S)NFr)r�rr�rPr��_read_row_from_packetr�)r�r��rowr&r&r'�_read_rowdata_packet_unbuffered|s


z+MySQLResult._read_rowdata_packet_unbufferedcCs,|jr(|j��}|�|�rd|_d|_qdSr�)r�rr�rP)r�r�r&r&r'r�s


z$MySQLResult._finish_unbuffered_querycCsJg}|j��}|�|�r d|_q2|�|�|��qt|�|_t|�|_dS)z:Read a rowdata packet for each data row in the result set.N)	rr�rP�appendrRr�r��tupler�)r�r�r�r&r&r'rQ�s


z MySQLResult._read_rowdata_packetc	Cs�g}|jD]p\}}z|��}Wnty6Yq|Yn0|durp|durR|�|�}tr`td|�|durp||�}|�|�q
t|�S)NzDEBUG: DATA = )rZread_length_coded_string�
IndexErrorr,r�r�rUrV)r�r�rSr��	converterr�r&r&r'rR�s
z!MySQLResult._read_row_from_packetc
Csg|_g|_|jj}|jj}g}t|j�D]�}|j�t�}|j�	|�|�	|�
��|j}|r�|tj
krn|}q�|tvr�|jdkr�d}q�|}q�d}nd}|jj�|�}|tjur�d}tr�td�||��|j�	||f�q*|j��}	|	��s�Jd��t|�|_
dS)z>Read a column descriptor packet for each column in the result.�?Nr2zDEBUG: field={}, converter={}zProtocol error, expecting EOF)�fieldsrrr�r�rrBr�rrUrCZ	type_coderZJSON�
TEXT_TYPESZ	charsetnrr�rNZthroughr�r��formatrOrV)
r�r�Z
conn_encodingrCr%ZfieldZ
field_typer�rXZ
eof_packetr&r&r'rJ�s6



zMySQLResult._get_descriptionsN)r9r:r;r�r>rnrr�rErPrFrTrrQrRrJr&r&r&r'r�s
	

r�c@seZdZdd�Zdd�ZdS)rMcCs||_||_dSr5)rNr)r�rNrr&r&r'r��szLoadLocalFile.__init__c	Cs�|jjst�dd��|j}z�zXt|jd��8}t|jd�}|�|�}|sHqT|�	|�q8Wd�n1sh0YWn&t
y�t�dd�|j���Yn0W|�	d�n|�	d�0dS)	z3Send data packets from the local file to the serverrrKr�i@Ni�zCan't find file '{0}'r))
rr�rrr�rNr	r�rnr�r�r�r\)r�ZconnZ	open_filer
�chunkr&r&r'r��s
.zLoadLocalFile.send_dataN)r9r:r;r�r�r&r&r&r'rM�srM)OZ
__future__rZ_compatrrrrrr	r�r6rorYr>rgr�rrKr
r�rrZ	constantsr
rrrrrZcursorsrZ
optionfilerZprotocolrrrrrr�utilrrrrrtru�ImportErrorZgetpassZgetuserryr4r�rhZ_py_version�ranger.r1Z	_socketior4r;ZBITZBLOBZ	LONG_BLOBZMEDIUM_BLOB�STRINGZ	TINY_BLOBZ
VAR_STRINGZVARCHARZGEOMETRYr[r�r�rArI�objectrJr�rMr&r&r&r'�<module>s�  




�
(N