HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/mysql/connector/__pycache__/protocol.cpython-39.pyc
a

�,�h���@sDdZddlmZddlZddlZddlmZddlmZm	Z	ddl
mZmZm
Z
mZmZmZmZmZmZddlmZdd	lmZmZmZmZmZdd
lmZddlmZm Z m!Z!m"Z"ddl#m#Z#dd
l$m%Z%m&Z&ddl'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0e�rddl1m2Z2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:Gdd�d�Z;dS)z,Implements the MySQL Client/Server protocol.�)�annotationsN)�deque)�Decimal�DecimalException)	�
TYPE_CHECKING�Any�Deque�Dict�List�Optional�Sequence�Tuple�Union�)�utils)�PARAMETER_COUNT_AVAILABLE�
ClientFlag�	FieldFlag�	FieldType�	ServerCmd)�MySQLConverter)�
DatabaseError�InterfaceError�ProgrammingError�
get_exception)�logger)�MySQLAuthPlugin�get_auth_plugin)�"MySQLCachingSHA2PasswordAuthPlugin)�BinaryProtocolType�DescriptionType�
EofPacketType�
HandShakeType�OkPacketType�StatsPacketType�
StrOrBytes)�MySQLSocket�
����-i@c@s�eZdZdZeddd�dd��Zeddd�dd��Zeddd�d	d
��Zeddd�d
d��Zedddd�dd��Z	ed~dddddddddd�	dd��Z
edededdddddf
ddddddddddddddd �d!d"��Z
eedefddddd#�d$d%��Zeddd&dd'�d(d)��Zed�dddd+�d,d-��Zeddd.�d/d0��Zedd1d.�d2d3��Zedd4d.�d5d6��Zed�ddd8d9�d:d;��Zdd<d.�d=d>�Zed�ddd@dA�dBdC��Zd�dDdEddFdG�dHdI�Zedd8dJdK�dLdM��Zedd8dNdK�dOdP��Zed�dddRdS�dTdU��ZedddVdW�dXdY��ZeddZd.�d[d\��Zd�d]ddd^d_�d`da�Zd�dDd]dddbdc�ddde�Zeddfd.�dgdh��Zeddidj�dkdl��Z edmdJdj�dndo��Z!edpdJdj�dqdr��Z"eddddds�dtdu��Z#d�ddwdxddyddzddd{�	d|d}�Z$dS)��
MySQLProtocolzRImplements MySQL client/server protocol

    Create and parses MySQL packets.
    �bytes)�pkt�returncCs |dtkstd��|dd�S)aParse a MySQL auth more data packet.

        Args:
            pkt: Packet representing an `auth more data` response.

        Returns:
            auth_data: Authentication method data (see [1]).

        Raises:
            InterfaceError: If packet's status tag doesn't
                            match `protocol.EXCHANGE_FURTHER_STATUS`.

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_connection_phase_packets_protocol_auth_more_data.html
        �z"Failed parsing AuthMoreData packet�N)�EXCHANGE_FURTHER_STATUSr)r.�r3�K/opt/nydus/tmp/pip-target-wkfpz8uv/lib64/python/mysql/connector/protocol.py�parse_auth_more_data\sz"MySQLProtocol.parse_auth_more_datazTuple[str, bytes]cCsV|dtkrtd��tj|dd�dd�\}}|rJ|ddkrJ|dd�}|��|fS)	a|Parse a MySQL auth switch request packet.

        Args:
            pkt: Packet representing an `auth switch request` response.

        Returns:
            plugin_name: Name of the client authentication plugin to switch to.
            plugin_provided_data: Plugin provided data (see [1]).

        Raises:
            InterfaceError: If packet's status tag doesn't
                            match `protocol.AUTH_SWITCH_STATUS`.

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/                latest/page_protocol_connection_phase_packets_protocol_
                auth_switch_request.html
        r0z'Failed parsing AuthSwitchRequest packetr1N���end���r)�AUTH_SWITCH_STATUSrr�read_string�decode)r.�plugin_namer3r3r4�parse_auth_switch_requestrsz'MySQLProtocol.parse_auth_switch_requestcCsFt�|dd�d�\}}|tkr(td��tj|dd�\}}|��|fS)a�Parse a MySQL auth next factor packet.

        Args:
            pkt: Packet representing an `auth next factor` response.

        Returns:
            plugin_name: Name of the client authentication plugin.
            plugin_provided_data: Initial authentication data for that
                                  client plugin (see [1]).

        Raises:
            InterfaceError: If packet's packet type doesn't
                            match `protocol.MFA_STATUS`.

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_connection_phase_packets_protocol_auth_                next_factor_request.html
        r0Nrz.Failed parsing AuthNextFactor packet (invalid)r6r7)r�read_int�
