1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
U
¤ý°d{ã@s<dZddlZddlZddlZddlZddlZddlmZmZm    Z    m
Z
m Z ddl m Z mZddlmZddlmZmZeefZeeejfZd!eeed    œd
d „Zd"eeed    œd d „Zeeedœdd„Zee ee    efdœdd„Z d#eeedœdd„Z!d$e
ee
eedœdd„Z"ee    ee    edœdd„Z#eedœdd „Z$dS)%z&This module contains helper functions.éN)ÚAnyÚCallableÚListÚOptionalÚUnioné)ÚTLS_CIPHER_SUITESÚ TLS_VERSIONS)ÚInterfaceError)Ú EscapeTypesÚ
StrOrBytesúutf-8)ÚvalueÚencodingÚreturncCst|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©rr©rúEd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\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ÚdecoderrrrÚdecode_from_bytes;s
r)ÚobjÚkeyrcCst|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)rrrrrÚget_item_or_attrHs
r)Úargsrcs:ttdœdd„‰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.
    )rrcSs¾|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\)rÚ NUMERIC_TYPESrÚ    bytearrayÚreplace)rrrrÚ_escapeas$
           zescape.<locals>._escapercsg|] }ˆ|ƒ‘qSrr)Ú.0Úarg©r/rrÚ
<listcomp>xszescape.<locals>.<listcomp>r)r Úlen)rrr2rÚescapeUs  r5Ú)Ú
identifierÚsql_modercCs8|dkr | dd¡}d|›dS| dd¡}d|›d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_QUOTESr*z""ú`z``)r.)r7r8ÚquotedrrrÚquote_identifier|s
   r;)ÚversionÚreasonrcsttdœ‡‡fdd„ }|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.
 
    Returns:
        Callable: A decorator used to mark functions as deprecated.
 
    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
    )Úfuncrcs(t ˆ¡tttdœ‡‡‡fdd„ ƒ}|S)zDecorate function.)rÚkwargsrcsndˆj›dg}ˆr$| dˆ›¡ˆr8| dˆ›¡t ¡j}tjd |¡tt     |j
¡|j dˆ||ŽS)zžWrapper function.
 
            Args:
                *args: Variable length argument list.
                **kwargs: Arbitrary keyword arguments.
            r)z' is deprecatedz since version z. r6)ÚcategoryÚfilenameÚlineno) Ú__name__ÚappendÚinspectÚ currentframeÚf_backÚwarningsÚ warn_explicitÚjoinÚDeprecationWarningÚgetfileÚf_codeÚf_lineno)rr?ÚmessageÚframe)r>r=r<rrÚwrapper¦s
 
üz-deprecated.<locals>.decorate.<locals>.wrapper)Ú    functoolsÚwrapsrr)r>rQ©r=r<)r>rÚdecorate£szdeprecated.<locals>.decorate)r)r<r=rUrrTrÚ
deprecatedŽsrV)Ú tls_versionÚcipher_suites_namesrcCs|g}i}tt |¡dƒD]}| tt|¡q|D]@}d|krN| |¡q6||krf| ||¡q6td|›dƒ‚q6|S)aTranslates 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.
 
    Returns:
        List[str]: List of translated names.
    rú-zThe 'z.' in cipher suites is not a valid cipher suite)Úranger    ÚindexÚupdaterrDr
)rWrXZtranslated_namesZ cipher_suitesr[ÚnamerrrÚiani_to_openssl_cs_nameÁs  
ÿr^)ÚdatarcCst |¡ d¡S)z»Return the hexadecimal representation of the binary data.
 
    Args:
        data (bytes): The binary data.
 
    Returns:
        str: The decoded hexadecimal representation of data.
    r )ÚbinasciiÚhexlifyr)r_rrrraás    ra)r )r )r6)NN)%Ú__doc__r`ÚdecimalrRrErHÚtypingrrrrrÚ    constantsrr    Úerrorsr
Útypesr r r-rZ
BYTE_TYPESÚintÚfloatÚDecimalr,ÚstrrrÚobjectrr5r;rVr^rarrrrÚ<module>s,     '4þ