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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
U
£ý°dñMã@srUdZddlZddlZddlZddlZddlZddlZddlmZddl    m
Z
ddl m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZddlmZmZmZmZmZm Z m!Z!ddl"m#Z#dd    l$m%Z%d
Z&e'e(d <e)e*ee#fZ+ee e)e e*e ee e#fe(d <e!e)e,fe)d œdd„Z-e)e.dœdd„Z/e)e.dœdd„Z0e)e.dœdd„Z1e)e.dœdd„Z2e)e.dœdd„Z3e)e.dœdd„Z4e)e,dœdd„Z5e,e)ee,e,fdœd d!„Z6e,ee,ee,fd œd"d#„Z7e,eeee,d$fd œd%d&„Z8dOe,ee,ee)ee,e,fd'œd(d)„Z9e,e)ee,e)fdœd*d+„Z:e,ee,ee)fd œd,d-„Z;e%e<d œd.d/„Z=dPe%ee<e)dd1œd2d3„Z>ee<e<fd4œd5d6„Z?ee<e<fd4œd7d8„Z@eee<e<fd4œd9d:„ZAee<e<e<fd4œd;d<„ZBe<e<d=œd>d?„ZCe<ee<ee<ge'ffd=œd@dA„ZDe<eee<e<fdBœdCdD„ZEe<e<dEœdFdG„ZFdQe!e)e%fe<e.dJœdKdL„ZGe
ƒee<e!e<ee<e<fffd4œdMdN„ƒZHdS)Rz
Utilities.éN)ÚDecimal)Ú    lru_cache)Ú in_table_a1Ú in_table_b1Ú in_table_c3Ú in_table_c4Ú in_table_c5Ú in_table_c6Ú in_table_c7Ú in_table_c8Ú in_table_c9Ú in_table_c11Ú in_table_c12Úin_table_c21_c22Ú in_table_d1Ú in_table_d2)ÚCallableÚDictÚListÚOptionalÚTupleÚTypeÚUnioné)Ú
HexLiteral)Ú
StrOrBytesFÚ__MYSQL_DEBUG__Ú NUMERIC_TYPES)ÚbufÚreturncCsvt|tƒr|St|ƒ}|dkr&|dS|dkrR|dd|}tt d|¡dƒS|dd|}tt d|¡dƒS)z&Unpacks the given buffer to an integerrréóú<Iéú<Q)Ú
isinstanceÚintÚlenÚstructÚunpack)rÚlengthÚtmp©r,úLd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\mysql/connector/utils.pyÚintreadGs
r.)ÚircCs(|dks|dkrtdƒ‚tt d|¡ƒS)z^
    Takes an unsigned byte (1 byte) and packs it as a bytes-object.
 
    Returns string.
    réÿz int1store requires 0 <= i <= 255ú<B©Ú
ValueErrorÚ    bytearrayr(Úpack©r/r,r,r-Ú    int1storeUsr7cCs(|dks|dkrtdƒ‚tt d|¡ƒS)z`
    Takes an unsigned short (2 bytes) and packs it as a bytes-object.
 
    Returns string.
    réÿÿz"int2store requires 0 <= i <= 65535ú<Hr2r6r,r,r-Ú    int2store`sr:cCs0|dks|dkrtdƒ‚tt d|¡dd…ƒS)zb
    Takes an unsigned integer (3 bytes) and packs it as a bytes-object.
 
    Returns string.
    réÿÿÿz%int3store requires 0 <= i <= 16777215r"ér2r6r,r,r-Ú    int3storeksr=cCs(|dks|dkrtdƒ‚tt d|¡ƒS)zb
    Takes an unsigned integer (4 bytes) and packs it as a bytes-object.
 
    Returns string.
    rìÿÿz'int4store requires 0 <= i <= 4294967295r"r2r6r,r,r-Ú    int4storevsr?cCs(|dks|dkrtdƒ‚tt d|¡ƒS)zZ
    Takes an unsigned integer (8 bytes) and packs it as string.
 
    Returns string.
    rìz!int8store requires 0 <= i <= 2^64r$r2r6r,r,r-Ú    int8storesrAcCs\|dks|dkrtdƒ‚|dkr&t}n.|dkr4t}n |dkrBt}n|dkrPt}nt}||ƒS)zÍ
    Takes an unsigned integers and packs it as a bytes-object.
 
    This function uses int1store, int2store, int3store,
    int4store or int8store depending on the integer value.
 
    returns string.
    rr@z!intstore requires 0 <= i <=  2^64r0r8r;r>)r3r7r:r=r?rA)r/Z formed_stringr,r,r-ÚintstoreŒs    rBcCs„|dks|dkrtdƒ‚|dkr0tt d|¡ƒS|dkrLdtt d|¡ƒS|d    krpd
