U Yzf_@sdZddlZddlZddlZddlmZddlmZmZddl m Z ddd Z dd d Z d d Z ddZdddZdddZddZdS)z&This module contains helper functions.N) NUMERIC_TYPES)TLS_CIPHER_SUITES TLS_VERSIONS)InterfaceErrorutf-8cCst|tr|S||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. ) isinstancebytesencodevalueencodingrf/private/var/folders/n9/53xbvtmd7sjg1q1l55xmpg58n4mgng/T/pip-unpacked-wheel-47tvuv7y/mysqlx/helpers.pyencode_to_bytes's rcCst|tr||S|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. )rr decoder rrrdecode_from_bytes3s rcCst|tr||St||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. )rdictgetattr)objkeyrrrget_item_or_attr@s rcs2ddt|dkr&fdd|DS|dS)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. cSs|dkr |St|tr|St|ttfrr|dd}|dd}|dd}|dd }|d d }|d d }nH|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\)rrr bytearrayreplace)r rrr_escapeXs$            zescape.._escapercsg|] }|qSrr).0argr&rr nszescape..r)len)argsrr)rescapeMs  r-cCs,|dkrd|ddSd|ddS)acQuote 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. Z ANSI_QUOTESz"{0}"r"z""z`{0}``z``)formatr%) identifierZsql_moderrrquote_identifierrs r2csfdd}|S)aThis 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 cstfdd}|S)zDecorate function.csldjg}r"|dr6|dtj}tjd|t t |j |j d||S)zWrapper function. Args: *args: Variable length argument list. **kwargs: Arbitrary keyword arguments. z'{}' is deprecatedz since version {}z. {}r.)categoryfilenamelineno) r0__name__appendinspect currentframef_backwarnings warn_explicitjoinDeprecationWarninggetfilef_codef_lineno)r,kwargsmessageframe)funcreasonversionrrwrappers   z-deprecated..decorate..wrapper) functoolswraps)rErHrFrG)rErdecorateszdeprecated..decorater)rGrFrLrrKr deprecatedsrMcCszg}i}tt|dD]}|tt|q|D]>}d|krN||q6||krf|||q6td|q6|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)rangerindexupdaterr7rr0)Z tls_versionZcipher_suites_namesZtranslated_namesZ cipher_suitesrPnamerrriani_to_openssl_cs_names rS)r)r)r.)NN)__doc__rIr8r;compatr constantsrrerrorsrrrrr-r2rMrSrrrrs    %  )