MFA_STATUSrr;r<)r.�statusr=r3r3r4�parse_auth_next_factor�s
z$MySQLProtocol.parse_auth_next_factorzDict[str, str])�
conn_attrsr/c	s��D]}�|durd�|<qt�fdd��D��t����t����}t�d|�g}�D]T}|�t�dt|���|�|���|�t�dt�|���|��|���q^d�|�S)azEncode the connection attributes.

        Args:
            conn_attrs: Connection attributes.

        Returns:
            serialized_conn_attrs: Serialized connection attributes as per [1].

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_connection_phase_packets_protocol_handshake_response.html
        N�c3s"|]}t|�t�|�VqdS)N)�len)�.0�x�rCr3r4�	<genexpr>��z0MySQLProtocol.make_conn_attrs.<locals>.<genexpr>�<BrJ)	�sumrE�keys�values�struct�pack�append�encode�join)rC�	attr_nameZconn_attrs_lenZconn_attrs_packetr3rHr4�make_conn_attrs�s 

�
��zMySQLProtocol.make_conn_attrs�intz
Optional[str])�client_flags�databaser/cCs|tj@r|r|��dSdS)a�Prepare database string for handshake response.

        Args:
            client_flags: Integer representing client capabilities flags.
            database: Initial database name for the connection.

        Returns:
            serialized_database: Serialized database name as per [1].

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_connection_phase_packets_protocol_handshake_response.html
        r6)rZCONNECT_WITH_DBrR)rWrXr3r3r4�connect_with_db�s���zMySQLProtocol.connect_with_dbNF�str�boolzOptional[Dict[str, Any]]zTuple[bytes, MySQLAuthPlugin])	�	auth_data�username�passwordrW�auth_plugin�auth_plugin_class�ssl_enabled�
plugin_configr/c
Cs�|sdt|||d�fS|dur"i}z*t||�|||d�}|j|fi|��}	Wn8ttfy�}
ztd|
���|
�WYd}
~
n
d}
~
00|	dur�td|j����|tj@r�t�	t
|	��|	n|	d}	|	|fS)aPrepare the first authentication response.

        Args:
            auth_data: Authorization data from initial handshake.
            username: Account's username.
            password: Account's password.
            client_flags: Integer representing client capabilities flags.
            auth_plugin: Authorization plugin name.
            auth_plugin_class: Authorization plugin class (has higher precedence
                               than the authorization plugin name).
            ssl_enabled: Whether SSL is enabled or not.
            plugin_config: Custom configuration to be passed to the auth plugin
                           when invoked. The parameters defined here will override
                           the ones defined in the auth plugin itself.

        Returns:
            auth_response: Authorization plugin response.
            auth_strategy: Authorization plugin instance created based
                           on the provided `auth_plugin` and `auth_plugin_class`
                           parameters.

        Raises:
            InterfaceError: If authentication fails or when got a NULL auth response.
        r6)raNzFailed authentication: z8Got NULL auth response while authenticating with plugin )rr�
auth_response�	TypeErrorr�namer�SECURE_CONNECTIONr�	int1storerE)r\r]r^rWr_r`rarb�
auth_strategyrc�errr3r3r4�auth_plugin_first_response�s0#��&����z(MySQLProtocol.auth_plugin_first_responserr"zOptional[Dict[str, str]])�	handshaker]r^rX�charsetrW�max_allowed_packetr_r`rC�is_change_user_requestrarbr/c

