
    :?h                        S r SSKrSSKrSSKJr  SSKJrJrJrJ	r	J
r
Jr   SSKrSr SSKrSrSSKJrJrJrJr  SS	KJrJrJrJrJr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(  SSK)J*r*  SSK+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5  SSK6J7r7J8r8J9r9J:r:J;r;J<r<J=r=J>r>  Sr? " S S5      r@ " S S5      rA " S S5      rB " S S5      rCg! \ a    Sr Nf = f! \ a    Sr Nf = f)z3Implementation of the X protocol for MySQL servers.    N)BytesIO)AnyDictListOptionalTupleUnionTF   )InterfaceErrorNotSupportedErrorOperationalErrorProgrammingError)
ExprParserbuild_bool_scalar
build_exprbuild_int_scalarbuild_scalarbuild_unsigned_int_scalar)encode_to_bytesget_item_or_attr)logger)CRUD_PREPARE_MAPPINGPROTOBUF_REPEATED_TYPESSERVER_MESSAGESMessagemysqlxpb_enum)Column)
AddStatementDeleteStatementFilterableStatementFindStatementInsertStatementModifyStatementReadStatementRemoveStatementSqlStatementUpdateStatement)
ColumnTypeMessageTypeProtobufMessageCextTypeProtobufMessageTypeResultBaseType
SocketTypeStatementType
StrOrBytesi  c                   N    \ rS rSrSrS\SS4S jrS\S\4S jr	S\S\4S	 jr
S
rg)
Compressore   zImplements compression/decompression using `zstd_stream`, `lz4_message`
and `deflate_stream` algorithms.

Args:
    algorithm (str): Compression algorithm.

.. versionadded:: 8.0.21

	algorithmreturnNc                    Xl         S U l        S U l        US:X  a5  [        R                  " 5       U l        [        R
                  " 5       U l        g US:X  a5  [        R                  " 5       U l        [        R                  " 5       U l        g g )Nzstd_streamdeflate_stream)	
_algorithm_compressobj_decompressobjzstdZstdCompressorZstdDecompressorzlibcompressobjdecompressobjselfr3   s     W/var/www/ev-aguas/ev-aguas-proceso/venv/lib/python3.13/site-packages/mysqlx/protocol.py__init__Compressor.__init__p   sq    (!%#'% $ 3 3 5D"&"7"7"9D** $ 0 0 2D"&"4"4"6D +    datac                    U R                   S:X  a  U R                  R                  U5      $ U R                   S:X  a^  [        R                  R                  5        nUR                  5       nX2R                  U5      -  nX2R                  5       -  nSSS5        U$ U R                  R                  U5      nX0R                  R                  [        R                  5      -  nU$ ! , (       d  f       W$ = f)zCompresses data and returns it.

Args:
    data (str, bytes or buffer object): Data to be compressed.

Returns:
    bytes: Compressed data.
r6   lz4_messageN)
r8   r9   compresslz4frameLZ4FrameCompressorbeginflushr>   Z_SYNC_FLUSH)rB   rG   
compressor
compresseds       rC   rJ   Compressor.compress|   s     ??m+$$--d33??m+--/:'--/
11$77
..00
 0  &&//5
''--d.?.?@@
 0/ s   6C""
C1c                    U R                   S:X  a  U R                  R                  U5      $ U R                   S:X  a:  [        R                  R                  5        nUR                  U5      nSSS5        U$ U R                  R                  U5      nX0R                  R                  [        R                  5      -  nU$ ! , (       d  f       W$ = f)zDecompresses a frame of data and returns it as a string of bytes.

Args:
    data (str, bytes or buffer object): Data to be compressed.

Returns:
    bytes: Decompresssed data.
r6   rI   N)	r8   r:   
decompressrK   rL   LZ4FrameDecompressorrO   r>   rP   )rB   rG   decompressordecompresseds       rC   rU   Compressor.decompress   s     ??m+&&11$77??m+//1\+66t< 2 **55d;++11$2C2CDD 21s   B>>
C)r8   r9   r:   )__name__
__module____qualname____firstlineno____doc__strrD   r/   bytesrJ   rU   __static_attributes__ rF   rC   r1   r1   e   s@    
7# 
7$ 
7Z E .z e rF   r1   c                   j    \ rS rSrSrS\SS4S jrS\4S jrS\4S jr	S	\SS4S
 jr
S\SS4S jrSrg)MessageReader   zImplements a Message Reader.

Args:
    socket_stream (mysqlx.connection.SocketStream): `SocketStream` object.