tt d |¡dd …ƒSd tt d|¡ƒS)z|
    Takes an unsigned integer and packs it as bytes,
    with the information of how much bytes the encoded int takes.
    rr@zRequires 0 <= i <= 2^64éûr1r8óür9r;óýr"r<óþr$r2r6r,r,r-Úlc_int¦srG)rÚsizercCs|d|…}||d…|fS)zi
    Reads bytes from a buffer.
 
    Returns a tuple with buffer less the read bytes, and the bytes.
    rNr,©rrHÚresr,r,r-Ú
read_bytes¸s rKcCsÀ|ddkr|dd…dfSd}}|d}|dkrX|}|d|d…|d|d…fS|dkrfd}n|dkrtd    }n |d
kr€d }t|d|d…ƒ}|||dd…||d||d…fS) u›
    Takes a buffer and reads a length coded string from the start.
 
    This is how Length coded strings work
 
    If the string is 250 bytes long or smaller, then it looks like this:
 
      <-- 1b  -->
      +----------+-------------------------
      |  length  | a string goes here
      +----------+-------------------------
 
    If the string is bigger than 250, then it looks like this:
 
      <- 1b -><- 2/3/8 ->
      +------+-----------+-------------------------
      | type |  length   | a string goes here
      +------+-----------+-------------------------
 
      if type == Ã¼:
          length is code in next 2 bytes
      elif type == Ã½:
          length is code in next 3 bytes
      elif type == Ã¾:
          length is code in next 8 bytes
 
    NULL has a special value. If the buffer starts with Ã» then
    it's a NULL and we return None as value.
 
    Returns a tuple (trucated buffer, bytes).
    rrCrNéúéüééýr<éþr#©r.)rr*ÚlsizeZfstr,r,r-Úread_lc_stringÂs   rS.cCsg}ddddœ}t|ƒ}d}||kr
||}|dkr:dS|dkrV| d¡|d    7}q|d
krŽ|}| ||d    ||d    …¡|d    |7}qd}z ||}Wntk
r´YdSXt||d    ||d    …ƒ}| ||d    ||||d    …¡|d    ||7}qt|ƒS) zXReads all length encoded strings from the given buffer
 
    Returns a list of bytes
    rNr<r#)rMrOrPrr0NrCrrL)r'ÚappendÚKeyErrorr.Útuple)rZbyteslstÚsizesZbuf_lenÚposÚfirstr*rRr,r,r-Úread_lc_string_list÷s0 
 
 
 &rZ)rÚendrHrc
