U
    eDN  ć                
   @   s¾  d Z dZdZegZzddlZdd eD ZdZW n ek
rH   dZY nX dd	l	m
Z
mZmZ zĪdd
lmZ ddlmZmZmZmZ ddlmZ zddlmZ e e” W n ek
rĄ   Y nX e e” eedrÜejZddlmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' i Z(e#j)j* +” D ]\Z,Z-e-e(de, < q$e#j.j* +” D ]\Z,Z-e-e(de, < qJe#j/j0 +” D ]\Z,Z-e-e(de, < qpej1 +” D ]\Z,Z-e-e(de, < qej2j3 +” D ]\Z,Z-e-e(de, < qŗej4j5 +” D ]\Z,Z-e-e(de, < qąej6j7 +” D ]\Z,Z-e-e(de, < qej8j* +” D ]\Z,Z-e-e(de, < q,ej9j* +” D ]\Z,Z-e-e(de, < qRe j:j;j< +” D ]\Z,Z-e-e(de, < qze j:j;j= +” D ]\Z,Z-e-e(de, < q¢e j:j> +” D ]\Z,Z-e-e(de, < qČe!j?j* +” D ]\Z,Z-e-e(de, < qīe!j@j* +” D ]\Z,Z-e-e(de, < qe"jAjB +” D ]\Z,Z-e-e(de, < q:e"jCjD +” D ]\Z,Z-e-e(d e, < q`e"jEjF +” D ]\Z,Z-e-e(d!e, < qe$jGjHj* +” D ]\Z,Z-e-e(d"e, < q®e%jIjJ +” D ]\Z,Z-e-e(d#e, < qŌe K” ZLe MeL”ZNeL OejP QejRjS”” eL OejP QejRjS”” eL OejP QejRjS”” eL OejP QejRjS”” eL OejP Qe jRjS”” eL OejP Qe!jRjS”” eL OejP Qe"jRjS”” eL OejP Qe#jRjS”” eL OejP Qe$jRjS”” eL OejP Qe%jRjS”” eL OejP Qe&jRjS”” eL OejP Qe'jRjS”” d$d eD ZdZTdZUG d%d& d&ZVW nV eeWeXfk
r ZY z0dZTedk	rZeYnd'ZUested(eU eYW 5 dZY[YX Y nX d)d*d+d,d-d.ZZG d/d0 d0Z[G d1d2 d2Z\d3d4 Z]dS )5z?Implementation of a helper class for MySQL X Protobuf messages.))zMysqlx.ServerMessages.Type.OKz	Mysqlx.Ok)z Mysqlx.ServerMessages.Type.ERRORzMysqlx.Error)z,Mysqlx.ServerMessages.Type.CONN_CAPABILITIESzMysqlx.Connection.Capabilities)z5Mysqlx.ServerMessages.Type.SESS_AUTHENTICATE_CONTINUEz#Mysqlx.Session.AuthenticateContinue)z/Mysqlx.ServerMessages.Type.SESS_AUTHENTICATE_OKzMysqlx.Session.AuthenticateOk)z!Mysqlx.ServerMessages.Type.NOTICEzMysqlx.Notice.Frame)z5Mysqlx.ServerMessages.Type.RESULTSET_COLUMN_META_DATAzMysqlx.Resultset.ColumnMetaData)z(Mysqlx.ServerMessages.Type.RESULTSET_ROWzMysqlx.Resultset.Row)z/Mysqlx.ServerMessages.Type.RESULTSET_FETCH_DONEzMysqlx.Resultset.FetchDone)z4Mysqlx.ServerMessages.Type.RESULTSET_FETCH_SUSPENDEDzMysqlx.Resultset.FetchSuspended)z?Mysqlx.ServerMessages.Type.RESULTSET_FETCH_DONE_MORE_RESULTSETSz(Mysqlx.Resultset.FetchDoneMoreResultsets)z.Mysqlx.ServerMessages.Type.SQL_STMT_EXECUTE_OKzMysqlx.Sql.StmtExecuteOk)z?Mysqlx.ServerMessages.Type.RESULTSET_FETCH_DONE_MORE_OUT_PARAMSz'Mysqlx.Resultset.FetchDoneMoreOutParams)z&Mysqlx.ServerMessages.Type.COMPRESSIONzMysqlx.Connection.CompressionNé    c                 C   s    i | ]\}}t t |”|qS © )ŚintŚ	_mysqlxpbŚ
enum_value©Ś.0ŚkeyŚvalr   r   śY/var/www/html/assets/scripts/venv/lib/python3.8/site-packages/mysqlx/protobuf/__init__.pyŚ
<dictcomp>U   s     r   TFé   )Ś
BYTE_TYPESŚNUMERIC_TYPESŚencode_to_bytes)Śprotobuf)Śdescriptor_databaseŚdescriptor_pb2Śdescriptor_poolŚmessage_factory)ŚRepeatedCompositeFieldContainer)ŚRepeatedCompositeContainerŚ__version__é   )Śmysqlx_connection_pb2Śmysqlx_crud_pb2Śmysqlx_cursor_pb2Śmysqlx_datatypes_pb2Śmysqlx_expect_pb2Śmysqlx_expr_pb2Śmysqlx_notice_pb2Ś
mysqlx_pb2Śmysqlx_prepare_pb2Śmysqlx_resultset_pb2Śmysqlx_session_pb2Śmysqlx_sql_pb2zMysqlx.ClientMessages.Type.zMysqlx.ServerMessages.Type.zMysqlx.Error.Severity.zMysqlx.Crud.DataModel.zMysqlx.Crud.Find.RowLock.zMysqlx.Crud.Order.Direction.z'Mysqlx.Crud.UpdateOperation.UpdateType.zMysqlx.Datatypes.Scalar.Type.zMysqlx.Datatypes.Any.Type.z0Mysqlx.Expect.Open.Condition.ConditionOperation.z!Mysqlx.Expect.Open.Condition.Key.z Mysqlx.Expect.Open.CtxOperation.zMysqlx.Expr.Expr.Type.z"Mysqlx.Expr.DocumentPathItem.Type.zMysqlx.Notice.Frame.Scope.zMysqlx.Notice.Warning.Level.z,Mysqlx.Notice.SessionStateChanged.Parameter.z)Mysqlx.Prepare.Prepare.OneOfMessage.Type.z*Mysqlx.Resultset.ColumnMetaData.FieldType.c                 C   s   i | ]\}}t | |qS r   ©Ś	_MESSAGESr   r   r   r
   r   ż   s      c                   @   s`   e Zd ZdZe ” Zedd Zedd Z	edd Z
edd	 Zed
d Zedd ZdS )Ś_mysqlxpb_purez]This class implements the methods in pure Python used by the
        _mysqlxpb C++ extension.c                 C   s   t j t | ””}| S )z«Create new Protobuf message.

            Args:
                name (str): Message type name.

            Returns:
                object: Protobuf message.
            )r'   ŚfactoryZGetPrototypeŚ_DESCRIPTOR_POOLZFindMessageTypeByName)ŚnameŚclsr   r   r
   Śnew_message  s    
’z_mysqlxpb_pure.new_messagec                 C   s   t |  S )zReturn enum value.

            Args:
                enum_key (str): Enum key.

            Returns:
                object: Protobuf message.
            r%   )Zenum_keyr   r   r
   r     s    
z_mysqlxpb_pure.enum_valuec                 C   s   |   ” S )zØSerialize message.

            Args:
                msg (object): Protobuf message.

            Returns:
                str: Serialized message string.
            )ZSerializeToString©Śmsgr   r   r
   Śserialize_message"  s    
z _mysqlxpb_pure.serialize_messagec                 C   s   |   ” S )zøSerialize partial message.

            Args:
                msg (object): Protobuf message.

            Returns:
                str: Serialized partial message string.
            )ZSerializePartialToStringr-   r   r   r
   Śserialize_partial_message.  s    
z(_mysqlxpb_pure.serialize_partial_messagec                 C   s   t  | ”}| |” |S )zęSerialize partial message.

            Args:
                msg_type_name (str): Message type name.
                payload (bytes): Payload.

            Returns:
                object: Message parsed from string.
            )r'   r,   ŚParseFromString)Śmsg_type_nameŚpayloadr.   r   r   r
   Śparse_message:  s    

z_mysqlxpb_pure.parse_messagec                 C   s4   t  | ”}|std|  t |”}| |” |S )zėParse server message message.

            Args:
                msg_type (str): Message type name.
                payload (bytes): Payload.

            Returns:
                object: Server message parsed from string.
            zUnknown msg_type: )ŚSERVER_MESSAGESŚgetŚ
ValueErrorr'   r,   r1   )Śmsg_typer3   r2   r.   r   r   r
   Śparse_server_messageI  s    


z#_mysqlxpb_pure.parse_server_messageN)Ś__name__Ś
__module__Ś__qualname__Ś__doc__r   ZMessageFactoryr(   Śstaticmethodr,   r   r/   r0   r4   r9   r   r   r   r
   r'     s   




r'   zProtobuf >=3.11.0 is requiredśProtobuf is not available: )z-Mysqlx.Prepare.Prepare.OneOfMessage.Type.FINDŚfind)z/Mysqlx.Prepare.Prepare.OneOfMessage.Type.INSERTŚinsert)z/Mysqlx.Prepare.Prepare.OneOfMessage.Type.UPDATEŚupdate)z/Mysqlx.Prepare.Prepare.OneOfMessage.Type.DELETEŚdelete)z-Mysqlx.Prepare.Prepare.OneOfMessage.Type.STMTZstmt_execute)z$Mysqlx.ClientMessages.Type.CRUD_FINDz&Mysqlx.ClientMessages.Type.CRUD_INSERTz&Mysqlx.ClientMessages.Type.CRUD_UPDATEz&Mysqlx.ClientMessages.Type.CRUD_DELETEz+Mysqlx.ClientMessages.Type.SQL_STMT_EXECUTEc                   @   s.   e Zd ZdZereneZe Ze	dd Z
dS )ŚProtobufzŁProtobuf class acts as a container of the Protobuf message class.

    It allows the switch between the C extension and pure Python implementation
    message handlers, by patching the `mysqlxpb` class attribute.
    c                 C   s>   | rt stdt | s&ts&td| r.tntt_| t_dS )z”Sets whether to use the C extension or pure Python implementation.

        Args:
            use_pure (bool): `True` to use pure Python implementation.
        r?   z-MySQL X Protobuf C extension is not availableN)	ŚHAVE_PROTOBUFŚImportErrorŚHAVE_PROTOBUF_ERRORŚHAVE_MYSQLXPB_CEXTr'   r   rD   ŚmysqlxpbŚuse_pure)rJ   r   r   r
   Śset_use_pure  s    zProtobuf.set_use_pureN)r:   r;   r<   r=   rH   r   r'   rI   rJ   r>   rK   r   r   r   r
   rD   {  s
   rD   c                   @   s¬   e Zd ZdZd#ddZdd Zdd Zd	d
 Zdd Zd$ddZ	dd Z
dd Zdd Zdd Zedd Zedd Zedd Zedd Zedd  Zed!d" ZdS )%ŚMessagezŠHelper class for interfacing with the MySQL X Protobuf extension.

    Args:
        msg_type_name (string): Protobuf type name.
        **kwargs: Arbitrary keyword arguments with values for the message.
    Nc                 K   s<   |rt j |”nd | jd< | ” D ]\}}|  ||” q"d S )NŚ_msg)rD   rI   r,   Ś__dict__ŚitemsŚ__setattr__)Śselfr2   Śkwargsr*   Śvaluer   r   r
   Ś__init__  s    ’zMessage.__init__c                 C   sŠ   t jrt|tr$t| j|t| qĢt|ttfrBt| j|| qĢt|t	r`t