Cs�|��}
g}|
rt�d�t�d�|dur6td�d�|�d�durNtd�d�z|pZ|d}Wn:ttfy�}ztd|�d	��d�WYd}~n
d}~00t�d
|�|
r�|�t�	dt
|
��d�tj|
��n,d
}|�t�	d|�t
|
��d�||||
��t
j|d|||||||d�\}}|�|�|�t
�||��|
�rP|�t�	d|��|tj@�rn|�|��d�|tj@�r�|	du�r�|�t
�|	��d�|�|fS)a�Make a MySQL Authentication packet.

        Args:
            handshake: Initial handshake.
            username: Account's username.
            password: Account's password.
            database: Initial database name for the connection
            charset: Client charset (see [2]), only the lower 8-bits.
            client_flags: Integer representing client capabilities flags.
            max_allowed_packet: Maximum packet size.
            auth_plugin: Authorization plugin name.
            auth_plugin_class: Authorization plugin class (has higher precedence
                               than the authorization plugin name).
            conn_attrs: Connection attributes.
            is_change_user_request: Whether is a `change user request` operation or not.
            ssl_enabled: Whether SSL is enabled or not.
            plugin_config: Custom configuration to be passed to the auth plugin
                           when invoked. The parameters defined here will override
                           the one defined in the auth plugin itself.

        Returns:
            handshake_response: Handshake response as per [1].
            auth_strategy: Authorization plugin instance created based
                           on the provided `auth_plugin` and `auth_plugin_class`.

        Raises:
            ProgrammingError: Handshake misses authentication info.

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_connection_phase_packets_protocol_handshake_response.html

            [2]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_basic_character_set.html#a_protocol_character_set
        zGot a `change user` requestzStarting authorization phaseNzGot a NULL handshaker\z$Handshake misses authentication infor_z-Handshake misses authentication plugin info (�)z#The provided initial strategy is %srKZsxZxxxxxxxxxxxxxxxxxxxxxxz<IIH)r\r]r^rWr_r`rarb�<Hr6rJ)rRr�debugr�getrd�KeyErrorrQrOrPrErZCHANGE_USERr,rjrYr�PLUGIN_AUTHZCONNECT_ARGSrUrS)rkr]r^rXrlrWrmr_r`rCrnrarbZ
b_usernameZresponse_payloadri�fillerrcrhr3r3r4�	make_authsn3




�������


zMySQLProtocol.make_auth)rlrWrmr/cCs$d�t�|�t�|�t�|�dg�S)a�Make a SSL authentication packet (see [1]).

        Args:
            charset: Client charset (see [2]), only the lower 8-bits.
            client_flags: Integer representing client capabilities flags.
            max_allowed_packet: Maximum packet size.

        Returns:
            ssl_request_pkt: SSL connection request packet.

        References:
            [1]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_connection_phase_packets_protocol_ssl_request.html

            [2]: https://dev.mysql.com/doc/dev/mysql-server/latest/                page_protocol_basic_character_set.html#a_protocol_character_set
        rJs�rSr�	int4store�	int2store)rlrWrmr3r3r4�
