U Yzf_ã@sˆdZddlZddlZddlZddlmZddlmZmZddl m Z ddd „Z dd d „Z d d „Z dd„Zddd„Zddd„Zdd„ZdS)z&This module contains helper functions.éNé)Ú NUMERIC_TYPES)ÚTLS_CIPHER_SUITESÚ TLS_VERSIONS)ÚInterfaceErrorúutf-8cCst|tƒr|S| |¡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Úencoding©rúf/private/var/folders/n9/53xbvtmd7sjg1q1l55xmpg58n4mgng/T/pip-unpacked-wheel-47tvuv7y/mysqlx/helpers.pyÚencode_to_bytes's rcCst|tƒr| |¡S|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. )rr Údecoder rrrÚdecode_from_bytes3s rcCst|tƒr||St||ƒ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ÚkeyrrrÚget_item_or_attr@s rcs2dd„‰t|ƒdkr&‡fdd„|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. cSs¾|dkr |St|tƒr|St|ttfƒrr| 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 Ú bytearrayÚreplace)r rrrÚ_escapeXs$            zescape.._escapercsg|] }ˆ|ƒ‘qSrr)Ú.0Úarg©r&rrÚ nszescape..r)Úlen)Úargsrr)rÚescapeMs  r-ÚcCs,|dkrd | dd¡¡Sd | dd¡¡S)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_moderrrÚquote_identifierrs r2cs‡‡fdd„}|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 cst ˆ¡‡‡‡fdd„ƒ}|S)zDecorate function.csld ˆj¡g}ˆr"| d ˆ¡¡ˆr6| d ˆ¡¡t ¡j}tjd |¡t t  |j ¡|j d�ˆ||ŽS)zžWrapper function. Args: *args: Variable length argument list. **kwargs: Arbitrary keyword arguments. z'{}' is deprecatedz since version {}z. {}r.)ÚcategoryÚfilenameÚlineno) r0Ú__name__ÚappendÚinspectÚ currentframeÚf_backÚwarningsÚ warn_explicitÚjoinÚDeprecationWarningÚgetfileÚf_codeÚf_lineno)r,ÚkwargsÚmessageÚframe)ÚfuncÚreasonÚversionrrÚwrapper•s   ýz-deprecated..decorate..wrapper)Ú functoolsÚwraps)rErH©rFrG)rErÚdecorate“szdeprecated..decorater)rGrFrLrrKrÚ deprecated‚srMcCszg}i}tt |¡dƒD]}| tt|¡q|D]>}d|krN| |¡q6||krf| ||¡q6td |¡ƒ‚q6|S)zãTranslates 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Úupdaterr7rr0)Z tls_versionZcipher_suites_namesZtranslated_namesZ cipher_suitesrPÚnamerrrÚiani_to_openssl_cs_name«s ÿrS)r)r)r.)NN)Ú__doc__rIr8r;ÚcompatrÚ constantsrrÚerrorsrrrrr-r2rMrSrrrrÚs    %  )