
    *h3                    Z   S r SSKJr  SSKrSSKrSSKJr  SSKJrJ	r	  SSK
JrJrJrJrJrJrJrJrJr  SSKJr  SS	KJrJrJrJrJr  SS
KJr  SSKJrJ r J!r!J"r"  SSK#J#r#  SSK$J%r%J&r&  SSK'J(r(  SSK)J*r*J+r+J,r,J-r-J.r.J/r/J0r0  \(       a  SSK1J2r2  Sr3Sr4Sr5Sr6Sr7Sr8Sr9Sr:Sr;Sr< " S S5      r=g)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                     \ rS rSrSr\S%S j5       r\S&S j5       r\S&S j5       r\S'S j5       r	\S(S j5       r
\   S)               S*S
 jj5       r\S\S\SSSS	S	S4
                           S+S jj5       r\\S\4       S,S jj5       r\S-S.S jj5       r\S/S0S jj5       r\S1S j5       r\S2S j5       r\S3S j5       r\S4S5S jj5       rS6S jr\S7S8S jj5       r  S9         S:S jjr\      S;S j5       r\      S<S j5       r\ S=     S>S jj5       r\      S?S j5       r\S@S j5       r S4       SAS jjr   SB           SCS jjr\SDS j5       r \SES j5       r!\    SFS  j5       r"\    SGS! j5       r#\SHS" j5       r$       SI                 SJS$ jjr%S#r&g)KMySQLProtocolX   zJImplements MySQL client/server protocol

Create and parses MySQL packets.
c                <    U S   [         :X  d  [        S5      eU S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   )pkts    P/var/www/auris/envauris/lib/python3.13/site-packages/mysql/connector/protocol.pyparse_auth_more_data"MySQLProtocol.parse_auth_more_data^   s(    $ 1v00 !EFF12w    c                    U S   [         :w  a  [        S5      e[        R                  " U SS SS9u  pU (       a  U S   S:X  a  U SS n UR	                  5       U 4$ )	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
r2   z'Failed parsing AuthSwitchRequest packetr3   N    endr   )AUTH_SWITCH_STATUSr   r   read_stringdecode)r5   plugin_names     r6   parse_auth_switch_request'MySQLProtocol.parse_auth_switch_requestt   sd    ( q6'' !JKK ,,SW'B3r7a<cr(C!!#S((r9   c                    [         R                  " U SS S5      u  pU[        :w  a  [        S5      e[         R                  " U SS9u  pUR                  5       U 4$ )aF  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
r2   Nr   z.Failed parsing AuthNextFactor packet (invalid)r;   r<   )r   read_int
MFA_STATUSr   r@   rA   )r5   statusrB   s      r6   parse_auth_next_factor$MySQLProtocol.parse_auth_next_factor   sY    * nnSWa0Z !QRR ,,Sg>!!#S((r9   c           
     j  ^  T  H  nT U   b  M  ST U'   M     [        U 4S jT  5       5      [        T R                  5       5      -   [        T R                  5       5      -   n[        R
                  " SU5      /nT  H  nUR                  [        R
                  " S[        U5      5      5        UR                  UR                  5       5        UR                  [        R
                  " S[        T U   5      5      5        UR                  T U   R                  5       5        M     SR                  U5      $ )aB  Encode 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
 c              3  X   >#    U  H  n[        U5      [        TU   5      -   v   M!     g 7fN)len).0x
conn_attrss     r6   	<genexpr>0MySQLProtocol.make_conn_attrs.<locals>.<genexpr>   s#     @ZAZ]++Zs   '*<Br9   )	sumrO   keysvaluesstructpackappendencodejoin)rR   	attr_nameconn_attrs_lenconn_attrs_packets   `   r6   make_conn_attrsMySQLProtocol.make_conn_attrs   s    $I)$,(*
9% $ @Z@@*//#$%*##%&' 	 $[[~>?#I$$V[[s9~%FG$$Y%5%5%78$$V[[s:i;P7Q%RS$$Z	%:%A%A%CD	 $
 xx)**r9   c                j    U [         R                  -  (       a  U(       a  UR                  5       S-   $ S$ )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
r;   )r   CONNECT_WITH_DBr\   )client_flagsdatabases     r6   connect_with_dbMySQLProtocol.connect_with_db   s4    " j888X OO'	
 	