| j| |” qĢt|trt
| j| | ” ” qĢt
| j| |” n6t|tr°t|| j|< nt|trĀ| ” n|| j|< d S ©N)rD   rJ   Ś
isinstanceŚstrŚsetattrrM   r   r   r   ŚlistŚgetattrŚextendrL   Z	MergeFromŚget_message©rQ   r*   rS   r   r   r
   rP   £  s    



’zMessage.__setattr__c                 C   s>   zt js| j| n
t| j|W S  tk
r8   td Y nX d S rU   )rD   rJ   rM   rZ   ŚKeyErrorŚAttributeError©rQ   r*   r   r   r
   Ś__getattr__·  s
    ’zMessage.__getattr__c                 C   s   |   ||” d S rU   )rP   r]   r   r   r
   Ś__setitem__æ  s    zMessage.__setitem__c                 C   s
   |   |”S rU   )ra   r`   r   r   r
   Ś__getitem__Ā  s    zMessage.__getitem__c                 C   s*   t js| jd  ||”S t| jd ||S )a  Returns the value of an element of the message dictionary.

        Args:
            name (string): Key name.
            default (object): The default value if the key does not exists.

        Returns:
            object: The value of the provided key name.
        rM   )rD   rJ   rN   r6   rZ   )rQ   r*   Śdefaultr   r   r
   r6   Å  s    ’żzMessage.getc                 C   s   || j d< dS )zdSets the message.

        Args:
            msg (dict): Dictionary representing a message.
        rM   N©rN   )rQ   r.   r   r   r
   Śset_messageÕ  s    zMessage.set_messagec                 C   s
   | j d S )zøReturns the dictionary representing a message containing parsed
        data.

        Returns:
            dict: The dictionary representing a message containing parsed data.
        rM   re   ©rQ   r   r   r
   r\   Ż  s    zMessage.get_messagec                 C   s   t j | j”S )zSerializes a message to a string.

        Returns:
            str: A string representing a message containing parsed data.
        )rD   rI   r/   rM   rg   r   r   r
   Śserialize_to_stringę  s    zMessage.serialize_to_stringc                 C   s   t j | j”S )z’Serializes the protocol message to a binary string.

        This method is similar to serialize_to_string but doesn't check if the
        message is initialized.

        Returns:
            str: A string representation of the partial message.
        )rD   rI   r0   rM   rg   r   r   r
   Śserialize_partial_to_stringī  s    	z#Message.serialize_partial_to_stringc                 C   s   t js| jd S | jjjS )zstring: Message type name.Z_mysqlxpb_type_name)rD   rJ   rM   Ś
DESCRIPTORZ	full_namerg   r   r   r
   Śtypeł  s    ’żzMessage.typec                 C   s   t j | |”S )a>  Creates a new message, initialized with parsed data.

        Args:
            msg_type_name (string): Message type name.
            payload (string): Serialized message data.

        Returns:
            dict: The dictionary representing a message containing parsed data.

        .. versionadded:: 8.0.21
        )rD   rI   r4   )r2   r3   r   r   r
   Śparse  s    zMessage.parsec                 C   s   t jr|  ” S tt|  ” S )zéReturns the size of the message in bytes.

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

        Returns:
            int: Size of the message in bytes.

        .. versionadded:: 8.0.21
        )rD   rJ   ZByteSizeŚlenr   rh   r-   r   r   r
   Ś	byte_size  s    ’
żzMessage.byte_sizec                 C   s   t j | |”S )a  Creates a new server-side message, initialized with parsed data.

        Args:
            msg_type (int): Message type.
            payload (string): Serialized message data.

        Returns:
            dict: The dictionary representing a message containing parsed data.
        )rD   rI   r9   )r8   r3   r   r   r
   Śparse_from_server#  s    zMessage.parse_from_serverc                 C   s   |  }|  tj ||”” |S )a  Creates a new message, initialized with parsed data and returns a
        :class:`mysqlx.protobuf.Message` object.

        Args:
            msg_type_name (string): Message type name.
            payload (string): Serialized message data.

        Returns:
            mysqlx.protobuf.Message: The Message representing a message
                                     containing parsed data.
        )rf   rD   rI   r4   )r+   r2   r3   r.   r   r   r
   Śfrom_message0  s    zMessage.from_messagec                 C   s   |  }|  tj ||”” |S )a  Creates a new server-side message, initialized with parsed data and
        returns a :class:`mysqlx.protobuf.Message` object.

        Args:
            msg_type (int): Message type.
            payload (string): Serialized message data.

        Returns:
            mysqlx.protobuf.Message: The Message representing a message
                                     containing parsed data.
        )rf   rD   rI   r9   )r+   r8   r3   r.   r   r   r
   Śfrom_server_messageA  s    zMessage.from_server_message)N)N)r:   r;   r<   r=   rT   rP   ra   rb   rc   r6   rf   r\   rh   ri   Śpropertyrk   r>   rl   rn   ro   Śclassmethodrp   rq   r   r   r   r
   rL     s.   

	




rL   c                 C   s   t j | ”S )zÆReturns the value of a MySQL X Protobuf enumerator.

    Args:
        name (string): MySQL X Protobuf numerator name.

    Returns:
        int: Value of the enumerator.
    )rD   rI   r   )r*   r   r   r
   Śmysqlxpb_enumS  s    	rt   )^r=   Z_SERVER_MESSAGES_TUPLESZPROTOBUF_VERSIONrY   ZPROTOBUF_REPEATED_TYPESr   r5   rH   rF   Śhelpersr   r   r   Zgoogler   Zgoogle.protobufr   r   r   r   Z#google.protobuf.internal.containersr   Zgoogle.protobuf.pyext._messager   ŚappendŚhasattrr   Ś r   r   r   r   r   r   r   r    r!   r"   r#   r$   r&   ZClientMessagesŚTyperO   r   r	   ZServerMessagesŚErrorZSeverityZ	DataModelZFindZRowLockZOrderZ	DirectionZUpdateOperationZ
UpdateTypeZScalarŚAnyZOpenŚ	ConditionZConditionOperationŚKeyZCtxOperationŚExprZDocumentPathItemŚFrameZScopeŚWarningZLevelZSessionStateChangedŚ	ParameterZPrepareZOneOfMessageZColumnMetaDataZ	FieldTypeZDescriptorDatabaseZ_DESCRIPTOR_DBZDescriptorPoolr)   ŚAddZFileDescriptorProtoZ
FromStringrj   Zserialized_pbrE   rG   r'   ŚSyntaxErrorŚ	TypeErrorŚerrZCRUD_PREPARE_MAPPINGrD   rL   rt   r   r   r   r
   Ś<module>   s$  /’


8
’’’’’’’’’’’’’’’’’’’’’’’’Z’"ļ @