File: D:/Python311/Lib/site-packages/mysqlx/__pycache__/helpers.cpython-311.pyc
�
�ncH � � � d Z ddlZddlZddlZddlZddlZddlmZmZ ddl m
Z
eefZ
eeej fZdd�Zdd�Zd � Zd
� Zdd�Zdd
�Zd� Zd� ZdS )z&This module contains helper functions.� N� )�TLS_CIPHER_SUITES�TLS_VERSIONS)�InterfaceError�utf-8c �Z � t | t � � r| n| � |� � S )z�Returns an encoded version of the string as a bytes object.
Args:
encoding (str): The encoding.
Resturns:
bytes: The encoded version of the string as a bytes object.
)�
isinstance�bytes�encode��value�encodings �0D:\Python311\Lib\site-packages\mysqlx/helpers.py�encode_to_bytesr , s) � � �u�e�,�,�H�5�5�%�,�,�x�2H�2H�H� c �Z � t | t � � r| � |� � n| S )z�Returns a string decoded from the given bytes.
Args:
value (bytes): The value to be decoded.
encoding (str): The encoding.
Returns:
str: The value decoded from bytes.
)r r
�decoder s r �decode_from_bytesr 8 s* � � &0��u�%=�%=�H�5�<�<��!�!�!�5�Hr c �\ � t | t � � r| | nt | |� � S )z�Get item from dictionary or attribute from object.
Args:
obj (object): Dictionary or object.
key (str): Key.
Returns:
object: The object for the provided key.
)r �dict�getattr)�obj�keys r �get_item_or_attrr E s+ � � "�#�t�,�,�C�3�s�8�8�'�#�s�2C�2C�Cr c �n �� d� �t | � � dk r�fd�| D � � S �| d � � S )a
Escapes special characters as they are expected to be when MySQL
receives them.
As found in MySQL source mysys/charset.c
Args:
value (object): Value to be escaped.
Returns:
str: The value if not a string, or the escaped string.
c � � | �| S t | t � � r| S t | t t f� � r�| � dd� � } | � dd� � } | � dd� � } | � dd � � } | � d
d� � } | � dd
� � } n�| � dd� � } | � dd� � } | � dd� � } | � dd� � } | � dd� � } | � dd� � } | S )zEscapes special characters.N� \s \\�
s \n�
s \r� 's \'� "s \"� s \�\z\\�
z\n�
z\r�'z\'�"z\"�z\)r �
NUMERIC_TYPESr
� bytearray�replace)r
s r �_escapezescape.<locals>._escape^ s( � �� ��L��e�]�+�+� ��L��e�e�Y�/�0�0�
6��M�M�%��1�1�E��M�M�%��0�0�E��M�M�%��0�0�E��M�M�'�;�7�7�E��M�M�'�;�7�7�E��M�M�'�;�7�7�E�E��M�M�$��/�/�E��M�M�$��.�.�E��M�M�$��.�.�E��M�M�&�*�5�5�E��M�M�&�*�5�5�E��M�M�&�*�5�5�E��r r c �&