
    "ij                         d Z ddlZddlZddlZddlZddlZddlmZmZ ddl	m
Z
 eefZeeej        fZddZddZd	 Zd
 ZddZddZd Zd ZdS )z&This module contains helper functions.    N   )TLS_CIPHER_SUITESTLS_VERSIONS)InterfaceErrorutf-8c                 Z    t          | t                    r| n|                     |          S )zReturns 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     F/srv/django_bis/venv311/lib/python3.11/site-packages/mysqlx/helpers.pyencode_to_bytesr   -   s)     ue,,H55%,,x2H2HH    c                 Z    t          | t                    r|                     |          n| S )zReturns 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   9   s*     &0u%=%=H5<<!!!5Hr   c                 \    t          | t                    r| |         nt          | |          S )zGet 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   F   s+     "#t,,C3s88'#s2C2CCr   c                  n    d t          |           dk    rfd| 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|                     dd          } |                     dd          } |                     dd          } |                     dd	          } |                     d
d          } |                     dd          } n|                     dd          } |                     dd          } |                     dd          } |                     dd          } |                     dd          } |                     dd          } | S )zEscapes 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   _escapezescape.<locals>._escape^   s%   =L}-- 	LeeY/00 	6MM%11EMM%00EMM%00EMM';77EMM';77EMM';77EEMM$//EMM$..EMM$..EMM&*55EMM&*55EMM&*55Er   r   c                 &    g | ]} |          S  r.   ).0argr,   s     r   
<listcomp>zescape.<locals>.<listcomp>t   s!    ------r   r   )len)argsr,   s    @r   escaper4   S   sQ      * 4yy1}}--------747r    c                     |dk    r)d                     |                     dd                    S d                     |                     dd                    S )ac  Quote the given identifier with backticks, converting backticks (`)
    in the identifier name with the correct escape sequence (``) unless the
    identifier is quoted (") as in sql_mode set to ANSI_QUOTES.

    Args:
        identifier (str): Identifier to quote.

    Returns:
        str: Returns string with the identifier quoted with backticks.
    ANSI_QUOTESz"{0}"r'   z""z`{0}``z``)formatr+   )
identifiersql_modes     r   quote_identifierr<   x   sS     =  ~~j00d;;<<<>>*,,S$77888r   c                       fd}|S )a  This is a decorator used to mark functions as deprecated.

    Args:
        version (Optional[string]): Version when was deprecated.
        reason (Optional[string]): Reason or extra information to be shown.

    Usage:

    .. code-block:: python

       from mysqlx.helpers import deprecated

       @deprecated('8.0.12', 'Please use other_function() instead')
       def deprecated_function(x, y):
           return x + y
    c                 L     t          j                    fd            }|S )zDecorate function.c                     d                     j                  g}r(|                    d                                          r(|                    d                                          t          j                    j        }t          j        d                    |          t          t          j
        |j                  |j                    | i |S )zWrapper function.

            Args:
                *args: Variable length argument list.
                **kwargs: Arbitrary keyword arguments.
            z'{}' is deprecatedz since version {}z. {}r5   )categoryfilenamelineno)r9   __name__appendinspectcurrentframef_backwarningswarn_explicitjoinDeprecationWarninggetfilef_codef_lineno)r3   kwargsmessageframefuncreasonversions       r   wrapperz-deprecated.<locals>.decorate.<locals>.wrapper   s     ,224=AABG D299'BBCCC 6v}}V44555(**1E"2777#3#3,>,3OEL,I,I*/.: : : : 4((((r   )	functoolswraps)rR   rU   rS   rT   s   ` r   decoratezdeprecated.<locals>.decorate   sC    				) 	) 	) 	) 	) 	) 
		)$ r   r.   )rT   rS   rX   s   `` r   
deprecatedrY      s)    "     , Or   c                 r   g }i }t          t          j        |           dz             D ]-}|                    t          t          |                             .|D ]]}d|v r|                    |           ||v r|                    ||                    <t          d                    |                    |S )zTranslates a cipher suites names list; from IANI names to OpenSSL names.

    Args:
        TLS_version (str): The TLS version to look at for a translation.
        cipher_suite_names (list): A list of cipher suites names.
    r   -z5The '{}' in cipher suites is not a valid cipher suite)ranger   indexupdater   rD   r   r9   )tls_versioncipher_suites_namestranslated_namescipher_suitesr]   names         r   iani_to_openssl_cs_namerd      s     M |)+66:;; E E.|E/BCDDDD# > >$;;##D))))]""##M$$78888  "006t> > >r   c                 P    t          j        |                               d          S )zReturn the hexadecimal representation of the binary data.

    Args:
        data (str): The binary data.

    Returns:
        bytes: The hexadecimal representation of data.
    r   )binasciihexlifyr   )datas    r   rg   rg      s#     D!!((111r   )r   )r5   )NN)__doc__rf   decimalrV   rE   rH   	constantsr   r   errorsr   r*   r
   
BYTE_TYPESintfloatDecimalr)   r   r   r   r4   r<   rY   rd   rg   r.   r   r   <module>rq      s$  : - ,         6 6 6 6 6 6 6 6 " " " " " "  
eW_.	I 	I 	I 	I
I 
I 
I 
I
D 
D 
D" " "J9 9 9 9 ' ' ' 'T  4	2 	2 	2 	2 	2r   