r9   NFc                T   U(       d  US:X  a  S[        XUS94$ Uc  0 n [        X45      " XUS9nUR                  " U 40 UD6nUc  [	        SUR
                   35      e[        R                  " [        U5      5      U-   nX4$ ! [        [        4 a  n	[	        SU	 35      U	eSn	A	ff = f)a  Prepare 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.
rL   r;   )ssl_enabledNzFailed authentication: z8Got NULL auth response while authenticating with plugin )	r   r   auth_response	TypeErrorr   namer   lc_intrO   )
	auth_datausernamepasswordauth_pluginauth_plugin_classrj   plugin_configauth_strategyrk   errs
             r6   auth_plugin_first_response(MySQLProtocol.auth_plugin_first_response   s    D K2->    M	K+KKM *77	S]SM   ',,-/ 
 S%78=H++ >* 	K #:3%!@AsJ	Ks   #B B'B""B'r   c           
        UR                  5       n/ nU
(       a  [        R                  " S5        [        R                  " S5        U c  [        S5      SeU R	                  S5      c  [        S5      Se U=(       d    U S   n[        R                  " S
U5        U
(       aC  UR                  [        R                  " S[        U5       S3[        R                  U5      5        O:SnUR                  [        R                  " SU [        U5       S3UUUU5      5        [        R                  U S   UUUUUUS9u  nnUR                  U5        UR                  [        R                  XS5      5        U
(       a&  UR                  [        R                  " SU5      5        U[         R"                  -  (       a"  UR                  UR                  5       S-   5        U[         R$                  -  (       a'  U	b$  UR                  [        R'                  U	5      5        SR)                  U5      U4$ ! [
        [        4 a  n[        SU S	35      SeSnAff = f)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
zGot a `change user` requestzStarting authorization phaseNzGot a NULL handshakero   z$Handshake misses authentication inforr   z-Handshake misses authentication plugin info ()z#The provided initial strategy is %srU   sxxxxxxxxxxxxxxxxxxxxxxxxz<IIB)ro   rp   rq   rr   rs   rj   rt   <Hr;   r9   )r\   r   debugr   getrl   KeyErrorr[   rY   rZ   rO   r   CHANGE_USERr/   rw   rg   r   PLUGIN_AUTHCONNECT_ARGSra   r]   )	handshakerp   rq   rf   charsetre   max_allowed_packetrr   rs   rR   is_change_user_requestrj   rt   
b_usernameresponse_payloadrv   fillerrk   ru   s                      r6   	make_authMySQLProtocol.make_auth  s*   f __&
!LL6734"#9:D==%-"#IJPTT	%A=)AK 	:KH!##Z),)) F##6(3z?"326 & (5'O'O,#/#' (P (
$} 	. 	 = =l UV "##FKKg$>? *000##K$6$6$87$BC :222
8N##M$A$A*$MNxx()=88m 8$ 	"?uAF	s   4H* *I:I

Ic                    SR                  [        R                  " U5      [        R                  " U5      [        R                  " U 5      S/5      $ )aC  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
r9   s                          )r]   r   	int4store	int1store)r   re   r   s      r6   make_auth_sslMySQLProtocol.make_auth_ssl  sB    0 xx- 23(	
 	
r9   c                @    [         R                  " U 5      nUc  U$ X!-   $ )z(Make a MySQL packet containing a command)r   r   )commandargumentdatas      r6   make_commandMySQLProtocol.make_command  s$     w''t<T_<r9   c                \    [         R                  " U 5      [         R                  " U5      -   $ )z0Make a MySQL packet with Fetch Statement command)r   r   )statement_idrowss     r6   make_stmt_fetchMySQLProtocol.make_stmt_fetch  s!     |,ut/DDDr9   c           	        0 n[         R                  " SU SS 5      S   US'   US   [        :w  a  [        SUS    S[         35      e[        R
                  " U SS SS	9u  oS
'   [         R                  " SU SS 5      u  US'   nnUS'   US'   nnUS
   R                  5       US
'   U SS n [        R                  " X4-   5      nSnU[        R                  -  (       a/  U(       a  [        SUS-
  5      OSnU SU nXS n US   S:X  a  USS nU[        R                  -  (       aY  SU ;  a!  US
   R                  S5      (       a  SU soS'   O[        R
                  " U SS	9u  oS'   US   R                  S5      US'   OSUS'   X'-   US'   XaS'   U$ )zParse a MySQL Handshake-packet.<xxxxBr   r3   protocolz$Protocol mismatch; server version = z, client version = Nr;   r<   server_version_originalz<I8sx2sBH2sBxxxxxxxxxx   server_threadidr   server_statusr9         r>   z5.5.8rr   utf-8mysql_native_passwordro   capabilities)rY   unpackPROTOCOL_VERSIONr   r   r@   rA   intreadr   SECURE_CONNECTIONminr   
startswith)	packetres
auth_data1capabilities1capabilities2auth_data_lengthr   
auth_data2sizes	            r6   parse_handshakeMySQLProtocol.parse_handshake  s     --&1+>qAJz?..6s:6G H$$4#57  271B1B12JG2
.-. MM2F1RLA	
!"	N ),-F)G)N)N)P%&}}]%BC
*6664D3r+a/0"D$JE]F"~"'_
*000f$-F)G)R)R* * 14V,]+/4/@/@W/U,]+!$]!3!:!:7!CC!8C%2K*N
r9   c                   U S   S:X  d  [        S5      e0 n [        R                  " SU SS 5      S   US'   [        R                  " U SS 5      u  oS'   [        R                  " U 5      u  oS	'   [        R                  " S
U SS 5      u  US'   US'   U SS n U (       a2  [        R
                  " U 5      u  oS'   US   R                  S5      US'   U$ ! [         a  n[        S5      UeSnAff = f)zParse a MySQL OK-packetr2   r   z#Failed parsing OK packet (invalid).r   r3   field_countNaffected_rows	insert_idz<HHstatus_flagwarning_countinfo_msgr   zFailed parsing OK packet.)r   rY   r   r   read_lc_intread_lc_stringrA   
ValueError)r   	ok_packetrv   s      r6   parse_okMySQLProtocol.parse_ok  s    ayA~ !FGG		G'-}}Xva{'KA'NIm$161B1B6!":1N.Fo.-2->->v-F*Fk* eVAa[1-(/*ABZF050D0DV0L-*-(1*(=(D(DW(M	*%   	G !<=3F	Gs   B:C 
C/C**C/c                     [         R                  " U SS 5      S   nU$ ! [        R                  [        4 a  n[        S5      UeSnAff = f)z=Parse a MySQL packet with the number of columns in result setr2   Nr   zFailed parsing column count)r   r   rY   errorr   r   )r   countrv   s      r6   parse_column_count MySQLProtocol.parse_column_count  sQ    	I%%fQRj1!4ELj) 	I !>?SH	Is     AAAc           	        [         R                  " U SS 5      u  p[         R                  " U 5      u  p[         R                  " U 5      u  p[         R                  " U 5      u  p[         R                  " U 5      u  p[         R                  " U 5      u  p [        R                  " SU 5      u  nnnnnUR                  U5      USSSSU) [        R                  -  UU4	$ ! [        R                   a    [        S5      Sef = f)zParse a MySQL column-packet.r2   Nz	<xHIBHBxxz!Failed parsing column information)	r   r   rY   r   r   r   rA   r   NOT_NULL)r   encoding_rm   r   column_typeflagss          r6   parse_columnMySQLProtocol.parse_column  s    ((4	((0	((0	((0	++F3((0			P k62 KK!FY'''

 
	
 || 	P !DE4O	Ps   C !C?c                (   US   S:X  a  U R                  U5      $ Sn0 n [        R                  " SU5      nUS   S:X  a  [        U5      S::  d  [	        U5      eUS	   US
'   US   US'   U$ ! [        R                   a  n[	        U5      UeSnAff = f)zParse a MySQL EOF-packetr2   r   zFailed parsing EOF packet.z<xxxBBHHNr   r)   	   r*   r      r   )r   rY   r   r   r   rO   )selfr   err_msgr   unpackedrv   s         r6   	parse_eofMySQLProtocol.parse_eof6  s    !9>==((.	3}}Z8H s"s6{a'7 ))'{O%a[M
 || 	3 )s2	3s   A, ,B BBc                6   Sn0 nS/nSnU(       a  U SS R                  S5      nOU R                  S5      nU HU  n UR                  SS5       Vs/ s H  owR                  5       PM     snu  pXUR	                  S5      n [        U5      X5'   MW     U$ s  snf ! [         a  n	[        U5      U	eSn	A	ff = f! [        [        4 aQ     [        UR	                  S5      5      X5'    M  ! [         a#  n	[        U S	U S
[        U5       S35      U	eSn	A	ff = ff = f)zParse the statistics packetz)Failed getting COM_STATISTICS informationr9   r2   Ns        :r*   r   z (:rz   )
splitstripr   r   rA   intr   r   r   repr)
r   with_headererrmsgr   pairslblpairvvalrv   s
             r6   parse_statisticsMySQLProtocol.parse_statisticsJ  s*    =.012J$$[1ELL-ED6/3zz$/BC/B!GGI/BC
 **W%CSs8  
 D 6$V,#56 j) SS&szz'':;CH' S(F82cU!DI;a)HIsRSSsS   BB*BB7B
B4#B//B47DC''
D1DDDc                   Un/ nSnSnSn	 U(       d  X:X  a   Xg4$ UR                  U5      n
U
R                  S5      (       a  U
SS /nUR                  U5      n
U
R                  S5      (       a=  UR                  U
SS 5        UR                  U5      n
U
R                  S5      (       a  M=  UR                  U
SS 5        [        R                  " SR                  U5      5      nOJU
S   S:X  a  U
S   S:  a  U R                  U
5      nSnO$Sn[        R                  " [        U
SS 5      5      nUc  Ub  UR                  U5        OUc  Uc  [        U
5      eU	S-  n	GMV  )	zRead 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.
Nr   s   r2   r9   r)      r   )	recvr   r[   r   read_lc_string_listr]   r   bytesr   )r   sockversionr   read_timeoutr   r   eofrowdatair   datass               r6   read_text_resultMySQLProtocol.read_text_resultg  sa   $ aj* y) YY|,F  11<0''88LL,!YY|4F ''88 VABZ(33CHHUODc!fQi!mnnV,33E&*4EF{w2G$#F++FA- r9   c                   US   [         R                  :X  a  SnSnOoUS   [         R                  :X  a  SnSnOSUS   [         R                  [         R                  4;   a  SnSnO'US   [         R
                  :X  a  SnSnO[        S	5      eUS
   [        R                  -  (       a  UR                  5       nXS [        R                  " X SU 5      S   4$ )z%Parse an integer from a binary packetr   <b<hr*   <ir2   <qr   zUnknown integer typer   Nr   )r   TINYSHORTINT24LONGLONGLONGr   r   UNSIGNEDupperrY   r   )r   fieldformat_lengths       r6   _parse_binary_integer#MySQLProtocol._parse_binary_integer  s    
 8y~~%GF1X(GF1X)//9>>::GF1X+++GF 3448i(((mmoGwwq8H!I!!LMMr9   c                    US   [         R                  :X  a  SnSnOSnSnXS [        R                  " X0SU 5      S   4$ )z)Parse a float/double from a binary packetr   r   <dr2   z<fNr   )r   DOUBLErY   r   )r   r  r  r  s       r6   _parse_binary_float!MySQLProtocol._parse_binary_float  sN    
 8y'''FGFGwwq8H!I!!LMMr9   c                j    [         R                  " U 5      u  pU [        UR                  U5      5      4$ )z(Parse a New Decimal from a binary packet)r   r   r   rA   )r   r   values      r6   _parse_binary_new_decimal'MySQLProtocol._parse_binary_new_decimal  s/    
  ..v6W 5677r9   c           
         U S   nSnUS:X  aw  [         R                  " SU SS 5      S   nU S   nU S   nU[        R                  [        R                  4;   a  [
        R
                  " XEUS9nO[
        R                  " XEUS9nOrUS:  al  SnUS	:X  a   [         R                  " S
U SUS-    5      S   n[
        R
                  " [         R                  " SU SS 5      S   U S   U S   U S   U S   U S   US9nXS-   S U4$ )z&Parse a timestamp from a binary packetr   Nr2   r}   r   r   )yearmonthdayr      <Ir   r3      )r  r  r  hourminutesecondmicrosecond)rY   r   r   DATETIME	TIMESTAMPdatetimedate)r   
field_typer  r  r  r  r  mcss           r6   _parse_binary_timestamp%MySQLProtocol._parse_binary_timestamp  s    CGQ;==va{3A6D1IE)Ci00)2E2EFF ))tcJ 4#Fq[C|mmD&VaZ*@A!D%%]]4!5a8Qi1IAYayayE z|$e,,r9   c                R   U S   nU(       d  U SS [         R                  " 5       4$ U SUS-    nSnUS:  a  [        R                  " SUSS 5      S   n[        R                  " SUSS 5      S   nUS   S:X  a  US-  n[         R                  " UUS   UUS	   US   S
9nXS-   S U4$ )z'Parse a time value from a binary packetr   r   Nr   r  r3   r>   r   r  )dayssecondsmicrosecondsminuteshours)r   	timedeltarY   r   )r   r  r   r#  r'  tmps         r6   _parse_binary_time MySQLProtocol._parse_binary_time  s     12J 2 2 455a&1*%A:--d12h/2C}}T4!9-a07a<BJD  GGq'
 z|$c**r9   c                   [        U5      S-   S-   S-  nUSU  Vs/ s H  n[        U5      PM     nnX$S n/ nSn[        U5       GH  u  pU[        U	S-   S-  5         SU	S-   S-  -  -  (       a  UR                  S5        M>  U
S   [        R
                  [        R                  [        R                  [        R                  [        R                  4;   a&  U R                  X*5      u  p(UR                  U5        M  U
S   [        R                  [        R                  4;   a'  U R                  X*5      u  p(UR                  U5        GM  U
S   [        R                  [        R                  4;   a'  U R!                  X#5      u  p(UR                  U5        GMT  U
S   [        R"                  [        R$                  [        R&                  4;   a*  U R)                  X*S   5      u  p(UR                  U5        GM  U
S   [        R*                  :X  a'  U R-                  U5      u  p(UR                  U5        GM  U
S   [        R.                  :X  a@  [0        R2                  " U5      u  p(UR                  [4        R6                  " U5      5        GMI  U
S   [8        R:                  :X  d	  U
S   S:X  a,  [0        R2                  " U5      u  p(UR                  U5        GM  [0        R2                  " U5      u  p( UR                  UR=                  U5      5        GM     [A        U5      $ s  snf ! [>         a    UR                  U5         GM  f = f)z(Parse values from a binary result packetr   r*   r   r   Nr   ?   )!rO   r   	enumerater[   r   r   r   r   r  r  r  r  FLOATr  DECIMAL
NEWDECIMALr  r  DATEr  r$  TIMEr.  VECTORr   r   r   _vector_to_pythonr   BINARYrA   UnicodeDecodeErrortuple)r   fieldsr   r   null_bitmap_lengthr   null_bitmaprX   r  posr  s              r6   _parse_binary_values"MySQLProtocol._parse_binary_values  s    "&kAo1a7'-a0B'CD'C!s1v'CD+,$(#F+JC3a1}-.!a1}2DEd#Qx""  !% : :6 Ie$qi..	@@ $ 8 8 Ge$qi//1E1EFF $ > >v Oe$q""## 
 #'">">vQx"Pe$qY^^+"&"9"9&"Ae$qY---"'"6"6v">n>>uEFqY---qR"'"6"6v">e$"'"6"6v">)MM%,,w"78O ,V V}a EZ * )MM%(()s   L$4 L))M	M	c                B   / nSnSnSn	 Ub   Xg4$ X:X  a   Xg4$ [        UR                  U5      5      n
U
S   S:X  a  U R                  U
5      nSnO U
S   S:X  a  SnU R                  X*SS U5      nUc  Ub  UR	                  U5        OUc  Uc  [        U
5      eU	S-  n	M  )zgRead MySQL binary protocol result

Reads all or given number of binary resultset rows from the socket.
Nr   r2   r)   r3   r   )r   r   r   rA  r[   r   )r   r   columnsr   r   r   r   r   rX   r   r   s              r6   read_binary_result MySQLProtocol.read_binary_result8  s      { z { 499\23FayCnnV,a22712JP{v1F##F++FA! r9   c                `   U S   S:X  d  [        S5      e0 n [        R                  " U SS S5      u  oS'   [        R                  " U S5      u  oS'   [        R                  " U S5      u  oS	'   U S
S n [        R                  " U S5      u  oS'   U$ ! [         a  n[        S5      UeSnAff = f)z(Parse a MySQL Binary Protocol OK packet.r2   r   zFailed parsing Binary OK packetr3   Nr   r*   num_columns
num_paramsr   r   )r   r   rF   r   )r   ok_pktrv   s      r6   parse_binary_prepare_ok%MySQLProtocol.parse_binary_prepare_ok^  s     ayA~ !BCC	M-2^^F12J-J*F>*,1NN61,E)F=)+0>>&!+D(F<(ABZF.3nnVQ.G+F?+   	M !BCL	Ms   A8B 
B-B((B-c                   SnSnU S:  a^  U S:  a  Sn[         R                  nOU S:  a  Sn[         R                  nOU S:  a  Sn[         R                  nOrS	n[         R                  nO_S
nU S::  a  Sn[         R                  nODU S::  a  Sn[         R                  nO+U S::  a  Sn[         R                  nO[         R                  nSn[
        R                  " X05      X4$ )z0Prepare an integer for the MySQL binary protocolNr   ir   i r   i   r   r      r+   rU   i  r}   l    r  z<Q)r   r   r   r  r  rY   rZ   )r  r"  r   r  s       r6   prepare_binary_integer$MySQLProtocol.prepare_binary_integerp  s     
19}&^^
&&__
+%&^^
&//
E|&^^
%&__
*$&^^
&//
G+Z??r9   c                   [        U [        R                  5      (       a  [        R                  nO;[        U [        R                  5      (       a  [        R
                  nO[        S5      e[        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      /n[        U [        R                  5      (       a  UR                  [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                   5      /5        U R"                  S:  a/  UR%                  [        R&                  " U R"                  5      5        SR)                  U5      n[        R                  " [+        U5      5      U-   U4$ )aK  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.dater   r9   )
isinstancer   r   r  r!  r6  r   r   	int2storer  r   r  r  extendr  r  r  r  r[   r   r]   rO   )r  r"  chunkspackeds       r6   prepare_binary_timestamp&MySQLProtocol.prepare_binary_timestamp  s-    eX..//"++Jx}}--"JQRR OOEJJ'OOEKK(OOEII&
 eX..//MMOOEJJ/OOELL1OOELL1   1$eooe.?.?@A&!s6{+f4j@@r9   c                   [        U [        R                  [        R                  45      (       d  [	        S5      e[
        R                  nSnSn[        / 5      n[        U [        R                  5      (       a  U R                  S:  a  Sn[        U R                  S5      u  pV[        US5      u  pxUR                  [        R                  " [        U R                  5      5      [        R                  " U5      [        R                  " U5      [        R                  " U5      /5        U R                   nOUR                  [        R                  " S5      [        R                  " U R"                  5      [        R                  " U R$                  5      [        R                  " U R&                  5      /5        U R(                  nU(       a%  UR+                  [        R                  " U5      5        UR-                  [        R                  " U5      5        SR/                  U5      n	[        R                  " [1        U	5      5      U	-   U4$ )aI  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.timer   Nr   i  <   r9   )rR  r   r,  timer   r   r7  r   r'  divmodr(  rT  r   r   absr   r)  r  r  r  r  r[   
appendleftr]   rO   )
r  r"  negativer#  rU  r+  	remainderminssecsrV  s
             r6   prepare_binary_time!MySQLProtocol.prepare_binary_time  s    %("4"4hmm!DEERSS^^
$RyeX//00zzA~!'t!<U!)R0LTMMOOC

O4OOE*OOD)OOD)	 $$CMMOOA&OOEJJ/OOELL1OOELL1	 ##CMM%//#./%//(34&!s6{+f4j@@r9   c                z    SR                  [        R                  " U 5      [        R                  " U5      U/5      $ )z=Prepare long data for prepared statements

Returns a string.
r9   )r]   r   r   rS  )	statementparamr   s      r6   prepare_stmt_send_long_data)MySQLProtocol.prepare_stmt_send_long_data  s,     xx3U__U5KTRSSr9    c	           
        Sn	S/[        U5      S-   S-  -  n
/ n/ nSn[        U5      n/ nU(       d  UOU[        -   nUS:X  a  SnUc  0 nU(       a=  [        U5      nU H  u  nnUR                  U5        M     S/[        U5      S-   S-  -  n
U(       d  U(       Gao  U[        U5      :w  a  [	        S5      e[        U5       GHE  u  nnSnUcb  U
US-  ==   SUS-  -  -  ss'   UR                  [        R                  " [        R                  5      [        R                  " U5      -   5        Mn  UU;   a1  UU   S   (       a  [        R                  nGO[        R                  nGO[        U[        5      (       a(  U R                  U5      u  nnnUR                  U5        GO[        U[        5      (       aT  UR!                  U5      nUR                  [        R"                  " [        U5      5      U-   5        [        R                  nGO][        U[$        5      (       aC  UR                  [        R"                  " [        U5      5      U-   5        [        R                  nGO[        U[&        5      (       as  UR                  [        R"                  " [        [        U5      R!                  U5      5      5      [        U5      R!                  U5      -   5        [        R(                  nGO}[        U[*        5      (       a8  UR                  [,        R.                  " S	U5      5        [        R0                  nGO0[        U[2        R2                  [2        R4                  45      (       a&  U R7                  U5      u  nnUR                  U5        O[        U[2        R8                  [2        R:                  45      (       a&  U R=                  U5      u  nnUR                  U5        OU(       a\  [        U5      R!                  U5      nUR                  [        R"                  " [        U5      5      U-   5        [        R                  nO#[?        S
UR@                  RB                   S35      eUR                  [        R                  " U5      [        R                  " U5      -   5        U(       d  GM  US-   U:  d  GM  UUU-
     S   R!                  U5      nUR                  [        R"                  " [        U5      5      U-   5        GMH     [        RD                  " U5      [        R                  " U5      [        RD                  " U	5      /nUb  U[        U5      -   nOUnU(       a  Ub%  UR                  [        R"                  " U5      5        URG                  U
 Vs/ s H  n[,        R.                  " SU5      PM     sn5        UR                  [        R                  " S5      5        SnU HN  nUR                  U5        Ub2  US-   U:  a  UR                  UUU-
     5        OUR                  S5        US-  nMP     U H  nUR                  U5        M     SRI                  U5      $ s  snf )z6Make a MySQL packet with the Statement Execute commandr   r   r   r   r9   utf8mb4utf8zTFailed executing prepared statement: data values does not match number of parametersr  z&MySQL binary protocol can not handle 'z	' objectsBr;   )%rO   r   listr[   r   r2  r   r   r   NULLBLOBSTRINGrR  r   rO  strr\   rn   r   r   r4  floatrY   rZ   r  r   r!  rW  r,  r[  rc  r   	__class____name__r   rT  r]   )r   r   r   
parametersr   long_data_usedr   query_attrsconverter_str_fallbackiteration_countr?  rX   typesrV  data_lenquery_attr_namesr   attr_valr@  r  _flagsr"  rm   r   parameter_countbitr   a_typea_values                                r6   make_stmt_executeMySQLProtocol.make_stmt_execute  s    cc$i!m12 t9(*(e6O.OiG!N:D*8H%  +##d)a-A!56K3z?*$2  (o
U=+qS1W~=+LL	7%//&:QQ .(%c*1-%.^^
 &/%5%5
s++
 33E:	"MM&)s++!LL1EMM%,,s5z":U"BC!*!1!1Ju--MM%,,s5z":U"BC!*!1!1Jw//MMSU):):7)C%DEe*++G45 "+!2!2Ju--MM&++dE":;!*!1!1J(9(98=='IJJ+/+H+H+O(VZMM&)(:(:HMM'JKK+/+C+CE+J(VZMM&)+J--g6EMM%,,s5z":U"BC!*!1!1J*!OO445Y@  U__Z85??6;RRS;37X#5&sX~6q9@@ID$++ELLT,Cd,JKq .t OOL)OOE"OOO,
 "&[)99O&O&ell?;<MMKHKS6;;sC0KHIMM%//!,-Ef%
 *qy8+&6ux7G&HIg.
   "g& " xx) Is   !Y-)r5   r   returnr   )r5   r   r  zTuple[str, bytes])rR   zDict[str, str]r  r   )re   r   rf   Optional[str]r  r   )NFN)ro   r   rp   rs  rq   rs  rr   rs  rs   r  rj   boolrt   Optional[Dict[str, Any]]r  Tuple[bytes, MySQLAuthPlugin])r   r#   rp   rs  rq   rs  rf   r  r   r   re   r   r   r   rr   r  rs   r  rR   zOptional[Dict[str, str]]r   r  rj   r  rt   r  r  r  )r   r   re   r   r   r   r  r   rN   )r   r   r   zOptional[bytes]r  r   )r   )r   r   r   r   r  r   )r   r   r  r#   )r   r   r  r$   )r   r   r  Optional[int])r   )r   r   r   rs  r  r!   )r   r   r  r"   )T)r   r   r   r  r  r%   )r   N)
r   r'   r   zTuple[int, ...]r   r   r   r  r  zATuple[List[Tuple[Optional[bytes], ...]], Optional[EofPacketType]])r   r   r  r!   r  Tuple[bytes, int])r   r   r  r!   r  zTuple[bytes, float])rm  )r   r   r   rs  r  zTuple[bytes, Decimal])r   r   r"  r   r  z?Tuple[bytes, Optional[Union[datetime.date, datetime.datetime]]])r   r   r  z Tuple[bytes, datetime.timedelta])r=  List[DescriptionType]r   r   r   rs  r  zTuple[BinaryProtocolType, ...])r   r   N)r   r'   rD  r  r   r   r   rs  r   r  r  zDTuple[List[Tuple[BinaryProtocolType, ...]], Optional[EofPacketType]])r   r   r  zDict[str, int])r  r   r  zTuple[bytes, int, int])r  z'Union[datetime.date, datetime.datetime]r  r  )r  z(Union[datetime.timedelta, datetime.time]r  r  )rf  r   rg  r   r   r   r  r   )rj  rj  r   Nrm  NF)r   r   r   zSequence[BinaryProtocolType]rw  r   r   r   rx  z Optional[Dict[int, Tuple[bool]]]r   rs  ry  z.Optional[List[Tuple[str, BinaryProtocolType]]]rz  r  r  r   )'rv  
__module____qualname____firstlineno____doc__staticmethodr7   rC   rI   ra   rg   rw   DEFAULT_CHARSET_IDDEFAULT_MAX_ALLOWED_PACKETr   r   r   r   r   r   r   r   r   r   r   r  r  r  r$  r.  rA  rE  rK  rO  rW  rc  rh  r  __static_attributes__rj  r9   r6   r/   r/   X   s$   
  * ) )4 ) )4 + +< 
 
(  ,0!26:,:,:, :, 	:,
 ):, :, 0:, 
':, :,x 
 #')"<%)+//3',!26w9 w9w9 w9  	w9
 w9 w9  w9 #w9 )w9 -w9 !%w9 w9 0w9 
'w9 w9r )"<


  
 
	
 
@ = =
 E E 1 1f  , I I 
 
@(  @ &*.. !. 	.
 $.
.` NN-N	N N2 NN-N	N N &,88 #8	8 8 --- 
I- -> + +4 	8%8 8 	8
 
(8| &*$$ '$ 	$
 $ $$
$L  " @ @B (A6(A	(A (AT 5A75A	5A 5An T T .0!;?FJ',E E  +E  	E 
 E  9E  E  DE  !%E  
E  E r9   r/   )>r  
__future__r   r   rY   collectionsr   decimalr   r   typingr   r   r	   r
   r   r   r   r   r   rL   r   	constantsr   r   r   r   r   
conversionr   errorsr   r   r   r   r   pluginsr   r   plugins.caching_sha2_passwordr   r|  r    r!   r"   r#   r$   r%   r&   networkr'   r   r?   r4   	OK_STATUS
EOF_STATUSrG   
ERR_STATUSLOCAL_INFILE_STATUSr  r  r/   rj  r9   r6   <module>r     s   : 3 "    -
 
 
   ' R R  5 M   $    	


  ' j  j r9   