make_auth_ssl�s��zMySQLProtocol.make_auth_sslzOptional[bytes])�command�argumentr/cCst�|�}|dur|S||S)z(Make a MySQL packet containing a commandN)rrg)r{r|�datar3r3r4�make_command�s
zMySQLProtocol.make_commandr)�statement_id�rowsr/cCst�|�t�|�S)z0Make a MySQL packet with Fetch Statement command)rrx)rr�r3r3r4�make_stmt_fetch�szMySQLProtocol.make_stmt_fetch)�packetr/c		Cs�i}t�d|dd��d|d<|dtkrDtd|d�dt����tj|dd�dd	�\}|d
<t�d|dd��\|d
<}}|d<|d<}}|d
��|d
<|dd�}t�||�}d}|tj	@�r|r�t
d|d�nd}|d|�}||d�}|ddk�r|dd�}|tj@�rrd|v�rH|d
�d��rHd|}|d<ntj|dd	�\}|d<|d�d�|d<nd|d<|||d<||d<|S)zParse a MySQL Handshake-packet.�<xxxxBrr1�protocolz$Protocol mismatch; server version = z, client version = Nr6r7Zserver_version_originalz<I8sx2sBH2sBxxxxxxxxxx�Zserver_threadidrlZ
server_statusrJ�
�r9z5.5.8r_�utf-8Zmysql_native_passwordr\�capabilities)
rO�unpack�PROTOCOL_VERSIONrrr;r<Zintreadrrf�minrt�
startswith)	r��resZ
auth_data1Z
capabilities1Z
capabilities2Zauth_data_lengthr�Z
auth_data2�sizer3r3r4�parse_handshake�sR�����zMySQLProtocol.parse_handshaker#c
Cs�|ddkstd��i}z�t�d|dd��d|d<t�|dd��\}|d<t�|�\}|d	<t�d
|dd��\|d<|d<|dd�}|r�t�|�\}|d
<|d
�d�|d
<Wn.ty�}ztd�|�WYd}~n
d}~00|S)zParse a MySQL OK-packetr0rz#Failed parsing OK packet (invalid).r�r1Zfield_countNZ
affected_rowsZ	insert_idz<HH�status_flag�
warning_countZinfo_msgr�zFailed parsing OK packet.)rrOr�r�read_lc_int�read_lc_stringr<�
ValueError)r�Z	ok_packetrir3r3r4�parse_ok�s$� zMySQLProtocol.parse_okz
Optional[int]c
CsVzt�|dd��d}|WStjtfyP}ztd�|�WYd}~n
d}~00dS)z=Parse a MySQL packet with the number of columns in result setr0NrzFailed parsing column count)rr�rO�errorr�r)r��countrir3r3r4�parse_column_counts
z MySQLProtocol.parse_column_countr�r )r��encodingr/c	Cs�t�|dd��\}}t�|�\}}t�|�\}}t�|�\}}t�|�\}}t�|�\}}zt�d|�\}}}}}Wntjy�td�d�Yn0|�|�|dddd|tj@||f	S)zParse a MySQL column-packet.r0Nz	<xHIBHBxxz!Failed parsing column information)	rr�rOr�r�rr<rZNOT_NULL)r�r��_rerlZcolumn_type�flagsr3r3r4�parse_columns6
��
�zMySQLProtocol.parse_columnr!c
Cs�|ddkr|�|�Sd}i}zt�d|�}Wn0tjy^}zt|�|�WYd}~n
d}~00|ddkrxt|�dks�t|��|d	|d
<|d|d<|S)
zParse a MySQL EOF-packetr0rzFailed parsing EOF packet.z<xxxBBHHNrr(�	r)r��r�)r�rOr�r�rrE)�selfr��err_msgr��unpackedrir3r3r4�	parse_eof:s
 zMySQLProtocol.parse_eofTr$)r��with_headerr/c	Cs"d}i}dg}d}|r*|dd��d�}n
|�d�}|D]�}zdd�|�dd	�D�\}}Wn.ty�}zt|�|�WYd}~n
d}~00|�d
�}zt|�||<Wq8ttf�yzt|�d
��||<WnFt�y}z,t|�d|�dt|��d
��|�WYd}~n
d}~00Yq80q8|S)zParse the statistics packetz)Failed getting COM_STATISTICS informationrJr0Ns  cSsg|]}|���qSr3)�strip)rF�vr3r3r4�
<listcomp>\rJz2MySQLProtocol.parse_statistics.<locals>.<listcomp>�:r)r�z (�:ro)	�splitr�rr<rVrsrr�repr)	r�r��errmsgr��pairsZlbl�pair�valrir3r3r4�parse_statisticsNs*
 
