
    g(1                         d Z dgZddlZddlmZmZmZmZmZ ddl	m
Z
mZ ddlmZmZmZ ddlmZ dd	lmZmZmZ dd
lmZmZmZmZ ddlmZmZ ddlmZ ddl m!Z!m"Z" ddl#m$Z$  G d de          ZdS )z,Implements the MySQL Client/Server protocol.MySQLProtocol    N)AnyDictListOptionalTuple   )
ClientFlag	ServerCmd)InterfaceErrorProgrammingErrorget_exception)logger)DEFAULT_CHARSET_IDDEFAULT_MAX_ALLOWED_PACKETr   )BinaryProtocolTypeDescriptionTypeEofPacketTypeHandShakeType)lc_intread_lc_string_list   )MySQLSocket)MySQLAuthPluginget_auth_plugin)"MySQLCachingSHA2PasswordAuthPluginc                    V   e Zd ZdZe	 	 	 d dededededee         d	ed
ee	ee
f                  deeef         fd            Zedededdddddf
dedededee         dedededee         dee         dee	eef                  ded	ed
ee	ee
f                  deeef         fd            Z	 	 	 d!dedee         dededee         deeeedf                  ee         f         fdZ	 	 d"dedeedf         dedee         deeeee         df                  ee         f         f
dZdS )#r   zSImplements MySQL client/server protocol.

    Create and parses MySQL packets.
    NF	auth_datausernamepasswordauth_pluginauth_plugin_classssl_enabledplugin_configreturnc                 j   |s|dk    rdt          |||          fS |i }	  t          ||          |||          } |j        | fi |}n,# t          t          f$ r}	t	          d|	           |	d}	~	ww xY w|t	          d|j                   t          t          |                    |z   }||fS )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.
             )r#   NzFailed authentication: z8Got NULL auth response while authenticating with plugin )r   r   auth_response	TypeErrorr   namer   len)
r   r   r    r!   r"   r#   r$   auth_strategyr)   errs
             h/var/www/html/nodeJS/PythonScripts/venv3.11/lib/python3.11/site-packages/mysql/connector/aio/protocol.pyauth_plugin_first_responsez(MySQLProtocol.auth_plugin_first_response:   s-   D  	K2-->(      M	KKOK9JKK(  M 8M7	SS]SSMM>* 	K 	K 	K !@3!@!@AAsJ	K   /',/ /  
 s=1122]Bm++s   *A A6A11A6r   	handshakedatabasecharsetclient_flagsmax_allowed_packet
conn_attrsis_change_user_requestc           	         |                                 }g }|
rt          j        d           t          j        d           | t          d          d|                     d          t          d          d	 |p| d         }n-# t
          t          f$ r}t          d| d	          dd}~ww xY wt          j        d
|           |
rE|                    t          j	        dt          |           dt          j        |                     n@d}|                    t          j	        d| t          |           d||||                     t                              | d         ||||||          \  }}|                    |           |                    t                              ||                     |
r(|                    t          j	        d|                     |t           j        z  r*|                    |                                 dz              |t           j        z  r/|	-|                    t                              |	                     d                    |          |fS )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 handshaker   z$Handshake misses authentication infor!   z-Handshake misses authentication plugin info ()z#The provided initial strategy is %sz<Bsxxxxxxxxxxxxxxxxxxxxxxxxz<IIB)r   r   r    r!   r"   r#   r$   z<Hr(       )encoder   debugr   getr*   KeyErrorappendstructpackr,   r   CHANGE_USERr   r0   connect_with_dbr
   PLUGIN_AUTHCONNECT_ARGSmake_conn_attrsjoin)r1   r   r    r2   r3   r4   r5   r!   r"   r6   r7   r#   r$   
b_usernameresponse_payloadr.   fillerr)   r-   s                      r/   	make_authzMySQLProtocol.make_authw   s   f __&&
! 	8L67773444"#9::D==%%-"#IJJPTT	%A=)AKK8$ 	 	 	"FFFF 	
 	:KHHH! 	##,Z,,,)     F##6663z??666 &    (5'O'O,#/#' (P (
 (
$} 	... 	 = =lH U UVVV " 	@##FKg$>$>??? *00 	D##K$6$6$8$87$BCCC :22 	O
8N##M$A$A*$M$MNNNxx())=88s   9
B B.B))B.r   utf-8sockcolumnscountread_timeout.c                 p  K   g }d}d}d}		 |s|	|k    rn|                     |           d{V }
|
d         dk    r|                     |
          }d}n-|
d         dk    r!d}|                     ||
dd         |          }|||                    |           n||t	          |
          |	dz  }	||fS )zxRead MySQL binary protocol result.

        Reads all or given number of binary resultset rows from the socket.
        Nr   T         r   )read	parse_eof_parse_binary_valuesrA   r   )selfrO   rP   rQ   r3   rR   rowseofvaluesipackets              r/   read_binary_resultz MySQLProtocol.read_binary_result   s       	 a5jj99\22222222FayCnnV,,a227F122JPP{v1F#####F+++FA	 c{r<   versionc                 <  K   |}g }d}d}d}		 |s|	|k    rn|                     |           d{V }
|
                    d          r|
dd         g}|                     |           d{V }
|
                    d          rM|                    |
dd                    |                     |           d{V }
|
                    d          M|                    |
dd                    t          d                    |                    }nV|
d         dk    r$|
d         dk     r|                     |
          }d}n&d}t          t          |
dd                             }|||                    |           n||t          |
          |	d	z  }	||fS )
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   Ts   rT   r<   rU      r   )rW   
startswithrA   r   rI   rX   bytesr   )rZ   rO   ra   rQ   rR   _r[   r\   rowdatar^   r_   datass               r/   read_text_resultzMySQLProtocol.read_text_result  s     $ 	 a5jj99\22222222F  11 A#yy66666666''88 ;LL,,,#'99\#:#:::::::F ''88 ; VABBZ(((-chhuoo>>c!!fQi!mmnnV,,-eF122J.?.?@@{w2G$$$$#F+++FA-	. Syr<   )NFN)r   rN   N)r   N)__name__
__module____qualname____doc__staticmethodre   strr   boolr   r   r   r   r0   r   r   r   intrM   r   r   r   r   r   r`   ri    r<   r/   r   r   4   s        
  ,0!26:, :,:,:, :, 	:,
 $C=:, :,  S#X/:, 
uo%	&:, :, :, \:,x 
 #')"<%)+//3',!26w9 w9 w9w9 w9 3-	w9
 w9 w9  w9 c]w9 $C=w9 T#s(^,w9 !%w9 w9  S#X/w9 
uo%	&w9 w9 w9 \w9| &*" "" o&" 	"
 " sm" 
U%s*+,	!
" " " "R &*. .. sCx. 	.
 sm. 
U8E?C'()	!
. . . . . .r<   )%rm   __all__rB   typingr   r   r   r   r   	constantsr
   r   errorsr   r   r   r   protocolr   r   r   _MySQLProtocoltypesr   r   r   r   utilsr   r   networkr   pluginsr   r   plugins.caching_sha2_passwordr   rr   r<   r/   <module>r~      s{  : 3 2
  3 3 3 3 3 3 3 3 3 3 3 3 3 3 - - - - - - - - D D D D D D D D D D               
 V U U U U U U U U U U U / / / / / / / /             5 5 5 5 5 5 5 5 M M M M M MQ Q Q Q QN Q Q Q Q Qr<   