Cs–|dkr|dkrtdƒ‚|dk    rxz| |¡}Wn,tk
rZ}ztdƒ|‚W5d}~XYnX||dd…|d|…fS|dk    rŠt||ƒStdƒ‚dS)zr
    Reads a string up until a character or for a given size.
 
    Returns a tuple (trucated buffer, string).
    Nz&read_string() needs either end or sizezend byte not present in bufferrrz.read_string() needs either end or size (weird))r3ÚindexrK)rr[rHÚidxÚerrr,r,r-Ú read_strings
 
r_cCs t|d|…ƒ}||d…|fS)zMRead an integer from buffer
 
    Returns a tuple (truncated buffer, int)
    rNrQrIr,r,r-Úread_int8sr`cCsÜ|s tdƒ‚|d}|dkr,|dd…dfS|dkrH|dd…t|ƒfS|dkrt|dd…t d|dd…¡dfS|d    kr¤|d
d…t d |dd
…d ¡dfS|d krÐ|dd…t d|dd…¡dfStdƒ‚dS)z
    Takes a buffer and reads an length code string from the start.
 
    Returns a tuple with buffer less the integer and the integer read.
    z Empty buffer.rrCrNrMr<z<xHrOr r"r!rPé    z<xQz%Failed reading length encoded integer)r3r&r(r))rZlcbyter,r,r-Ú read_lc_intAs$($rbcCs2t|tƒsd dd„|Dƒ¡Sd dd„|Dƒ¡S)z"Debug function for showing buffersÚcSsg|]}d|d›‘qS©z\xZ02xr,©Ú.0Úcr,r,r-Ú
<listcomp>^sz"_digest_buffer.<locals>.<listcomp>cSsg|]}dt|ƒd›‘qSrd)Úordrer,r,r-rh_s)r%ÚstrÚjoin)rr,r,r-Ú_digest_buffer[s
rlé)ÚabufferÚprefixÚlimitrcCsL|r<|r"|dkr"t|d|…ƒ}nt|ƒ}t|d|ƒn tt|ƒƒdS)z2Debug function printing output of _digest_buffer()rz: N)rlÚprint)rnrorpÚdigestr,r,r-Ú print_bufferbs  rs)rc    Csˆi}tj dd¡}tj |¡s"|St|ddP}|D]D}| d¡}t|ƒdkrPq4|d ¡}|d d    ¡     d
¡}|||<q4W5QRX|S) zsParse the contents of /etc/os-release file.
 
    Returns:
        A dictionary containing release information.
    ú/etcz
os-releaseúutf-8©Úencodingú=rNrrÚ
ú"©
ÚosÚpathrkÚexistsÚopenÚsplitr'ÚlowerÚrstripÚstrip)ÚdistroZos_release_fileÚfile_objÚlineÚ    key_valueÚkeyÚvaluer,r,r-Ú_parse_os_releaseps 
  rŠc    Cs„i}tj dd¡}tj |¡r€t|ddP}|D]D}| d¡}t|ƒdkrLq0|d ¡}|d d    ¡     d
¡}|||<q0W5QRX|S) ztParse the contents of /etc/lsb-release file.
 
    Returns:
        A dictionary containing release information.
    rtz lsb-releaserurvrxrNrrryrzr{)r„Zlsb_release_filer…r†r‡rˆr‰r,r,r-Ú_parse_lsb_release…s 
  r‹c    Cs¶i}ttjddd˜}ztjd|d}Wn tk
rHYW5QR£dSX| t ¡¡     ¡}|D]F}| 
d¡}t |ƒdkr|q`|d      d
d ¡  ¡}|d  d ¡}|||<q`W5QRX|S)ztParse the output of the lsb_release command.
 
    Returns:
        A dictionary containing release information.
    Úwrurv)Z lsb_releasez-a)ÚstderrNú:rNrú Ú_rú    )rr|ÚdevnullÚ
subprocessÚ check_outputÚOSErrorÚdecodeÚsysÚgetfilesystemencodingÚ
splitlinesr€r'Úreplacerrƒ)r„r’ÚstdoutÚlinesr†r‡rˆr‰r,r,r-Ú_parse_lsb_release_command™s
 rcCsˆtƒ}|r,| dd¡| dd¡| dd¡fStƒ}|rX| dd¡| dd¡| dd¡fStƒ}|r„| dd¡| d    d¡| d
d¡fSd S) aNTries to determine the name of the Linux OS distribution name.
 
    First tries to get information from ``/etc/os-release`` file.
    If fails, tries to get the information of ``/etc/lsb-release`` file.
    And finally the information of ``lsb-release`` command.
 
    Returns:
        A tuple with (`name`, `version`, `codename`)
    Z
distrib_idrcZdistrib_releaseZdistrib_codenameZdistributor_idÚreleaseZcodenameÚnameZ
version_idZversion_codename)rcrcrc)r‹ÚgetrrŠ)r„r,r,r-Úlinux_distribution°s&
 
 
 
ý
 
 
ý
 
 
ýr¡)Ú unicode_strrcCs|rt |d¡dkrdSdS)zÈGet the readiness direction of the unicode string.
 
    We assume that the direction is "L-to-R" if the first character does not
    indicate the direction is "R-to-L" or an "AL" (Arabic Letter).
    r)ÚRÚALúR-to-LzL-to-R)Ú unicodedataÚ bidirectional)r¢r,r,r-Ú_get_unicode_read_directionÕsr¨cCs@t|ƒ}|dkr8t|dƒr(t|dƒs0tdƒ‚dtiSdtiS)at
    1) The characters in section 5.8 MUST be prohibited.
 
    2) If a string contains any RandALCat character, the string MUST NOT
       contain any LCat character.
 
    3) If a string contains any RandALCat character, a RandALCat
       character MUST be the first character of the string, and a
       RandALCat character MUST be the last character of the string.
    r¥réÿÿÿÿzvInvalid unicode Bidirectional sequence, if the first character is RandALCat, the final charactermust be RandALCat too.z7Bidirectional Characters requirement 2 [StringPrep, d2])r¨rr3r)r¢Zread_dirr,r,r-Ú_get_unicode_direction_ruleãs ÿrª)Únormalized_strrc Cs¤ttttttttttt    t
dœ }z|  t |ƒ¡Wn2t k
rb}z|t|ƒfWY¢Sd}~XYnX|D]6}| ¡D](\}}||ƒrt|dkrt||fSqtqhdS)aªCheck for Prohibited Output according to rfc4013 profile.
 
    This profile specifies the following characters as prohibited input:
 
       - Non-ASCII space characters [StringPrep, C.1.2]
       - ASCII control characters [StringPrep, C.2.1]
       - Non-ASCII control characters [StringPrep, C.2.2]
       - Private Use characters [StringPrep, C.3]
       - Non-character code points [StringPrep, C.4]
       - Surrogate code points [StringPrep, C.5]
       - Inappropriate for plain text characters [StringPrep, C.6]
       - Inappropriate for canonical representation characters [StringPrep, C.7]
       - Change display properties or deprecated characters [StringPrep, C.8]
       - Tagging characters [StringPrep, C.9]
 
    In addition of checking of Bidirectional Characters [StringPrep, Section 6]
    and the Unassigned Code Points [StringPrep, A.1].
 
    Returns:
        A tuple with ("probited character", "breaked_rule")
    ) z4Space characters that contains the ASCII code pointsz&Space characters non-ASCII code pointsz(Unassigned Code Points [StringPrep, A.1]z.Non-ASCII space characters [StringPrep, C.1.2]z,ASCII control characters [StringPrep, C.2.1]z(Private Use characters [StringPrep, C.3]z+Non-character code points [StringPrep, C.4]z'Surrogate code points [StringPrep, C.5]z9Inappropriate for plain text characters [StringPrep, C.6]zGInappropriate for canonical representation characters [StringPrep, C.7]zDChange display properties or deprecated characters [StringPrep, C.8]z$Tagging characters [StringPrep, C.9]Nr)r rrrrrrr    r
r r Úupdaterªr3rjÚitems)r«Úrulesr^ÚcharZruleÚfuncr,r,r-Ú"validate_normalized_unicode_stringÿs,ô"r±)Úa_stringrcCs0dd„|Dƒ}d |¡}t d|¡}|s,dS|S)a(normalizes a unicode string according to rfc4013
 
    Normalization of a unicode string according to rfc4013: The SASLprep profile
    of the "stringprep" algorithm.
 
    Normalization Unicode equivalence is the specification by the Unicode
    character encoding standard that some sequences of code points represent
    essentially the same character.
 
    This method normalizes using the Normalization Form Compatibility
    Composition (NFKC), as described in rfc4013 2.2.
 
    Returns:
        Normalized unicode string according to rfc4013.
    cSs(g|] }t|ƒrdnt|ƒr dn|‘qS)rrc)rr)rfr¯r,r,r-rhFsÿz,normalize_unicode_string.<locals>.<listcomp>rcÚNFKC)rkr¦Ú    normalize)r²Z    nstr_listZnstrr,r,r-Únormalize_unicode_string3sþ
 rµóru)Úpayloadrwrc
Csrt|tƒr|St|tƒr t|ƒSt|tƒsjzt|j|dƒWStk
rh}ztdƒ|‚W5d}~XYnXt|ƒS)z(Initialize a bytearray from the payload.rvzpayload must be a str or bytesN)r%r4r&ÚbytesÚencodeÚAttributeErrorr3)r·rwr^r,r,r-Úinit_bytearrayXs
 
 
r»cCs¸dddœ}tjdkrldt ¡dkr.d|d<n&dt ¡dkrHd    |d<n t ¡|d<d
t ¡d ›|d <nHt ¡|d<t ¡d krœdt ¡d›|d <nd t    ƒdd…¡|d <|S)z4Return a dict with the platform arch and OS version.rc)ÚarchÚversionÚntÚ64rÚx86_64r¼Ú32Úi386zWindows-rr½ÚDarwinzmacOS-ú-rN)
r|rŸÚplatformÚ architectureÚ    win32_verÚmachineÚsystemÚmac_verrkr¡)Úplatr,r,r-Ú get_platformis
 
 
 
   rÌ)NN)Nrm)r¶ru)IÚ__doc__r|rÅr(r“r—r¦ÚdecimalrÚ    functoolsrÚ
stringpreprrrrrr    r
r r r rrrrÚtypingrrrrrrrZ custom_typesrÚtypesrrÚboolÚ__annotations__r&Úfloatrr¸r.r4r7r:r=r?rArBrGrKrSrZr_r`rbrjrlrsrŠr‹rr¡r¨rªr±rµr»rÌr,r,r,r-Ú<module>s†  @$   ü(     
5 *ý
ü     ÿþ %"þ 4&ÿ
þ