>zMySQLProtocol.parse_statisticsr&zTuple[int, ...]zATuple[List[Tuple[Optional[bytes], ...]], Optional[EofPacketType]])�sock�versionr�r/cCs"|}g}d}d}d}|s ||kr$�q|��}	|	�d�r�|	dd�g}
|��}	|	�d�rr|
�|	dd��|��}	qL|
�|	dd��t�d�|
��}nB|	ddkr�|	ddkr�|�|	�}d}nd}t�t|	dd���}|dur�|dur�|�|�n|du�r|du�rt|	��|d7}q||fS)	z�Read MySQL text result

        Reads all or given number of rows from the socket.

        Returns a tuple with 2 elements: a list with all rows and
        the EOF packet.
        Nrs���r0rJr(�r)	�recvr�rQrZread_lc_string_listrSr�r-r)r�r�r�r�r�r��eofZrowdata�ir�Zdatasr3r3r4�read_text_resultks6




zMySQLProtocol.read_text_resultzTuple[bytes, int])r��fieldr/cCs�|dtjkrd}d}nL|dtjkr0d}d}n4|dtjtjfvrNd}d}n|dtjkrdd}d}|d	tj@rz|��}||d
�t	�
||d|��dfS)z%Parse an integer from a binary packetr�<b�<hr)�<ir0�<qr�r�Nr)r�TINY�SHORT�INT24�LONG�LONGLONGrZUNSIGNED�upperrOr�)r�r��format_�lengthr3r3r4�_parse_binary_integer�sz#MySQLProtocol._parse_binary_integerzTuple[bytes, float]cCsD|dtjkrd}d}nd}d}||d�t�||d|��dfS)z)Parse a float/double from a binary packetrr��<dr0z<fNr)r�DOUBLErOr�)r�r�r�r�r3r3r4�_parse_binary_float�sz!MySQLProtocol._parse_binary_float�utf8zTuple[bytes, Decimal])r�rlr/cCs t�|�\}}|t|�|��fS)z(Parse a New Decimal from a binary packet)rr�rr<)r�rl�valuer3r3r4�_parse_binary_new_decimal�sz'MySQLProtocol._parse_binary_new_decimalz?Tuple[bytes, Optional[Union[datetime.date, datetime.datetime]]])r��
field_typer/c	Cs�|d}d}|dkrpt�d|dd��d}|d}|d}|tjtjfvr^tj|||d�}q�tj|||d�}np|dkr�d}|d	kr�t�d
|d|d��d}tjt�d|dd��d|d|d|d|d
|d|d�}||dd�|fS)z&Parse a timestamp from a binary packetrNr0rprr�)�year�month�dayr���<Ir�r1�)r�r�r��hour�minute�second�microsecond)rOr�r�DATETIME�	TIMESTAMP�datetime�date)r�r�r�r�r�r�r��mcsr3r3r4�_parse_binary_timestamp�s.�
z%MySQLProtocol._parse_binary_timestampz Tuple[bytes, datetime.timedelta]cCs�|d}|s |dd�t��fS|d|d�}d}|dkrTt�d|dd��d}t�d|dd��d}|ddkr�|d9}tj||d||d	|dd
�}||dd�|fS)z'Parse a time value from a binary packetrrNr�r�r1r9r�r�)�days�seconds�microseconds�minutes�hours)r��	timedeltarOr�)r�r�r}r�r��tmpr3r3r4�_parse_binary_time�s$�z MySQLProtocol._parse_binary_timezList[DescriptionType]zTuple[BinaryProtocolType, ...])�fieldsr�rlr/c
	Cs6t|�ddd}dd�|d|�D�}||d�}g}d}t|�D�]�\}}	|t|dd�d|dd>@r�|�d�qF|	dtjtjtjtjtj	fvr�|�
||	�\}}|�|�qF|	dtjtjfvr�|�
||	�\}}|�|�qF|	dtjtjfv�r|�||�\}}|�|�qF|	dtjtjtjfv�rX|�||	d�\}}|�|�qF|	dtjk�r�|�|�\}}|�|�qF|	dtjk�r�t�|�\}}|�t�|��qF|	dtjk�s�|	dd	k�r�t�|�\}}|�|�qFt�|�\}}z|�|�|��WqFt�y*|�|�YqF0qFt |�S)
z(Parse values from a binary result packetr�r)r�cSsg|]}t|��qSr3)rV)rFr�r3r3r4r�rJz6MySQLProtocol._parse_binary_values.<locals>.<listcomp>rNr�?)!rE�	enumeraterVrQrr�r�r�r�r�r�r��FLOATr��DECIMALZ
NEWDECIMALr�r��DATEr�r��TIMEr�ZVECTORrr�rZ_vector_to_pythonrZBINARYr<�UnicodeDecodeError�tuple)
r�r�r�rlZnull_bitmap_length�null_bitmaprNr��posr�r3r3r4�_parse_binary_values�s\$
��z"MySQLProtocol._parse_binary_valueszDTuple[List[Tuple[BinaryProtocolType, ...]], Optional[EofPacketType]])r��columnsr�rlr/c
Cs�g}d}d}d}|durq�||kr$q�t|���}	|	ddkrL|�|	�}d}n&|	ddkrrd}|�||	dd�|�}|dur�|dur�|�|�n|dur�|dur�t|	��|d7}q||fS)zwRead MySQL binary protocol result

        Reads all or given number of binary resultset rows from the socket.
        Nrr0r(r1r)r-r�r�r�rQr)
r�r�r�r�rlr�r�rNr�r�r3r3r4�read_binary_result5s*

z MySQLProtocol.read_binary_resultzDict[str, int]c
Cs�|ddkstd��i}zht�|dd�d�\}|d<t�|d�\}|d<t�|d�\}|d	<|d
d�}t�|d�\}|d<Wn.ty�}ztd�|�WYd}~n
d}~00|S)z(Parse a MySQL Binary Protocol OK packet.r0rzFailed parsing Binary OK packetr1Nrr)Znum_columnsZ
num_paramsrr�)rrr?r�)r�Zok_pktrir3r3r4�parse_binary_prepare_okZs z%MySQLProtocol.parse_binary_prepare_okzTuple[bytes, int, int])r�r/cCs�d}d}|dkrX|dkr$d}tj}q�|dkr8d}tj}q�|dkrLd}tj}q�d	}tj}nJd
}|dkrpd}tj}n2|d
kr�d}tj}n|dkr�d}tj}n
tj}d}t�||�||fS)z0Prepare an integer for the MySQL binary protocolNri����r�i���r�i�r�r��r*rKi��rpl��r�z<Q)rr�r�r�r�rOrP)r�r�r�r�r3r3r4�prepare_binary_integerls6z$MySQLProtocol.prepare_binary_integerz'Union[datetime.date, datetime.datetime]cCs�t|tj�rtj}nt|tj�r(tj}ntd��t�|j	�t�
|j�t�
|j�g}t|tj�r�|�
t�
|j�t�
|j�t�
|j�g�|jdkr�|�t�|j��d�|�}t�
t|��||fS)a�Prepare a timestamp object for the MySQL binary protocol

        This method prepares a timestamp of type datetime.datetime or
        datetime.date for sending over the MySQL binary protocol.
        A tuple is returned with the prepared value and field type
        as elements.

        Raises ValueError when the argument value is of invalid type.

        Returns a tuple.
        z2Argument must a datetime.datetime or datetime.daterrJ)�
isinstancer�rr�r�r�r�rryr�rgr�r��extendr�r�r�r�rQrxrSrE)r�r��chunks�packedr3r3r4�prepare_binary_timestamp�s(


�


��

z&MySQLProtocol.prepare_binary_timestampz(Union[datetime.timedelta, datetime.time]c
Cst|tjtjf�std��tj}d}d}tg�}t|tj�r�|jdkrJd}t	|j
d�\}}t	|d�\}}|�t�
t|j��t�|�t�|�t�|�g�|j}n6|�t�
d�t�|j�t�|j�t�|j�g�|j}|r�|�t�
|��|�t�|��d�|�}	t�t|	��|	|fS)a�Prepare a time object for the MySQL binary protocol

        This method prepares a time object of type datetime.timedelta or
        datetime.time for sending over the MySQL binary protocol.
        A tuple is returned with the prepared value and field type
        as elements.

        Raises ValueError when the argument value is of invalid type.

        Returns a tuple.
        z3Argument must a datetime.timedelta or datetime.timerNri�<rJ)r�r�r��timer�rr�rr��divmodr�r�rrx�absrgr�r�r�r�r�rQ�
appendleftrSrE)
r�r��negativer�r�r��	remainderZminsZsecsr�r3r3r4�prepare_binary_time�s@
��


��
z!MySQLProtocol.prepare_binary_time)�	statement�paramr}r/cCsd�t�|�t�|�|g�S)zMPrepare long data for prepared statements

        Returns a string.
        rJrw)rrr}r3r3r4�prepare_stmt_send_long_data�sz)MySQLProtocol.prepare_stmt_send_long_datar3zSequence[BinaryProtocolType]rz Optional[Dict[int, Tuple[bool]]]z.Optional[List[Tuple[str, BinaryProtocolType]]])	rr}�
parametersr��long_data_usedrl�query_attrs�converter_str_fallbackr/c		Csd}	dgt|�dd}
g}g}d}
t|�}g}|s:|n|t}|dkrNd}|durZi}|r�t|�}|D]\}}|�|�qjdgt|�dd}
|s�|�r*|t|�kr�td	��t|�D�]l\}}d}|du�r|
|dd|d>O<|�t�tj	�t�|��q�||v�r6||d�r,tj
}ntj}�n�t|t
��r`|�|�\}
}}|�|
��npt|t��r�|�|�}|�t�t|��|�tj}�n8t|t��r�|�t�t|��|�tj}�n
t|t��r|�t�tt|��|���t|��|��tj}n�t|t��r,|�t�d
|��tj}n�t|tjtjf��rZ|�|�\}
}|�|
�nvt|tjtjf��r�|�|�\}
}|�|
�nH|�r�t|��|�}|�t�t|��|�tj}ntd|j j!�d���|�t�|�t�|��|r�|d|kr�|||d�|�}|�t�t|��|�q�t�"|�t�|�t�"|	�g}|du�r^|t|�}n|}|�r|du�r�|�t�|��|�#d
d�|
D��|�t�d��d}|D]N}|�|�|du�r�|d|k�r�|�|||�n
|�d�|d7}�q�|D]}|�|��qd�$|�S)z6Make a MySQL packet with the Statement Execute commandrrr�r�rJZutf8mb4r�NzTFailed executing prepared statement: data values does not match number of parametersr�z&MySQL binary protocol can not handle 'z	' objectscSsg|]}t�d|��qS)�B)rOrP)rF�bitr3r3r4r�jrJz3MySQLProtocol.make_stmt_execute.<locals>.<listcomp>r6)%rEr�listrQrr�rrgrZNULLZBLOB�STRINGr�rVr�rZrRZlc_intr-rr��floatrOrPr�r�r�r�r�r�rr�	__class__�__name__rxr�rS)r�rr}rr�rrlrr	Ziteration_countr�rN�typesr��data_lenZquery_attr_namesr��attr_valr�r��_flagsr�rer�Zparameter_countr��a_typeZa_valuer3r3r4�make_stmt_execute�s�
�
�

�


�����




zMySQLProtocol.make_stmt_execute)NFN)N)r)r�)T)r)r�)r�)rr�)r3r3rNr�NF)%r�
__module__�__qualname__�__doc__�staticmethodr5r>rBrUrYrj�DEFAULT_CHARSET_ID�DEFAULT_MAX_ALLOWED_PACKETrvrzr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr3r3r3r4r,Vs��"A�,z� 3 �,
��>�%!*7
�r,)<r�
__future__rr�rO�collectionsr�decimalrr�typingrrrr	r
rrr
rrDr�	constantsrrrrr�
conversionr�errorsrrrrrZpluginsrrZplugins.caching_sha2_passwordrrrr r!r"r#r$r%�networkr&r�r:r2Z	OK_STATUSr@Z
ERR_STATUSrrr,r3r3r3r4�<module>s2,$