.. versionadded:: 8.0.21
socket_streamr4   Nc                 :    Xl         S U l        S U l        / U l        g N)_stream_compressor_msg
_msg_queuerB   rf   s     rC   rD   MessageReader.__init__   s    #015!%	)+rF   c                 t   U R                   (       a  U R                   R                  S5      $ [        R                  " SU R                  R                  S5      5      u  pUS:X  a  [        S5      eU R                  R                  US-
  5      nU[        ;  a  [        SU 35      eUS:X  a  US	:X  a  U R                  5       $ [        R                  " X#5      nUS
:X  a  US   n[        U R                  R                  US   5      5      nSnXu:  ay  [        R                  " SUR                  S5      5      u  pUR                  US-
  5      n
U R                   R                  [        R                  " X5      5        XxS-   -  nXu:  a  My  U R                   (       a  U R                   R                  S5      $ S$ U$ )af  Reads X Protocol messages from the stream and returns a
:class:`mysqlx.protobuf.Message` object.

Raises:
    :class:`mysqlx.ProgrammingError`: If e connected server does not
                                      have the MySQL X protocol plugin
                                      enabled.

Returns:
    mysqlx.protobuf.Message: MySQL X Protobuf Message.
r   <LB   
   z[The connected server does not have the MySQL X protocol plugin enabled or protocol mismatchr
   zUnknown message type:    rF      uncompressed_sizepayload   N)rl   popstructunpackri   readr   r   
ValueError_read_messager   from_server_messager   rj   rU   append)rB   
frame_size
frame_typeframe_payload	frame_msgru   streambytes_processedpayload_sizemsg_typerv   s              rC   r}   MessageReader._read_message   s    ????&&q))!'udll6G6G6J!K
"$  ))*q.9_,5j\BCC  4%%''//
J	 )*= >T--8899MNOFO!5)/ufkk!n)M& ++lQ&67&&w'B'B8'UV!#33	 "5
 .2__4??&&q)F$FrF   c                 f    U R                   b  U R                   nSU l         U$ U R                  5       $ )zORead message.

Returns:
    mysqlx.protobuf.Message: MySQL X Protobuf Message.
N)rk   r}   rB   msgs     rC   read_messageMessageReader.read_message   s2     99 ))CDIJ!!##rF   r   c                 @    U R                   b  [        S5      eXl         g)zPush message.

Args:
    msg (mysqlx.protobuf.Message): MySQL X Protobuf Message.

Raises:
    :class:`mysqlx.OperationalError`: If message push slot is full.
NzMessage push slot is full)rk   r   r   s     rC   push_messageMessageReader.push_message   s     99 "#>??	rF   r3   c                 B    U(       a  [        U5      U l        gSU l        g)zCreates a :class:`mysqlx.protocol.Compressor` object based on the
compression algorithm.

Args:
    algorithm (str): Compression algorithm.

.. versionadded:: 8.0.21

Nr1   rj   rA   s     rC   set_compressionMessageReader.set_compression   s     5>:i04rF   )rj   rk   rl   ri   )rZ   r[   r\   r]   r^   r-   rD   r)   r}   r   r   r_   r   ra   rb   rF   rC   rd   rd      s\    ,j ,T ,-{ -^
$k 
$  
H 
H 
HrF   rd   c                   R    \ rS rSrSrS\SS4S jrS\S\SS4S	 jr	S
\
SS4S jrSrg)MessageWriteri  zImplements a Message Writer.

Args:
    socket_stream (mysqlx.connection.SocketStream): `SocketStream` object.

.. versionadded:: 8.0.21

rf   r4   Nc                     Xl         S U l        g rh   )ri   rj   rm   s     rC   rD   MessageWriter.__init__  s    #015rF   r   r   c                 f   UR                  U5      nU R                  (       Ga/  U[        :  Ga$  [        UR	                  5       5      n[
        R                  " SUS-   U5      nU R                  R                  SR                  XT/5      5      n[        S5      nXS'   US-   US'   [        S5      nXhS'   SR                  [        UR                  5       5      S	S
 [        UR                  5       5      /5      n	[        S5      n
[
        R                  " S[        U	5      S-   U
5      nU R                  R                  SR                  XY/5      5        g	[        UR	                  5       5      n[
        R                  " SUS-   U5      nU R                  R                  SR                  XT/5      5        g	)zyWrite message.

Args:
    msg_type (int): The message type.
    msg (mysqlx.protobuf.Message): MySQL X Protobuf Message.
rp   r
   rF   zMysqlx.Connection.Compressionclient_messagesrq   ru   rv   Nz&Mysqlx.ClientMessages.Type.COMPRESSION)	byte_sizerj   _COMPRESSION_THRESHOLDr   serialize_to_stringry   packrJ   joinr   serialize_partial_to_stringr   lenri   sendall)rB   r   r   msg_sizemsg_strheaderrR   msg_first_fieldsmsg_payloadoutputmsg_comp_ids              rC   write_messageMessageWriter.write_message  sw    ==%+A A%c&=&=&?@G[[1h?F))22388V<M3NOJ&'FG2:./4<qL01!"ABK%/	"XX#$4$P$P$RS $K$K$K$MN	F ((PQK[[FaEFLL  6*:!;<%c&=&=&?@G[[1h?FLL  6*;!<=rF   r3   c                 B    U(       a  [        U5      U l        gSU l        g)zCreates a :class:`mysqlx.protocol.Compressor` object based on the
compression algorithm.

Args:
    algorithm (str): Compression algorithm.
Nr   rA   s     rC   r   MessageWriter.set_compression@  s     5>:i04rF   )rj   ri   )rZ   r[   r\   r]   r^   r-   rD   intr)   r   r_   r   ra   rb   rF   rC   r   r     sK    6j 6T 6#>c #> #> #>JH H HrF   r   c                      \ rS rSrSrS\S\SS4S jr\S\	\
   4S j5       r\S	\S
\SS4S j5       rS\S\	\   4S jr S7S
\\\4   S\S\\S   \\\\4      4   4S jjrS	\S\SS4S jrS\S\	\   4S jrS\
SS4S jrS\4S jrS\SS4S jr  S8S\
S\	\
   S\	\
   SS4S jjrS\ 4S jr!S\
SS4S jr"S9S jr#S\
S	\S
\\$\%\&\'\(\)4   SS4S  jr*S\
S	\S
\SS4S! jr+S"\,SS4S# jr-S\
S	\S
\\\4   SS4S$ jr.S\
S	\SS4S% jr/S
\\$\'4   S\0\
\4   4S& jr1S
\\&\)4   S\0\
\4   4S' jr2S
\\%\(4   S\0\
\4   4S( jr3 S:S)\
S
\\
\44   S*\	\5\
\4      S\0\
\4   4S+ jjr6\S
\\7\84   S\0\
\4   4S, j5       r9S\SS4S- jr:S\S\	\   4S. jr;S\S\\<   4S/ jr=S9S0 jr>S9S1 jr?S9S2 jr@S9S3 jrAS:S4\	\   S\4S5 jjrBS6rCg);ProtocoliJ  zImplements the MySQL X Protocol.

Args:
    read (mysqlx.protocol.MessageReader): A Message Reader object.
    writer (mysqlx.protocol.MessageWriter): A Message Writer object.

.. versionchanged:: 8.0.21
readerwriterr4   Nc                 8    Xl         X l        S U l        / U l        g rh   )_reader_writer_compression_algorithm	_warnings)rB   r   r   s      rC   rD   Protocol.__init__T  s    &,&,59#$&rF   c                     U R                   $ )zstr: The compresion algorithm.)r   )rB   s    rC   compression_algorithmProtocol.compression_algorithmZ  s     ***rF   r   stmtc                 b   UR                   (       a  UR                  5       U S'   UR                  (       a"  U S   R                  UR	                  5       5        UR
                  (       a"  U S   R                  UR                  5       5        UR                  (       a  UR                  5       U S'   gg)zApply filter.

Args:
    msg (mysqlx.protobuf.Message): The MySQL X Protobuf Message.
    stmt (Statement): A `Statement` based type object.
criteriaordergroupinggrouping_criteriaN)		has_whereget_where_exprhas_sortextendget_sort_exprhas_group_byget_grouping
has_having
get_having)r   r   s     rC   _apply_filterProtocol._apply_filter_  s     >>"113C
O==L 2 2 45
O""4#4#4#67??'+'8C#$ rF   argc           	         [        U[        5      (       a   [        SUS9n[        SSUS9n[        SSUS9$ [        U[        5      (       a  [        SS[	        U5      S9$ [        U[
        5      (       a.  US	:  a  [        SS[        U5      S9$ [        SS[        U5      S9$ [        U[        5      (       aQ  [        U5      S
:X  aB  Uu  pE[        SUU R                  U5      S9n[        SUR                  5       /S9n[        SS
US9$ [        U[        5      (       d3  [        U[        [        45      (       a  [        US	   [        5      (       a  / nU H  n	/ n
U	R                  5        H>  u  p[        SUU R                  U5      S9nU
R                  UR                  5       5        M@     [        SU
S9n[        SS
US9nUR                  UR                  5       5        M     [        S5      nXS'   [        SSUS9$ [        U[        5      (       a]  / n
U H>  u  p[        SUU R                  U5      S9nU
R                  UR                  5       5        M@     [        SU
S9n[        SS
US9nU$ g)zxCreate any.

Args:
    arg (object): Arbitrary object.

Returns:
    mysqlx.protobuf.Message: MySQL X Protobuf Message.
zMysqlx.Datatypes.Scalar.String)valuezMysqlx.Datatypes.Scalar   )typev_stringMysqlx.Datatypes.Anyr
   )r   scalarr      #Mysqlx.Datatypes.Object.ObjectFieldkeyr   Mysqlx.Datatypes.Objectfldr   objzMysqlx.Datatypes.Arrayr      )r   arrayN)
isinstancer_   r   boolr   r   r   r   tupler   _create_anyget_messagedictlistitemsr   )rB   r   r   r   arg_key	arg_valueobj_fldr   array_valuesr   obj_fldsr   msg_objmsg_anyr   s                  rC   r   Protocol._create_anyp  sw    c3<CHE6QOF1&IIc4  &Q7H7M  c3Qw*+C0 
 &05 
 c5!!c#h!m!$G5&&y1G
 3':M:M:O9PQC1sCCc4  sT5M**z#a&$/G/GL"'++-JC%="..u5G
 OOG$7$7$9: #0 "";J!"8qgN##G$7$7$9:  23C'L1EEc4  H!
!9**51
  3 3 56 " 7XFG41'JGNrF   	is_scalarc                   ^ ^ S[         S[        [        [        4   4UU 4S jjnUR	                  5       nUR                  5       nUc  U Vs/ sH
  oc" U5      PM     sn$ [        U5      nUS/-  nU[        U5      :w  a  [        S5      eUR                  5        H&  u  pX;  a  [        SU	 35      eXY   n
U" U5      X'   M(     U$ s  snf )aS  Returns the binding any/scalar.

Args:
    stmt (Statement): A `Statement` based type object.
    is_scalar (bool): `True` to return scalar values.

Raises:
    :class:`mysqlx.ProgrammingError`: If unable to find placeholder for
                                      parameter.

Returns:
    list: A list of ``Any`` or ``Scalar`` objects.
r   r4   c                    > T(       a  [        U 5      R                  5       $ TR                  U 5      R                  5       $ rh   )r   r   r   )r   r   rB   s    rC   build_value/Protocol._get_binding_args.<locals>.build_value  s6     #E*6688##E*6688rF   Nz;The number of bind parameters and placeholders do not matchz*Unable to find placeholder for parameter: )	r   r	   r+   r*   get_bindingsget_binding_mapr   r   r   )rB   r   r   r   bindingsbinding_mapr   countargsnameposs   ` `        rC   _get_binding_argsProtocol._get_binding_args  s    "	9	9&(??@	9 	9 $$&**, 4<=H5K&H==K 4&.CM!"M  $>>+KD&&@G  #C#E*DI ,  >s   Cresultc                    US   S:X  a  [         R                  " SUS   5      nU R                  R                  UR                  5        [
        R                  " SUR                  UR                  5        UR                  UR                  UR                  UR                  5        gUS   S:X  a  [         R                  " SUS   5        gUS   S:X  a  [         R                  " S	US   5      nUS
   [        S5      :X  aG  UR                  US    Vs/ sH'  n[        [        US5      S5      R                  5       PM)     sn5        g[        US   [        [         5      5      (       a  US   S   OUS   nUS
   [        S5      :X  a  UR#                  [        US5      5        gUS
   [        S5      :X  a  UR%                  [        US5      5        gggs  snf )zProcess frame.

Args:
    msg (mysqlx.protobuf.Message): A MySQL X Protobuf Message.
    result (Result): A `Result` based type object.
r   r
   zMysqlx.Notice.Warningrv   z:Protocol.process_frame Received Warning Notice code %s: %sr   z$Mysqlx.Notice.SessionVariableChangedr   z!Mysqlx.Notice.SessionStateChangedparamzBMysqlx.Notice.SessionStateChanged.Parameter.GENERATED_DOCUMENT_IDSr   v_octetsr   z9Mysqlx.Notice.SessionStateChanged.Parameter.ROWS_AFFECTEDv_unsigned_intz?Mysqlx.Notice.SessionStateChanged.Parameter.GENERATED_INSERT_IDN)r   from_messager   r   r   r   warningcodeappend_warninglevelr   set_generated_idsr   decoder   r   r   set_rows_affectedset_generated_insert_id)rB   r   r   warn_msgsess_state_msgr   sess_state_values          rC   _process_frameProtocol._process_frame  s    v;!++,CS^THNN!!(,,/NNL
 !!(..(--N[A  !GYX[A$113S^N g&-T+  ((
 &4G%<	 &=E ),UJ? &(# &=	 "&w/7N1O  #7+A. (0 ! "'*mO/  ,,()9;KL $G,U1  22()9;KL; s   -Gc                      U R                   R                  5       nWR
                  S:X  a  [        US   US   5      eUR
                  S:X  a   U R                  X!5        O|UR
                  S:X  a  gUR
                  S	:X  a  UR                  S5        OIUR
                  S
:X  a  UR                  S5        O'UR
                  S:X  a  UR                  S5         U$  U$ M  ! [         a<  n[        UR	                  5       5      nU(       a  [        U SU 35      Ue SnAGNSnAff = f! [        [        4 a     GM<  f = f)zHRead message.

Args:
    result (Result): A `Result` based type object.
Tz	 reason: NMysqlx.Errorr   r  Mysqlx.Notice.FramezMysqlx.Sql.StmtExecuteOkzMysqlx.Resultset.FetchDonez(Mysqlx.Resultset.FetchDoneMoreResultsetsMysqlx.Resultset.Row)r   r   RuntimeErrorreprget_warningsr   r   r  AttributeErrorKeyError
set_closedset_has_more_resultsset_has_data)rB   r   r   errwarningss        rC   r}   Protocol._read_message  s=    Mll//1
 xx>)&s5z3v;??xx00''4 7799!!$'GG++D133##D) 
 
3    M 3 3 56&#iz'BCL M '1 s)   C  D)  
D&*1D!!D&)D>=D>r3   c                 |    Xl         U R                  R                  U5        U R                  R                  U5        g)zSets the compression algorithm to be used by the compression
object, for uplink and downlink.

Args:
    algorithm (str): Algorithm to be used in compression/decompression.

.. versionadded:: 8.0.21

N)r   r   r   r   rA   s     rC   r   Protocol.set_compression?  s.     '0#$$Y/$$Y/rF   c                 V   [        S5      nU R                  R                  [        S5      U5        U R                  R                  5       nUR                  S:X  a,  U R                  R                  5       nUR                  S:X  a  M,  UR                  S:X  a  [        US   US   5      eU$ )zSGet capabilities.

Returns:
    mysqlx.protobuf.Message: MySQL X Protobuf Message.
z!Mysqlx.Connection.CapabilitiesGetz/Mysqlx.ClientMessages.Type.CON_CAPABILITIES_GETr  r  r   r  )r   r   r   r   r   r   r   r   r   s     rC   get_capabilitesProtocol.get_capabilitesM  s     9:""KL	
 ll'')hh//,,++-C hh// 88~%"3u:s6{;;
rF   kwargsc           
         U(       d  g[        S5      nUR                  5        H  u  p4[        S5      nX5S'   [        U[        5      (       aq  Un/ nU H>  n[        SUU R	                  Xh   5      S9n	UR                  U	R                  5       5        M@     [        SUS9n
[        S	S
U
S9nUR                  5       US'   OU R	                  U5      US'   US   R                  UR                  5       /5        M     [        S5      nX,S'   U R                  R                  [        S5      U5         U R                  5       $ ! [         a  nUR                  S:w  a  e  SnAgSnAff = f)zSet capabilities.

Args:
    **kwargs: Arbitrary keyword arguments.

Returns:
    mysqlx.protobuf.Message: MySQL X Protobuf Message.
NzMysqlx.Connection.CapabilitieszMysqlx.Connection.Capabilityr   r   r   r   r   r   r   r   r   capabilitiesz!Mysqlx.Connection.CapabilitiesSetz/Mysqlx.ClientMessages.Type.CON_CAPABILITIES_SETi  )r   r   r   r   r   r   r   r   r   r   r   read_okr   errno)rB   r'  r)  r   r   
capabilityr   r   itemr   r   r   r   r  s                 rC   set_capabilitiesProtocol.set_capabilitiesa  sd    ?@ ,,.JC !?@J!$v%&&!D%= "..u{;G
 OOG$7$7$9: " "";J!"8qgN&-&9&9&;
7#&*&6&6u&=
7#(//1G1G1I0JK' )( 9:*N""KL	

	<<>! 	 yyD  !	s   .D> >
E#EE#method	auth_datainitial_responsec                     [        S5      nXS'   Ub  X$S'   Ub  X4S'   U R                  R                  [        S5      U5        g)zSend authenticate start.

Args:
    method (str): Message method.
    auth_data (Optional[str]): Authentication data.
    initial_response (Optional[str]): Initial response.
z Mysqlx.Session.AuthenticateStart	mech_nameNr1  r2  z2Mysqlx.ClientMessages.Type.SESS_AUTHENTICATE_STARTr   r   r   r   )rB   r0  r1  r2  r   s        rC   send_auth_startProtocol.send_auth_start  sR     89!K ('&6"#""NO	
rF   c                     U R                   R                  5       nUR                  S:X  a,  U R                   R                  5       nUR                  S:X  a  M,  UR                  S:w  a  [        S5      eUS   $ )zRead authenticate continue.

Raises:
    :class:`InterfaceError`: If the message type is not
                             `Mysqlx.Session.AuthenticateContinue`

Returns:
    str: The authentication data.
r  #Mysqlx.Session.AuthenticateContinuez>Unexpected message encountered during authentication handshaker1  r   r   r   r   r   s     rC   read_auth_continueProtocol.read_auth_continue  sn     ll'')hh//,,++-C hh//88<< P  ;rF   c                 b    [        SUS9nU R                  R                  [        S5      U5        g)zMSend authenticate continue.

Args:
    auth_data (str): Authentication data.
r9  )r1  z5Mysqlx.ClientMessages.Type.SESS_AUTHENTICATE_CONTINUENr5  )rB   r1  r   s      rC   send_auth_continueProtocol.send_auth_continue  s/     ;yQ""QR	
rF   c                      U R                   R                  5       nUR                  S:X  a  gUR                  S:X  a  [        UR                  5      eMR  )zfRead authenticate OK.

Raises:
    :class:`mysqlx.InterfaceError`: If message type is `Mysqlx.Error`.
zMysqlx.Session.AuthenticateOkr  N)r   r   r   r   r   r   s     rC   read_auth_okProtocol.read_auth_ok  sI     ,,++-Cxx::xx>)$SWW-- rF   r   c                 $   UR                   (       a  UR                  S:w  a  UR                  S:X  a  U R                  U5      u  pBOVUR                  S:X  a  U R                  U5      u  pBO2UR                  S:X  a  U R	                  U5      u  pBO[        SU 35      e[        UR                  5       5      n[        S5      n[        S5      n[        SXeS	9US
'   UR                  S:X  a  [        SXeS-   S	9US'   XrS'   [        U   u  p[        S5      n
[        U5      U
S'   X*U	'   [        S5      nUR                  US'   XS'   U R                  R                  [        S5      U5         U R                  5         g! [         a  n[         UeSnAff = f)aV  
Send prepare statement.

Args:
    msg_type (str): Message ID string.
    msg (mysqlx.protobuf.Message): MySQL X Protobuf Message.
    stmt (Statement): A `Statement` based type object.

Raises:
    :class:`mysqlx.NotSupportedError`: If prepared statements are not
                                       supported.

.. versionadded:: 8.0.16
Mysqlx.Crud.InsertMysqlx.Crud.FindMysqlx.Crud.UpdateMysqlx.Crud.DeletezInvalid message type: z!Mysqlx.Expr.Expr.Type.PLACEHOLDERzMysqlx.Crud.LimitExprzMysqlx.Expr.Expr)r   position	row_countr
   offset
limit_expr#Mysqlx.Prepare.Prepare.OneOfMessager   zMysqlx.Prepare.Preparestmt_idr   z*Mysqlx.ClientMessages.Type.PREPARE_PREPAREN)	has_limitr   
build_findbuild_updatebuild_deleter|   r   r   r   r   r   rM  r   r   r*  r   r   )rB   r   r   r   _rH  placeholdermsg_limit_expr
oneof_typeoneof_op	msg_oneofmsg_preparer  s                rC   send_prepare_prepareProtocol.send_prepare_prepare  s   6 >>chh*>>xx--.311**40311**403 #9(!DEE4,,./H'(KLK$%<=N*1"+N;' xx--+2&[a<,x( !/3H=
AB	)*5	&!(67!%I'F""FG	

	-LLN 	-#,	-s   (E9 9
FF

Fc                 "   [         U   u  pE[        S5      n[        U5      US'   X&U'   [        S5      nUR                  US'   U R	                  USS9nU(       a  US   R                  U5        UR                  (       al  US   R                  U R                  UR                  5       5      R                  5       U R                  UR                  5       5      R                  5       /5        U R                  R                  [        S5      U5        g	)
z
Send execute statement.

Args:
    msg_type (str): Message ID string.
    msg (mysqlx.protobuf.Message): MySQL X Protobuf Message.
    stmt (Statement): A `Statement` based type object.

.. versionadded:: 8.0.16
rL  r   zMysqlx.Prepare.ExecuterM  Fr   r   z*Mysqlx.ClientMessages.Type.PREPARE_EXECUTEN)r   r   r   rM  r   r   rN  r   get_limit_row_countr   get_limit_offsetr   r   )	rB   r   r   r   rU  rV  rW  msg_executer   s	            rC   send_prepare_executeProtocol.send_prepare_execute  s      4H=
AB	)*5	&!(67!%I%%de%<&&t,>>&&$$T%=%=%?@LLN$$T%:%:%<=IIK 	""FG	
rF   rM  c                     [        S5      nXS'   U R                  R                  [        S5      U5        U R	                  5         g)zf
Send prepare deallocate statement.

Args:
    stmt_id (int): Statement ID.

.. versionadded:: 8.0.16
zMysqlx.Prepare.DeallocaterM  z-Mysqlx.ClientMessages.Type.PREPARE_DEALLOCATEN)r   r   r   r   r*  )rB   rM  msg_deallocs      rC   send_prepare_deallocate Protocol.send_prepare_deallocate>  s@     9:!(I""IJ	
 	rF   c                 0   UR                   (       aE  [        S5      nUR                  5       US'   UR                  S:X  a  UR	                  5       US'   XBS'   US:g  nU R                  X5S9nU(       a  US   R                  U5        U R                  X5        g	)
z
Send a message without prepared statements support.

Args:
    msg_type (str): Message ID string.
    msg (mysqlx.protobuf.Message): MySQL X Protobuf Message.
    stmt (Statement): A `Statement` based type object.

.. versionadded:: 8.0.16
zMysqlx.Crud.LimitrI  rE  rJ  limit+Mysqlx.ClientMessages.Type.SQL_STMT_EXECUTEr\  r   N)rN  r   r]  r   r^  r   r   send_msg)rB   r   r   r   	msg_limitr   r   s          rC   send_msg_without_psProtocol.send_msg_without_psO  s      >> 34I%)%=%=%?Ik"xx--&*&;&;&=	(#$L MM	%%d%@Kt$h$rF   c                 N    U R                   R                  [        U5      U5        g)z
Send a message.

Args:
    msg_type (str): Message ID string.
    msg (mysqlx.protobuf.Message): MySQL X Protobuf Message.

.. versionadded:: 8.0.16
N)r   r   r   )rB   r   r   s      rC   ri  Protocol.send_msgk  s     	""=#:C@rF   c                 &   [        UR                  5       (       a  SOS5      n[        SUR                  R                  UR
                  R                  S9n[        SX#S9nUR                  (       a  UR                  5       US'   U R                  XA5        UR                  5       (       a  [        S5      US	'   O#UR                  5       (       a  [        S
5      US	'   UR                  R                  S:  a  UR                  R                  US'   SU4$ )aC  Build find/read message.

Args:
    stmt (Statement): A :class:`mysqlx.ReadStatement` or
                      :class:`mysqlx.FindStatement` object.

Returns:
    (tuple): Tuple containing:

        * `str`: Message ID string.
        * :class:`mysqlx.protobuf.Message`: MySQL X Protobuf Message.

.. versionadded:: 8.0.16
Mysqlx.Crud.DataModel.DOCUMENTMysqlx.Crud.DataModel.TABLEMysqlx.Crud.Collectionr   schemarE  
data_model
collection
projectionz'Mysqlx.Crud.Find.RowLock.EXCLUSIVE_LOCKlockingz$Mysqlx.Crud.Find.RowLock.SHARED_LOCKr   locking_optionsz$Mysqlx.ClientMessages.Type.CRUD_FIND)r   is_doc_basedr   targetr   rt  has_projectionget_projection_exprr   is_lock_exclusiveis_lock_sharedlock_contentionr   rB   r   rv  rw  r   s        rC   rO  Protocol.build_findw  s    " #  "" -.


 $!!;;##


 (ZW $ 8 8 :C3%!!##*+TUC	N  ""*+QRC	N%%)%)%9%9%?%?C!"5s::rF   c                    [        UR                  5       (       a  SOS5      n[        SUR                  R                  UR
                  R                  S9n[        SX#S9nU R                  XA5        UR                  5       R                  5        Hv  u  pV[        S5      nUR                  US'   UR                  US	'   UR                  b  [        UR                  5      US
'   US   R                  UR                  5       /5        Mx     SU4$ )aD  Build update message.

Args:
    stmt (Statement): A :class:`mysqlx.ModifyStatement` or
                      :class:`mysqlx.UpdateStatement` object.

Returns:
    (tuple): Tuple containing:

        * `str`: Message ID string.
        * :class:`mysqlx.protobuf.Message`: MySQL X Protobuf Message.

.. versionadded:: 8.0.16
rp  rq  rr  rs  rF  ru  zMysqlx.Crud.UpdateOperation	operationsourcer   z&Mysqlx.ClientMessages.Type.CRUD_UPDATE)r   r{  r   r|  r   rt  r   get_update_opsr   update_typer  r   r   r   r   )rB   r   rv  rw  r   rR  	update_opr  s           rC   rP  Protocol.build_update  s   " #  "" -.


 $!!;;##


  Z
 	3% //1779LA =>I%.%:%:Ik""+"2"2Ih*%/	%@	'"##Y%:%:%<$=> : 8<<rF   c                     [        UR                  5       (       a  SOS5      n[        SUR                  R                  UR
                  R                  S9n[        SX#S9nU R                  XA5        SU4$ )aD  Build delete message.

Args:
    stmt (Statement): A :class:`mysqlx.DeleteStatement` or
                      :class:`mysqlx.RemoveStatement` object.

Returns:
    (tuple): Tuple containing:

        * `str`: Message ID string.
        * :class:`mysqlx.protobuf.Message`: MySQL X Protobuf Message.

.. versionadded:: 8.0.16
rp  rq  rr  rs  rG  ru  z&Mysqlx.ClientMessages.Type.CRUD_DELETE)r   r{  r   r|  r   rt  r   r  s        rC   rQ  Protocol.build_delete  sz    " #  "" -.


 $!!;;##


  Z
 	3%7<<rF   	namespacefieldsc                 *   [        SUUSS9nU(       a}  / nUR                  5        H>  u  pg[        SUU R                  U5      S9nUR                  UR	                  5       5        M@     [        SUS9n	[        SS	U	S
9n
U
R	                  5       /US'   SU4$ )aZ  Build execute statement.

Args:
    namespace (str): The namespace.
    stmt (Statement): A `Statement` based type object.
    fields (Optional[dict]): The message fields.

Returns:
    (tuple): Tuple containing:

        * `str`: Message ID string.
        * :class:`mysqlx.protobuf.Message`: MySQL X Protobuf Message.

.. versionadded:: 8.0.16
zMysqlx.Sql.StmtExecuteF)r  r   compact_metadatar   r   r   r   r   r   r   r   rh  )r   r   r   r   r   )rB   r  r   r  r   r   r   r   r   r   r   s              rC   build_execute_statement Protocol.build_execute_statement  s    * $"	
 H$lln
!9**51
  3 3 56 - 7XFG41'JG"..01CK<cAArF   c                 n   [        U R                  5       (       a  SOS5      n[        SU R                  R                  U R
                  R                  S9n[        SXS9n[        U S5      (       ab  U R                   HR  n[        X@R                  5       (       + 5      R                  5       nUS   R                  UR                  5       /5        MT     U R                  5        H  n[        S	5      n[        U[        5      (       a6  U H/  nUS
   R                  [        U5      R                  5       /5        M1     O,US
   R                  [        U5      R                  5       /5        US   R                  UR                  5       /5        M     [        U S5      (       a  U R!                  5       US'   SU4$ )aC  Build insert statement.

Args:
    stmt (Statement): A :class:`mysqlx.AddStatement` or
                      :class:`mysqlx.InsertStatement` object.

Returns:
    (tuple): Tuple containing:

        * `str`: Message ID string.
        * :class:`mysqlx.protobuf.Message`: MySQL X Protobuf Message.

.. versionadded:: 8.0.16
rp  rq  rr  rs  rD  ru  _fieldsrx  zMysqlx.Crud.Insert.TypedRowfieldrow	is_upsertupsertz&Mysqlx.ClientMessages.Type.CRUD_INSERT)r   r{  r   r|  r   rt  hasattrr  r   parse_table_insert_fieldr   r   
get_valuesr   r   r   r  )	r   rv  rw  r   r  exprr   r  vals	            rC   build_insertProtocol.build_insert  s   $ #  "" -.


 $!!;;##


  Z
 4##!0022**,  L!(($*:*:*<)=>	 & __&E78C%&& CL''C)D)D)F(GH ! G##Z%6%B%B%D$EFJs012 ' 4%% NN,CM7<<rF   c                 B    U R                  U5      nUb  [        S5      eg)zClose the result.

Args:
    result (Result): A `Result` based type object.

Raises:
    :class:`mysqlx.OperationalError`: If message read is None.
NzExpected to close the result)r}   r   rB   r   r   s      rC   close_resultProtocol.close_resultJ  s*       (?"#ABB rF   c                     U R                  U5      nUc  gUR                  S:X  a  U$ U R                  R                  U5        g)zDRead row.

Args:
    result (Result): A `Result` based type object.
Nr  )r}   r   r   r   r  s      rC   read_rowProtocol.read_rowW  sC       (;88--J!!#&rF   c                    / n U R                  U5      nUc   U$ UR                  S:X  a  U R                  R                  U5         U$ UR                  S:w  a  [	        S5      e[        US   US   US   US   US   US	   US
   UR                  SS5      UR                  SS5      UR                  SS5      UR                  SS5      UR                  S5      5      nUR                  U5        M  )zReturns column metadata.

Args:
    result (Result): A `Result` based type object.

Raises:
    :class:`mysqlx.InterfaceError`: If unexpected message.
r  zMysqlx.Resultset.ColumnMetaDatazUnexpected msg typer   catalogrt  tableoriginal_tabler   original_namelength   	collationr   fractional_digitsflags   content_type)r}   r   r   r   r   r   getr   )rB   r   columnsr   cols        rC   get_column_metadataProtocol.get_column_metadatae  s    $$V,C{* ) xx11))#.$ # xx<<$%:;;FIHG$%FO$"%Q'+Q/$'C NN3/ rF   c                     U R                   R                  5       nUR                  S:X  a  [        SUS    3US   S9eUR                  S:w  a  [        S5      eg)	zMRead OK.

Raises:
    :class:`mysqlx.InterfaceError`: If unexpected message.
r  zMysqlx.Error: r   r  )r+  z	Mysqlx.OkzUnexpected message encounteredNr:  r   s     rC   r*  Protocol.read_ok  s[     ll'')88~% >#e*!>c&kRR88{" !ABB #rF   c                 d    [        S5      nU R                  R                  [        S5      U5        g)zSend connection close.zMysqlx.Connection.Closez$Mysqlx.ClientMessages.Type.CON_CLOSENr5  r   s     rC   send_connection_closeProtocol.send_connection_close  s*    /0""@A3	
rF   c                 d    [        S5      nU R                  R                  [        S5      U5        g)zSend close.zMysqlx.Session.Closez%Mysqlx.ClientMessages.Type.SESS_CLOSENr5  r   s     rC   
send_closeProtocol.send_close  s*    ,-""ABC	
rF   c                     [        S5      n[        S5      nXS'   SUS'   [        S5      nUR                  5       /US'   U R                  R	                  [        S5      U5        g	)
zSend expectation.z3Mysqlx.Expect.Open.Condition.Key.EXPECT_FIELD_EXISTzMysqlx.Expect.Open.Conditioncondition_keyz6.1condition_valuezMysqlx.Expect.Opencondz&Mysqlx.ClientMessages.Type.EXPECT_OPENN)r   r   r   r   r   )rB   cond_keymsg_ocmsg_eos       rC   send_expect_openProtocol.send_expect_open  sh     !VW78"*$) !-. ,,./v""BCV	
rF   	keep_openc                    [        S5      nUc#   U R                  5         U R                  5         SnU(       a  SUS'   U R                  R                  [        S5      U5        U R                  5         U(       a  gg! [         a    Sn NXf = f)zSend reset session message.

Returns:
    boolean: ``True`` if the server will keep the session open,
             otherwise ``False``.
zMysqlx.Session.ResetTFr  z%Mysqlx.ClientMessages.Type.SESS_RESET)r   r  r*  r   r   r   r   )rB   r  r   s      rC   
send_resetProtocol.send_reset  s     ,-"%%' 	 #C""ABC	
 	 " "!	"s   "A< <B
B)r   r   r   r   )T)NN)r4   Nrh   )DrZ   r[   r\   r]   r^   rd   r   rD   propertyr   r_   r   staticmethodr)   r    r   r   r   r	   r&   r   r   r+   r*   r   r,   r  r}   r   r%  r.  r6  r`   r;  r>  rA  r!   r   r#   r$   r%   r'   rY  r`  r   rd  rk  ri  r   rO  rP  rQ  r.   r   r  r   r"   r  r  r  r(   r  r*  r  r  r  r  ra   rb   rF   rC   r   r   J  s   '} 'm ' ' +x} + + 9; 9.A 9d 9 9 Hs Hx'< HV QU,-|;<,IM,	tDz4&9;R&R STT	U,\4+ 4~ 4$ 4lN x7L B0 0 0 (. . .f $(*.	

 C=
 #3-	

 

0 E  &

C 

D 

.B-B- B- 
	B- 
B-H#
#
"-#
5H#
	#
Js t "%% % '56	%
 
%8
A 
A; 
A4 
A(;-67(;	sK	 (;T'=/?:;'=	sK	 '=R=/?:;=	sK	 =J ,0	(B(B C&'(B c3h(	(B
 
sK	 (BT 2=L/122=	sK	 2= 2=hC> Cd C~ (;2G ". "T*=M "H
C


HTN d  rF   r   )Dr^   ry   r>   ior   typingr   r   r   r   r   r	   	lz4.framerK   HAVE_LZ4ImportError	zstandardr;   	HAVE_ZSTDerrorsr   r   r   r   r  r   r   r   r   r   r   helpersr   r   r   protobufr   r   r   r   r   r   r   	statementr   r   r    r!   r"   r#   r$   r%   r&   r'   typesr(   r)   r*   r+   r,   r-   r.   r/   r   r1   rd   r   r   rb   rF   rC   <module>r     s   : :    : :HI   7     	 	 	  A AHaH aHH:H :Hz@ @C	  H  Is"   C C CCCC