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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
U
¤ý°d®àã@sdZddlmZddlmZzLddlZdZejejej    dœZ
e edƒrLej nej e
d<e ed    ƒodejZWn ek
rˆd
Zd
ZiZ
YnXddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZdd lmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%zddl&Z'ddl(Z'Wnek
r<d
Z)YnXdZ)dd l*m*Z*m+Z+dd l,m-Z-ddl.m/Z/ddl0m1Z1m2Z2m3Z3ddl4m5Z5m6Z6m7Z7ddl8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ddlAmBZBddlCmDZDmEZEmFZFmGZGmHZHmIZIddlJmKZKmLZLmMZMddlNmNZNddlOmPZPddlQmRZRmSZSmTZTmUZUmVZVddlWmXZXmYZYmZZZm[Z[m\Z\ddl]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhddlmiZimjZjmkZkmlZlejm nd¡ddlompZpmqZqmrZrmsZsddltmuZuddlvmwZwmxZxd d!d"d#œZyd$Zzd%Z{d&Z|d'Z}d(Z~d)Zd*Z€e d+¡Z‚d,Zƒd,Z„d-Z…d.Z†d/Z‡d/Zˆd0Z‰d.ZŠe†e†e…e…eˆe‡e‡e‰d1œZ‹d2eŠiZŒe d3¡Ze d4ejŽ¡Ze d5ejŽ¡Ze d6¡Z‘d7d8d9d:d;d<gZ’e’d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKgZ“dLdMdNœdOdP„Z”dQdRdSœdTdU„Z•GdVdW„dWƒZ–dXdXdYœdZd[„Z—Gd\d]„d]e˜ƒZ™Gd^d_„d_ƒZšGd`da„daƒZ›Gdbdc„dce›ƒZœGddde„deejƒZžGdfdg„dgƒZŸGdhdi„diƒZ Gdjdk„dkƒZ¡dMdldmœdndo„Z¢dMdpdqœdrds„Z£dpdRdtœdudv„Z¤dŠdpdwdRdxœdydz„Z¥dpdRdtœd{d|„Z¦dpdRdtœd}d~„Z§dpdRdtœdd€„Z¨dLdLdpdœd‚dƒ„Z©dLdLdidœd„d…„Zªd†d†dkd‡œdˆd‰„Z«dS)‹z4Implementation of communication for MySQL X servers.é)Ú annotations)Ú TracebackTypeNT)ÚTLSv1úTLSv1.1úTLSv1.2Ú PROTOCOL_TLSúTLSv1.3Ú HAS_TLSv1_3F)    ÚAnyÚCallableÚDictÚListÚMappingÚOptionalÚTupleÚTypeÚUnion)ÚdatetimeÚ    timedelta©Úwraps)ÚJSONDecodeError)Ú    parse_qslÚunquoteÚurlparseé)ÚMySQL41AuthPluginÚPlainAuthPluginÚSha256MemoryAuthPlugin)ÚCOMPRESSION_ALGORITHMSÚDEPRECATED_TLS_VERSIONSÚOPENSSL_CS_NAMESÚSUPPORTED_TLS_VERSIONSÚTLS_CIPHER_SUITESÚAuthÚ CompressionÚSSLMode©ÚSchema)ÚInterfaceErrorÚNotSupportedErrorÚOperationalErrorÚ    PoolErrorÚProgrammingErrorÚ TimeoutError)ÚescapeÚget_item_or_attrÚiani_to_openssl_cs_name)Úlogger)ÚProtobuf)ÚHAVE_LZ4Ú    HAVE_ZSTDÚ MessageReaderÚ MessageWriterÚProtocol)Ú
BaseResultÚ    DocResultÚResultÚ    RowResultÚ    SqlResult) Ú AddStatementÚDeleteStatementÚ FindStatementÚInsertStatementÚModifyStatementÚ ReadStatementÚRemoveStatementÚSelectStatementÚ SqlStatementÚUpdateStatementÚquote_identifier)Ú
ColumnTypeÚ MessageTypeÚResultBaseTypeÚ StatementTypeú..)ÚDUPLICATED_IN_LIST_ERRORÚTLS_VER_NO_SUPPORTEDÚTLS_VERSION_DEPRECATED_ERRORÚTLS_VERSION_ERROR)Úlinux_distribution)ÚLICENSEÚVERSIONz‘This session was closed because the connection has been idle for too long. Use 'mysqlx.getSession()' or 'mysqlx.getClient()' to create a new one.z<This session was closed because the server is shutting down.zThis session was closed because the connection has been killed in a different session. Use 'mysqlx.getSession()' or 'mysqlx.getClient()' to create a new one.)iéia i'zDROP DATABASE IF EXISTS {}z CREATE DATABASE IF NOT EXISTS {}zLSELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '{}'zSELECT @@versionécéxz[^a-zA-Z0-9._:\-*$#]i›Ä i@Bé<ii€Q)z[WinError 10053]z
[Errno 32]z[WinError 10061]z [Errno 111]z[WinError 10060]z [Errno 11001]z
[Errno -2]z Access deniedrUz,(?![^\(\)]*\))z!^\(address=(.+),priority=(\d+)\)$z^\(address=(.+)[,]*\)$z"^([a-zA-Z][a-zA-Z0-9+\-.]+)://(.*)ússl-certússl-caússl-keyússl-crlú tls-versionsútls-ciphersuitesÚuserÚpasswordÚschemaÚhostÚportÚroutersÚsocketússl-modeÚauthúuse-pureúconnect-timeoutúconnection-attributesÚ compressionúcompression-algorithmsúdns-srvr
Ústr)ÚkwargsÚreturnc    KsPg}dD]0}z| t||ƒ¡Wqtk
r6YqXq|sFtdƒ‚d |¡S)abGenerate a pool name.
 
    This function takes keyword arguments, usually the connection arguments and
    tries to generate a name for the pool.
 
    Args:
        **kwargs: Arbitrary keyword arguments with the connection arguments.
 
    Raises:
        PoolError: If the name can't be generated.
 
    Returns:
        str: The generated pool name.
    )rbrcr_ZdatabaseÚ    client_idz.Failed generating pool name; specify pool_nameÚ_)ÚappendrnÚKeyErrorr,Újoin)roÚpartsÚkey©rxúHd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\mysqlx/connection.pyÚgenerate_pool_nameØsrzúMapping[str, Any]ÚNone)Ú penalty_dictrpcCs|rt|tƒrt |¡dS)zÊUpdate the timeout penalties directory.
 
    Update the timeout penalties by error dictionary used to deactivate a pool.
    Args:
        penalty_dict (dict): The dictionary with the new timeouts.
    N)Ú
isinstanceÚdictÚ_TIMEOUT_PENALTIES_BY_ERR_NOÚupdate)r}rxrxryÚ!update_timeout_penalties_by_errorôsr‚c    @sÄeZdZdZddœdd„Zefddddœd    d
„Zd d d œdd„Zd ddœdd„Zddœdd„Z    ddœdd„Z
dddddddddœdd„Z ddœdd„Z ddœdd „Z ddœd!d"„Zddœd#d$„Zd%S)&Ú SocketStreamzImplements a socket stream.r|©rpcCsd|_d|_d|_d|_dS)NF)Ú_socketÚ_is_sslÚ
_is_socketÚ_host©ÚselfrxrxryÚ__init__szSocketStream.__init__rÚfloat)ÚparamsÚconnect_timeoutrpc Cs¢|dk    r|d}zt ||¡|_|d|_Wndtk
rz0t tj¡|_|j |¡|j |¡d|_Wnt    k
rŠt
dƒd‚YnXYnX|j d¡dS)zÇConnects to a TCP service.
 
        Args:
            params (tuple): The connection parameters.
 
        Raises:
            :class:`mysqlx.InterfaceError`: If Unix socket is not supported.
        NéèrTzUnix socket unsupported) reÚcreate_connectionr…rˆÚ
ValueErrorÚAF_UNIXÚ
settimeoutÚconnectr‡ÚAttributeErrorr))rŠrrŽrxrxryr”s"    ÿ  
zSocketStream.connectÚintÚbytes)ÚcountrpcCs\|jdkrtdƒ‚g}|dkrR|j |¡}|dkr:tdƒ‚| |¡|t|ƒ8}qd |¡S)z“Receive data from the socket.
 
        Args:
            count (int): Buffer size.
 
        Returns:
            bytes: The data received.
        NúMySQLx Connection not availablerózUnexpected connection close)r…r+ÚrecvÚ RuntimeErrorrsÚlenru)rŠr˜ÚbufÚdatarxrxryÚread"s    
 
zSocketStream.read)rŸrpc
CsZ|jdkrtdƒ‚z|j |¡Wn2tk
rT}ztd|›ƒ|‚W5d}~XYnXdS)z_Send data to the socket.
 
        Args:
            data (bytes): The data to be sent.
        Nr™zUnexpected socket error: )r…r+ÚsendallÚOSError)rŠrŸÚerrrxrxryr¡6s 
zSocketStream.sendallcCsF|js
dSz|j tj¡|j ¡Wntk
r:YnXd|_dS)zClose the socket.N)r…ÚshutdownreÚ    SHUT_RDWRÚcloser¢r‰rxrxryr¦CszSocketStream.closecCs | ¡dS©N©r¦r‰rxrxryÚ__del__OszSocketStream.__del__ú    List[str]rn)Ú
ssl_protosÚssl_modeÚssl_caÚssl_crlÚssl_certÚssl_keyÚ ssl_ciphersrpc Cs„ts| ¡tdƒ‚|dks |sLt ¡}|tjkr8d|_|tjkrâtj    |_
n–|j dd|d}    t s€|    dkr€t |ƒdkr€|d}    t|    }
t |
¡}|    dkrâd    |kr²|jtjO_d
|krÊ|jtjO_d |krâ|jtjO_|rBz| |¡tj|_
WnBttjfk
r@} z| ¡td | ›ƒ| ‚W5d} ~ XYnX|r¢z| |¡tj|_WnBttjfk
r } z| ¡td | ›ƒ| ‚W5d} ~ XYnX|rüz| ||¡WnBttjfk
rú} z| ¡td| ›ƒ| ‚W5d} ~ XYnX|r| d t|d|ƒ¡¡z|j|j |j!d|_ Wn2tj"k
rf} zt| ›ƒ| ‚W5d} ~ XYnX|tjkrNd|_g} t#j$dkrž|j!dkržddg} t% &|j!¡} |  '| dg| d¡d}g}| D]\}zt (|j  )¡|¡Wn4tj"k
r} z| *t+| ƒ¡W5d} ~ XYn Xd}q,qÎ|sN| ¡tdd |¡›ƒ‚d|_,|j  -¡}    |    dkr€d|    ›d}t. /|t0¡dS)axSet SSL parameters.
 
        Args:
            ssl_protos (list): SSL protocol to use.
            ssl_mode (str): SSL mode.
            ssl_ca (str): The certification authority certificate.
            ssl_crl (str): The certification revocation lists.
            ssl_cert (str): The certificate.
            ssl_key (str): The certificate key.
            ssl_ciphers (list): SSL ciphersuites to use.
 
        Raises:
            :class:`mysqlx.RuntimeError`: If Python installation has no SSL
                                          support.
            :class:`mysqlx.InterfaceError`: If the parameters are invalid.
        z&Python installation has no SSL supportNFT©ÚreverserrrrrrzInvalid CA Certificate: z Invalid CRL: zInvalid Certificate/Key: ú:)Úserver_hostnameÚnt)Ú    localhostú    127.0.0.1r·r¸z"Unable to verify server identity: ú, )rrzThis connection is using zZ which is now deprecated and will be removed in a future release of MySQL Connector/Python)1Ú SSL_AVAILABLEr¦rœÚsslÚcreate_default_contextr&ÚVERIFY_IDENTITYÚcheck_hostnameÚREQUIREDÚ    CERT_NONEÚ verify_modeÚsortÚTLS_V1_3_SUPPORTEDrÚ TLS_VERSIONSÚ
SSLContextÚoptionsÚ OP_NO_TLSv1_2Ú OP_NO_TLSv1_1Ú OP_NO_TLSv1Úload_verify_locationsÚ CERT_REQUIREDÚIOErrorÚSSLErrorr)ÚVERIFY_CRL_CHECK_LEAFÚ verify_flagsÚload_cert_chainÚ set_ciphersrur1Ú wrap_socketr…rˆÚCertificateErrorÚosÚnamereÚ gethostbyaddrÚextendÚmatch_hostnameÚ getpeercertrsrnr†ÚversionÚwarningsÚwarnÚDeprecationWarning)rŠr«r¬r­r®r¯r°r±ÚcontextÚ tls_versionZ ssl_protocolr£Z    hostnamesÚaliasesZ match_foundZerrsÚhostnameZwarn_msgrxrxryÚset_sslRs¤ 
 
 
 ÿþ
ý
 
 "
 ""ÿ   
ÿ
 
 
ÿzSocketStream.set_sslÚboolcCs|jS)zpVerifies if SSL is being used.
 
        Returns:
            bool: Returns `True` if SSL is being used.
        )r†r‰rxrxryÚis_sslÒszSocketStream.is_sslcCs|jS)zŒVerifies if socket connection is being used.
 
        Returns:
            bool: Returns `True` if socket connection is being used.
        )r‡r‰rxrxryÚ    is_socketÚszSocketStream.is_socketcCs |jp
|jS)zvVerifies if connection is secure.
 
        Returns:
            bool: Returns `True` if connection is secure.
        )r†r‡r‰rxrxryÚ    is_secureâszSocketStream.is_securecCs
|jdk    S)zrVerifies if connection is open.
 
        Returns:
            bool: Returns `True` if connection is open.
        N)r…r‰rxrxryÚis_openêszSocketStream.is_openN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r‹Ú_CONNECT_TIMEOUTr”r r¡r¦r©rârärårærçrxrxrxryrƒÿs  rƒr )Úfuncrpcs$tˆƒdddddœ‡fdd„ ƒ}|S)z¼Decorator used to catch OSError or RuntimeError.
 
    Raises:
        :class:`mysqlx.InterfaceError`: If `OSError` or `RuntimeError`
                                        is raised.
    r
)rŠÚargsrorpc     s¨z¤t|ttfƒr$| ¡r$t| ¡Ž‚ˆ|f|ž|Ž}t|tƒr | ¡}|D]T}|dtkrJt|d}d|d›d|›|df}t|ttfƒrš|     |¡q qJ|WStt
t t fk
r¢}zֈj dkrˆ|rˆt|dtƒrˆ|d ¡}|rˆ|d}t|d}d|d›d|›|df}t|tƒr\|j ¡|ddkr\tƒ |jt|Ž¡t|ttfƒrv|     |¡| ¡t|Ž|‚| ¡‚W5d}~XYnXdS)    zWrapper function.ÚcodezConnection close: Úmsgz: Úget_column_metadatarrUN)r~Ú
ConnectionÚPooledConnectionÚis_server_disconnectedr)Úget_disconnected_reasonr9Z get_warningsÚCONNECTION_CLOSED_ERRORÚset_server_disconnectedr¢rœr.rèr=ÚpoolÚremove_connectionsÚ PoolsManagerÚset_pool_unavailableÚ
disconnect)    rŠrîroÚresultZwarnsrÜÚ    error_msgÚreasonr£©rírxryÚwrapperûs\ ÿþ 
  þ
ÿþ ý  þ 
ÿ
 
z(catch_network_exception.<locals>.wrapperr)rírrxrryÚcatch_network_exceptionós2rcsReZdZdZdddœ‡fdd„ Zddœd    d
„Zddœd d „Zd dœdd„Z‡ZS)ÚRouterz“Represents a set of connection parameters.
 
    Args:
       settings (dict): Dictionary with connection settings
    .. versionadded:: 8.0.20
    r{r|)Úconnection_paramsrpcs(tƒ ¡| |¡| dd¡|d<dS)NÚ    availableT)Úsuperr‹rÚget)rŠr©Ú    __class__rxryr‹9s
 
zRouter.__init__rãr„cCs|dS)z’Verifies if the Router is available to open connections.
 
        Returns:
            bool: True if this Router is available else False.
        rrxr‰rxrxryr>szRouter.availablecCs d|d<dS)z1Sets this Router unavailable to open connections.FrNrxr‰rxrxryÚset_unavailableFszRouter.set_unavailablez%Union[str, Tuple[str, Optional[int]]]cCs d|kr|dS|d|dfS)z‘Verifies if the Router is available to open connections.
 
        Returns:
            tuple: host and port or socket information tuple.
        rerbrcrxr‰rxrxryÚget_connection_paramsJszRouter.get_connection_params)    rèrérêrër‹rr
r Ú __classcell__rxrxrryr1s
rc@szeZdZdZddddœdd„Zddœd    d
„Zd dd œd d„Zd dd œdd„Zddœdd„Zddœdd„Z    ddœdd„Z
dS)Ú RouterManagerzÒManages the connection parameters of all the routers.
 
    Args:
        Routers (list): A list of Router objects.
        settings (dict): Dictionary with connection settings.
    .. versionadded:: 8.0.20
    z List[Router]úDict[str, Any]r|)rdÚsettingsrpcCs0||_||_d|_d|_i|_g|_| ¡dS)NrT)Ú_routersÚ    _settingsÚ_cur_priority_idxÚ _can_failoverÚ_routers_directoryÚrouters_priority_listÚ_ensure_priorities)rŠrdrrxrxryr‹^szRouterManager.__init__r„cCsØd}|jD]<}| dd¡}|dkr4|d7}d|d<q
|dkr
tddƒ‚q
d|krbt|jƒkrpnn
tdd    ƒ‚|jjd
d „d d |jD]H}|d}||jkr¾t|ƒg|j|<|j |¡qŠ|j| t|ƒ¡qŠdS)zuEnsure priorities.
 
        Raises:
            :class:`mysqlx.ProgrammingError`: If priorities are invalid.
        rÚpriorityNrédz(The priorities must be between 0 and 100é§ú\You must either assign no priority to any of the routers or give a priority for every routeré cSs|dS)Nrrx©ÚxrxrxryÚ<lambda>€ršz2RouterManager._ensure_priorities.<locals>.<lambda>T)rwr³)    rrr-rrÂrrrrs)rŠÚpriority_countÚrouterrrxrxryrhs(
 
 ü
 
z RouterManager._ensure_prioritiesr–)rrpcCs|j|}dd„|Dƒ}|S)z¡Get a list of the current available routers that shares the given priority.
 
        Returns:
            list: A list of the current available routers.
        cSsg|]}| ¡r|‘qSrx)r)Ú.0r rxrxryÚ
<listcomp>’sz8RouterManager._get_available_routers.<locals>.<listcomp>©r)rŠrÚ router_listrxrxryÚ_get_available_routers‹s
z$RouterManager._get_available_routersrcCsF| |¡}|sdSt|ƒdkr&|dSt|ƒd}t d|¡}||S)z{Get a random router from the group with the given priority.
 
        Returns:
            Router: A random router.
        Nrr)r%rÚrandomÚrandint)rŠrr$ÚlastÚindexrxrxryÚ_get_random_connection_params•s
   z+RouterManager._get_random_connection_paramsrãcCs|jS)zŒReturns the next connection parameters.
 
        Returns:
            bool: True if there is more server to failover to else False.
        )rr‰rxrxryÚ can_failover¥szRouterManager.can_failovercCsÎ|jsBd|_|j ¡}|j dd¡|d<|j dd¡|d<t|ƒS|j|j}t|jƒ}d}|rÊ|     |¡}|dk    s||j|kr¤|j|dkrÊt| 
|¡ƒd    krÊd|_qÊ|jd7_|j|kr\|j|j}q\|S)
zvReturns the next connection parameters.
 
        Returns:
            Router: with the connection parameters.
        Frbr·rcé$TNré) rrrÚcopyrrrrrr*r%)rŠZrouter_settingsÚ cur_priorityZrouters_priority_lenÚsearchr rxrxryÚget_next_router­s,
 
 
 ÿþ
zRouterManager.get_next_routerzDict[int, List[Router]]cCs|jS)z™Returns the directory containing all the routers managed.
 
        Returns:
            dict: Dictionary with priorities as connection settings.
        r#r‰rxrxryÚget_routers_directoryÐsz#RouterManager.get_routers_directoryN) rèrérêrër‹rr%r*r+r1r2rxrxrxryr Us
#
#r c@sHeZdZdZdddœdd„Zddœdd    „Zd
dd œd d „Zddœdd„Zdddœdd„Zdjdddddœdd„Z    ddœdd„Z
ddœdd„Z ddœdd„Z ddœd d!„Z d"dd#œd$d%„Zdd&d'dd(œd)d*„Zdd&d'dd(œd+d,„Zed-d.d#œd/d0„ƒZed1d2d#œd3d4„ƒZed5d6d#œd7d8„ƒZed9d2d#œd:d;„ƒZed<d2d#œd=d>„ƒZedkddd?d@dAdBœdCdD„ƒZed"dEdFœdGdH„ƒZedddIdJœdKdL„ƒZedIdMd œdNdO„ƒZed2dd œdPdQ„ƒZed2dRd œdSdT„ƒZdEdœdUdV„Zd?dœdWdX„ZdYddZœd[d\„Zd?dœd]d^„Z d_dœd`da„Z!ddœdbdc„Z"ddœddde„Z#ddœdfdg„Z$ddœdhdi„Z%dS)lròzkConnection to a MySQL Server.
 
    Args:
        settings (dict): Dictionary with connection settings.
    rr|©rrpcCsÐ||_tƒ|_d|_d|_| d¡|_| d¡|_| d¡|_d|_    | dg¡|_
d|kr‚|dr‚|j
  | d¡| dd¡dœ¡t |j
|ƒ|_ | dt¡|_|jd    kr®d|_d    |_g|_d
|_d |_d|_dS) Nr_r`rardrbrc©rbrcrirTF)rrƒÚstreamÚprotocolÚ    keep_openrÚ_userÚ    _passwordZ_schemaÚ_active_resultrrsr Úrouter_managerrìÚ_connect_timeoutÚ _stmt_counterÚ_prepared_stmt_idsÚ_prepared_stmt_supportedÚ_server_disconnectedÚ_server_disconnected_reason)rŠrrxrxryr‹às6   
þÿÿ
zConnection.__init__r„cCs|jdk    r|j ¡d|_dS)zFetch active result.N)r:Ú    fetch_allr‰rxrxryÚfetch_active_results
 
zConnection.fetch_active_resultrK)rýrpcCs
||_dS)aSet active result.
 
        Args:
            `Result`: It can be :class:`mysqlx.Result`,
                      :class:`mysqlx.BufferingResult`,
                      :class:`mysqlx.RowResult`, :class:`mysqlx.SqlResult` or
                      :class:`mysqlx.DocResult`.
        N)r:©rŠrýrxrxryÚset_active_results    zConnection.set_active_resultc
Csžd}|j ¡r&zÞ|j ¡}|j | ¡|j¡t|jƒ}t|jƒ}t    ||ƒ|_
|j
  ¡j }|rndd„|Dƒni}|  |¡d|jkrž|jd}|j
j|d|j dtj¡}|j d¡}    |tjkrÈdn | |||    ¡}
| ¡|j
 |
¡WdSttfk
r"} z| }| ¡W5d} ~ XYqXq|dk    rrt|tjƒrrt|jƒdkr`td    |j›d
ƒ‚td |j›d ƒ‚t|jƒdkrt d |›ƒ‚t ddƒ‚dS)a Attempt to connect to the MySQL server.
 
        Raises:
            :class:`mysqlx.InterfaceError`: If fails to connect to the MySQL
                                            server.
            :class:`mysqlx.TimeoutError`: If connect timeout was exceeded.
        NcSsi|]}t|dƒ ¡|“qS©rÕ)r0Úlower)r!ÚcaprxrxryÚ
<dictcomp>)s z&Connection.connect.<locals>.<dictcomp>Ú
attributes©Zsession_connect_attrsrkrlrz9Connection attempt to the server was aborted. Timeout of z ms was exceededz8All server connection attempts were aborted. Timeout of z) ms was exceeded for each selected serverzCannot connect to host: ú,Unable to connect to any of the target hostsi¡)!r;r+r1r5r”r r<r6r7r8r6Zget_capabilitesZ capabilitiesÚ_set_tls_capabilitiesrÚset_capabilitiesrr%Z    PREFERREDÚDISABLEDÚ_set_compression_capabilitiesÚ _authenticateZset_compressionr¢rœr
r~reÚtimeoutrrr.r)) rŠÚerrorr ÚreaderÚwriterZ    caps_dataÚcapsÚ
conn_attrsrkÚ
algorithmsÚ    algorithmr£rxrxryr”s^     
ÿ
 
  ÿý
 
 
 ÿÿý  ÿ ÿzConnection.connect)rVrpc CsP|j d¡tjkrdS|j ¡r:|j d¡r6t d¡dSd|krR| ¡t    dƒ‚d}t
  ¡dkr¦t ƒ\}}}zd|koˆ|  d    ¡d
d k}Wntk
r¤d}YnXtjd krÄ|sÄ| ¡td ƒ‚|jjdd|j |j dd¡|j dtj¡|j d¡|j d¡|j d¡|j d¡|j d¡¡d|jkrL|jd}|jj|ddS)a©Set the TLS capabilities.
 
        Args:
            caps (dict): Dictionary with the server capabilities.
 
        Raises:
            :class:`mysqlx.OperationalError`: If SSL is not enabled at the
                                             server.
            :class:`mysqlx.RuntimeError`: If support for SSL is not available
                                          in Python.
 
        .. versionadded:: 8.0.21
        rfNz(SSL not required when using Unix socket.ÚtlszSSL not enabled at serverFÚLinuxz Oracle LinuxÚ.rÚ7)r-éé    z<The support for SSL is not available for this Python versionT)rZr]rZr\rYr[r^rJrK)rrr&rOr5rår2ÚwarningÚclose_connectionr+ÚplatformÚsystemrRÚsplitÚ
IndexErrorÚsysÚ version_inforœr6rNrâr¿)rŠrVZis_ol7ÚdistnamerÚrrrWrxrxryrMYsD
 
 
ÿ 
 
 
 
 
ù     
z Connection._set_tls_capabilitiesNrnzOptional[List[str]]ú Optional[str])rVrkrXrpc sŒ| d¡}|dkr6d}|tjkr(t|ƒ‚t |¡dSi}t|tƒr~|dddD]&}dd„|dd    dDƒ||d
<qTn*|jj    j
D]}d d„|jj jDƒ||j <qˆ| d g¡‰d}|r d d„|Dƒ}    ‡fdd„|    Dƒ}
|
ròt  |
d¡}n|tjkrtdƒ‚ndS|dkrFtr,dˆkr,d}ntrBdˆkrBd}nd}|ˆkrvd}|tjkrht|ƒ‚t |¡dS|jjd |id|S)aSet the compression capabilities.
 
        If compression is available, negociates client and server algorithms.
        By trying to find an algorithm from the requested compression
        algorithms list, which is supported by the server.
 
        If no compression algorithms list is provided, the following priority
        is used:
 
        1) zstd_stream
        2) lz4_message
        3) deflate_stream
 
        Args:
            caps (dict): Dictionary with the server capabilities.
            compression (str): The compression connection setting.
            algorithms (list): List of requested compression algorithms.
 
        Returns:
            str: The compression algorithm.
 
        .. versionadded:: 8.0.21
        .. versionchanged:: 8.0.22
        rkNz8Compression requested but the server does not support itÚvalueÚobjÚfldcSs"g|]}|ddd d¡‘qS)ÚscalarÚv_stringrjúutf-8)Údecode©r!rjrxrxryr"¸sÿz<Connection._set_compression_capabilities.<locals>.<listcomp>ÚarrayrwcSsg|]}|jjj d¡‘qS)ro)rmrnrjrprqrxrxryr"¾sÿrYcSsg|]}|tkrt|‘qSrx)r©r!Úitemrxrxryr"Êsþcsg|]}|ˆkr|‘qSrxrxrs©Zserver_algorithmsrxryr"ÏsrzmThe connection compression is set as required, but none of the provided compression algorithms are supported.Z zstd_streamZ lz4_messageZdeflate_streamzFCompression requested but the compression algorithm negotiation failed)rk)rr%r¿r*r2r`r~rrjrkrlrrrwrr)r5r4r6rN) rŠrVrkrXZcompression_datarðZcompression_dictrlrYZclient_algorithmsÚmatchedrxruryrPs\
 
 
 
þþ þ ÿ
 
ÿ 
z(Connection._set_compression_capabilitiesc
CsÊ|j d¡}|rL|tjkr$| ¡qÆ|tjkr8| ¡qÆ|tjkrÆ| ¡nz|j     
¡r`| ¡nfz | ¡Wnt k
r€YnXdSz | ¡Wn2t k
rÄ}zt d|›ƒ|‚W5d}~XYnXdS)z#Authenticate with the MySQL server.rgNzrAuthentication failed using MYSQL41 and SHA256_MEMORY, check username and password or try a secure connection err:) rrr$ZPLAINÚ_authenticate_plainZ SHA256_MEMORYÚ_authenticate_sha256_memoryZMYSQL41Ú_authenticate_mysql41r5rær))rŠrgr£rxrxryrQòs. 
 
 
 
 
 
 
 
  ÿüzConnection._authenticatecCsHt|j|jƒ}|j | ¡¡|j ¡}|j | |¡¡|j     ¡dS)z=Authenticate with the MySQL server using `MySQL41AuthPlugin`.N)
rr8r9r6Úsend_auth_startÚ    auth_nameÚread_auth_continueÚsend_auth_continueÚ    auth_dataÚ read_auth_ok©rŠÚpluginÚ
extra_datarxrxryrys
 
z Connection._authenticate_mysql41cCsF|j ¡stdƒ‚t|j|jƒ}|jj| ¡|     ¡d|j 
¡dS)z;Authenticate with the MySQL server using `PlainAuthPlugin`.z>PLAIN authentication is not allowed via unencrypted connection)r~N) r5rær)rr8r9r6rzr{r~r)rŠrrxrxryrws
ÿzConnection._authenticate_plaincCsHt|j|jƒ}|j | ¡¡|j ¡}|j | |¡¡|j     ¡dS)zBAuthenticate with the MySQL server using `Sha256MemoryAuthPlugin`.N)
rr8r9r6rzr{r|r}r~rr€rxrxryrx#s
 
z&Connection._authenticate_sha256_memoryrL)Ú    statementrpcCs,|jr(|j |j¡|j |j¡d|_dS)zrDeallocates statement.
 
        Args:
            statement (Statement): A `Statement` based type object.
        FN)Úpreparedr6Úsend_prepare_deallocateÚstmt_idr>Úremove)rŠrƒrxrxryÚ_deallocate_statement+sz Connection._deallocate_statementrJzgUnion[FindStatement, DeleteStatement, ModifyStatement, ReadStatement, RemoveStatement, UpdateStatement])Úmsg_typerðrƒrpcCsRz| ¡|j |||¡Wntk
r8d|_YdSX|j |j¡d|_dS)zåPrepares a statement.
 
        Args:
            msg_type (str): Message ID string.
            msg (mysqlx.protobuf.Message): MySQL X Protobuf Message.
            statement (Statement): A `Statement` based type object.
        FNT)    rCr6Zsend_prepare_preparer*r?r>rsr†r„©rŠr‰rðrƒrxrxryÚ_prepare_statement6szConnection._prepare_statementcCs\|js|j |||¡dS|jrr| |¡| |||¡|jsR|j |||¡dS|j |||¡d|_| ¡nÞ|jr|j    s|j |||¡nÀ|j    rÆ|j
sÆ| |¡|j |||¡d|_    | ¡nŠ|j    s|j
s|jsê| |||¡|js|j |||¡dS|j |||¡n8|j    rP|j
rP| |¡|j |||¡d|_    | ¡|  ¡dS)zùExecutes the prepared statement pipeline.
 
        Args:
            msg_type (str): Message ID string.
            msg (mysqlx.protobuf.Message): MySQL X Protobuf Message.
            statement (Statement): A `Statement` based type object.
        NF) r?r6Úsend_msg_without_psZdeallocate_prepare_executerˆr‹Zsend_prepare_executeZreset_exec_counterr„ÚchangedZrepeatedZincrement_exec_counterrŠrxrxryÚ_execute_prepared_pipelineSs@
 
 
 
 
z%Connection._execute_prepared_pipelinerFr=cCsT|j}|jdkrtdƒ‚t|tƒs*tdƒ‚|j d|¡\}}|j |||¡t|ƒS)zóExecute a SQL statement.
 
        Args:
            sql (str): The SQL statement.
 
        Raises:
            :class:`mysqlx.ProgrammingError`: If the SQL statement is not a
                                              valid string.
        Nr™z'The SQL statement is not a valid stringÚsql)    rr6r+r~rnr-Úbuild_execute_statementrŒr=)rŠrƒrr‰rðrxrxryÚsend_sql‘s 
 
zConnection.send_sqlz$Union[AddStatement, InsertStatement]r;cCsN|jdkrtdƒ‚|j |¡\}}|j ||¡d}t|tƒrD|j}t||ƒS)a Send an insert statement.
 
        Args:
            statement (`Statement`): It can be :class:`mysqlx.InsertStatement`
                                     or :class:`mysqlx.AddStatement`.
 
        Returns:
            :class:`mysqlx.Result`: A result object.
        Nr™)r6r+Z build_insertÚsend_msgr~r>Úidsr;)rŠrƒr‰rðr“rxrxryÚ send_insert¥s
 
zConnection.send_insertz%Union[FindStatement, SelectStatement]zUnion[DocResult, RowResult]cCs6|j |¡\}}| |||¡| ¡r.t|ƒSt|ƒS)aDSend an find statement.
 
        Args:
            statement (`Statement`): It can be :class:`mysqlx.SelectStatement`
                                     or :class:`mysqlx.FindStatement`.
 
        Returns:
            `Result`: It can be class:`mysqlx.DocResult` or
                      :class:`mysqlx.RowResult`.
        )r6Z
build_findrŽZ is_doc_basedr:r<©rŠrƒr‰rðrxrxryÚ    send_find¹szConnection.send_findz'Union[DeleteStatement, RemoveStatement]cCs&|j |¡\}}| |||¡t|ƒS)aSend an delete statement.
 
        Args:
            statement (`Statement`): It can be :class:`mysqlx.RemoveStatement`
                                     or :class:`mysqlx.DeleteStatement`.
 
        Returns:
            :class:`mysqlx.Result`: The result object.
        )r6Ú build_deleterŽr;r•rxrxryÚ send_deleteËs zConnection.send_deletez'Union[ModifyStatement, UpdateStatement]cCs&|j |¡\}}| |||¡t|ƒS)aSend an delete statement.
 
        Args:
            statement (`Statement`): It can be :class:`mysqlx.ModifyStatement`
                                     or :class:`mysqlx.UpdateStatement`.
 
        Returns:
            :class:`mysqlx.Result`: The result object.
        )r6Z build_updaterŽr;r•rxrxryÚ send_updateÚs zConnection.send_updaterãúOptional[Dict[str, Any]]zOptional[Result])Ú    namespaceÚcmdÚ raise_on_failÚfieldsrpcCsLz,|j |||¡\}}|j ||¡t|ƒWStk
rF|rB‚YnXdS)a‹Execute a non query command.
 
        Args:
            namespace (str): The namespace.
            cmd (str): The command.
            raise_on_fail (bool): `True` to raise on fail.
            fields (Optional[dict]): The message fields.
 
        Raises:
            :class:`mysqlx.OperationalError`: On errors.
 
        Returns:
            :class:`mysqlx.Result`: The result object.
        N)r6rr’r;r+)rŠr›rœrržr‰rðrxrxryÚexecute_nonqueryésÿ
zConnection.execute_nonqueryr–©rrpcCsN|j d|¡\}}|j ||¡t|ƒ}| ¡|jdkrBtdƒ‚|ddS)zèExecute a SQL scalar.
 
        Args:
            sql (str): The SQL statement.
 
        Raises:
            :class:`mysqlx.InterfaceError`: If no data found.
 
        Returns:
            :class:`mysqlx.Result`: The result.
        rrz No data found)r6rr’r<rBr˜r))rŠrr‰rðrýrxrxryÚexecute_sql_scalar
s 
zConnection.execute_sql_scalarr<)rœržrpcCs*|j d||¡\}}|j ||¡t|ƒS)zÎReturns the row result.
 
        Args:
            cmd (str): The command.
            fields (dict): The message fields.
 
        Returns:
            :class:`mysqlx.RowResult`: The result object.
        Úmysqlx)r6rr’r<)rŠrœržr‰rðrxrxryÚget_row_results zConnection.get_row_resultzOptional[MessageType]cCs |j |¡S)zdRead row.
 
        Args:
            result (:class:`mysqlx.RowResult`): The result object.
        )r6Úread_rowrDrxrxryr¤.szConnection.read_rowcCs|j |¡dS)zeClose result.
 
        Args:
            result (:class:`mysqlx.Result`): The result object.
        N)r6Ú close_resultrDrxrxryr¥7szConnection.close_resultzList[ColumnType]cCs |j |¡S)zlGet column metadata.
 
        Args:
            result (:class:`mysqlx.Result`): The result object.
        )r6rñrDrxrxryrñ@szConnection.get_column_metadatacCs|jd7_|jS)z|Returns the next statement ID.
 
        Returns:
            int: A statement ID.
 
        .. versionadded:: 8.0.16
        r)r=r‰rxrxryÚget_next_statement_idIsz Connection.get_next_statement_idcCs
|j ¡S)zgCheck if connection is open.
 
        Returns:
            bool: `True` if connection is open.
        )r5rçr‰rxrxryrçTszConnection.is_openzUnion[str, Tuple[str, int]])rÿrpcCsd|_||_dS)z†Set the disconnection message from the server.
 
        Args:
            reason (str): disconnection reason from the server.
        TN)r@rA)rŠrÿrxrxryr÷\sz"Connection.set_server_disconnectedcCs|jS)zÅVerify if the session has been disconnect from the server.
 
        Returns:
            bool: `True` if the connection has been closed from the server
                  otherwise `False`.
        )r@r‰rxrxryrôesz!Connection.is_server_disconnectedz%Optional[Union[str, Tuple[str, int]]]cCs|jS)z†Get the disconnection message sent by the server.
 
        Returns:
            string: disconnection reason from the server.
        )rAr‰rxrxryrõnsz"Connection.get_disconnected_reasoncCs| ¡s dS|j ¡dS)zDisconnect from server.N)rçr5r¦r‰rxrxryrüvszConnection.disconnectc
Csœ| ¡s dSz~zD| ¡|jr<|jD]}|j |¡q$d|_|j     ¡|j 
¡Wn4t t t fk
r†}zt d|¡W5d}~XYnXW5|j ¡XdS)z*Close a sucessfully authenticated session.NrzGWarning: An error occurred while attempting to close the connection: %s)rçr5r¦rCr?r>r6r…r=Z
send_closeÚread_okr)r+r¢r2r`)rŠr†r£rxrxryÚ close_session|s 
 
ýzConnection.close_sessionc
Csl| ¡s dS|jdk    r |j ¡z|j |j¡|_Wn2ttfk
rf}zt     d|¡W5d}~XYnXdS)z*Reset a sucessfully authenticated session.NzDWarning: An error occurred while attempting to reset the session: %s)
rçr:rBr6Z
send_resetr7r)r+r2r`)rŠr£rxrxryÚ reset_session—s
 
ýzConnection.reset_sessioncCsB| ¡s dS|jdk    r |j ¡|j ¡|j ¡|j ¡dS)z€Announce to the server that the client wants to close the
        connection. Discards any session state of the server.
        N)rçr:rBr6Zsend_connection_closer§r5r¦r‰rxrxryra¦s
 
 
 
zConnection.close_connection)N)N)&rèrérêrër‹rCrEr”rMrPrQryrwrxrˆr‹rŽrr‘r”r–r˜r™rŸr¡r£r¤r¥rñr¦rçr÷rôrõrür¨r©rarxrxrxryròÙs^" F:üc
 >û          ròcsteZdZdZdddœ‡fdd„ Zddœ‡fdd    „ Zddœd
d „Zddœd d „Zddœdd„Zdddœdd„Z    ‡Z
S)róaClass to hold :class:`Connection` instances in a pool.
 
    PooledConnection is used by :class:`ConnectionPool` to facilitate the
    connection to return to the pool once is not required, more specifically
    once the close_session() method is invoked. It works like a normal
    Connection except for methods like close() and sql().
 
    The close_session() method will add the connection back to the pool rather
    than disconnecting from the MySQL server.
 
    The sql() method is used to execute sql statements.
 
    Args:
        pool (ConnectionPool): The pool where this connection must return.
 
    .. versionadded:: 8.0.13
    ÚConnectionPoolr|)rørpcsBt|tƒstdƒ‚tƒ |j¡||_|jd|_|jd|_dS)Nz&pool should be a ConnectionPool objectrbrc)    r~rªr•rr‹Ú
cnx_configrørbrc)rŠrørrxryr‹Æs 
 zPooledConnection.__init__r„cstƒ ¡dS)zGCloses the connection.
 
        This method closes the socket.
        N)rr¨r‰rrxryraÎsz!PooledConnection.close_connectioncCs|j |¡dS)a“Do not close, but add connection back to pool.
 
        The close_session() method does not close the connection with the
        MySQL server. The connection is added back to the pool so it
        can be reused.
 
        When the pool is configured to reset the session, the session
        state will be cleared by re-authenticating the user once the connection
        is get from the pool.
        N)røÚadd_connectionr‰rxrxryr¨Õs zPooledConnection.close_sessioncCs |jdk    r|j ¡| ¡dS)zReconnect this connection.N)r:rBrQr‰rxrxryÚ    reconnectâs
 
zPooledConnection.reconnectcCs | ¡dS)zQReset the connection.
 
        Resets the connection by re-authenticate.
        N)r­r‰rxrxryÚresetèszPooledConnection.resetrnrFr cCs
t||ƒS©aCreates a :class:`mysqlx.SqlStatement` object to allow running the
        SQL statement on the target MySQL Server.
 
        Args:
            sql (string): The SQL statement to be executed.
 
        Returns:
            mysqlx.SqlStatement: SqlStatement object.
        )rF©rŠrrxrxryrïs
zPooledConnection.sql) rèrérêrër‹rar¨r­r®rr rxrxrryró³s róc@sîeZdZdZddddœdd„Zdddœd    d
„Zed d œd d„ƒZd.dddœdd„Zdd œdd„Z    d/dddœdd„Z
dddœdd„Z dddœdd„Z dd œdd„Z d d œd!d"„Zd0d dd$œd%d&„Zdd œd'd(„Zd)d œd*d+„Zdd œd,d-„ZdS)1rªaµThis class represents a pool of connections.
 
    Initializes the Pool with the given name and settings.
 
    Args:
        name (str): The name of the pool, used to track a single pool per
                    combination of host and user.
        **kwargs:
            max_size (int): The maximun number of connections to hold in
                            the pool.
            reset_session (bool): If the connection should be reseted when
                                  is taken from the pool.
            max_idle_time (int): The maximum number of milliseconds to allow
                                 a connection to be idle in the queue before
                                 being closed. Zero value means infinite.
            queue_timeout (int): The maximum number of milliseconds a
                                 request will wait for a connection to
                                 become available. A zero value means
                                 infinite.
            priority (int): The router priority, to choose this pool over
                            other with lower priority.
 
    Raises:
        :class:`mysqlx.PoolError` on errors.
 
    .. versionadded:: 8.0.13
    rnr
r|)rÕrorpcKs¦| |¡d|_g|_d|_d|_t ¡|_| dd¡|_    t
j   ||j    ¡| dd¡|_ | dd¡|_||_| dd¡|_| dd¡|_||_|d    |_|d
|_dS) NrTÚmax_sizeér©Ú max_idle_timeÚ queue_timeoutrrbrc)Ú_set_pool_nameZ_open_sessionsÚ_connections_opennedÚ
_availableÚ_timeoutrÚnowÚ_timeout_stamprÚ pool_max_sizeÚqueueÚQueuer‹r©r³rr´rr«rbrc)rŠrÕrorxrxryr‹s 
 
 
zConnectionPool.__init__)Ú    pool_namerpcCs@t |¡rtd|›dƒ‚t|ƒtkr6td|›dƒ‚||_dS)aƒSet the name of the pool.
 
        This method checks the validity and sets the name of the pool.
 
        Args:
            pool_name (str): The pool name.
 
        Raises:
            AttributeError: If the pool_name contains illegal characters
                            ([^a-zA-Z0-9._\-*$#]) or is longer than
                            connection._CNX_POOL_MAX_NAME_SIZE.
        z Pool name 'z' contains illegal charactersz ' is too longN)Ú_CNX_POOL_NAME_REGEXr0r•rÚ_CNX_POOL_MAX_NAME_SIZErÕ)rŠr¾rxrxryrµ,s
 
 zConnectionPool._set_pool_namer–r„cCs
t|jƒS)zDReturns the number of open connections that can return to this pool.)rr¶r‰rxrxryÚopen_connections?szConnectionPool.open_connectionsNzOptional[PooledConnection]©ÚcnxrpcCs|j |¡dS)zwRemoves a connection from this pool.
 
        Args:
            cnx (PooledConnection): The connection object.
        N)r¶r‡©rŠrÃrxrxryÚremove_connectionDsz ConnectionPool.remove_connectionc
Csx| ¡dkrtz|jd|jd}Wntjk
r6YqXz,z | ¡Wnttt    fk
r`YnXW5| |¡XqdS)z*Removes all the connections from the pool.rT©ÚblockrRN)
Úqsizerr´r¼ÚEmptyrÅrarœr¢r)rÄrxrxryrùLs  
z!ConnectionPool.remove_connectionscCsÆ|jstdƒ‚| ¡rtdƒ‚|sŽt|ƒ}| t¡ ¡ ¡dd}tdd„|     d¡d     d¡Dƒƒdkr€| d    |j
›¡ ¡|j   |¡n*t |tƒs td
ƒ‚| ¡r¸| ¡| ¡| |¡d S) a=Adds a connection to this pool.
 
        This method instantiates a Connection using the configuration passed
        when initializing the ConnectionPool instance or using the set_config()
        method.
        If cnx is a Connection instance, it will be added to the queue.
 
        Args:
            cnx (PooledConnection): The connection object.
 
        Raises:
            PoolError: If no configuration is set, if no more connection can
                       be added (maximum reached) or if the connection can not
                       be instantiated.
        z&Connection configuration not availableú'Failed adding connection; queue is fullrcss|]}t|ƒVqdSr§©r–©r!ÚnrxrxryÚ    <genexpr>usz0ConnectionPool.add_connection.<locals>.<genexpr>ú-r\©éré
úset mysqlx_wait_timeout = z1Connection instance not subclass of PooledSessionN)r«r,ÚfullrórÚ_SELECT_VERSION_QUERYÚexecuterBÚtuplerdr³r¶rsr~rôrùr¦Úqueue_connection)rŠrÃÚverrxrxryr¬[s &
zConnectionPool.add_connectionróc
Csft|tƒstdƒ‚|jr | ¡z|j|ddWn.tjk
r`}ztdƒ|‚W5d}~XYnXdS)aGPut connection back in the queue:
 
        This method is putting a connection back in the queue.
        It will not acquire a lock as the methods using _queue_connection() will
        have it set.
 
        Args:
            PooledConnection: The connection object.
 
        Raises:
            PoolError: On errors.
        z2Connection instance not subclass of PooledSession.F)rÇrÊN)r~rór,r©Úputr¼ÚFull)rŠrÃr£rxrxryrØ…s
zConnectionPool.queue_connection)Ú
connectionrpcCs|j |¡dS)zETracks connection in order of close it when client.close() is invoke.N)r¶rs)rŠrÜrxrxryÚtrack_connectionszConnectionPool.track_connectioncCs|jSr§rFr‰rxrxryÚ__str__¡szConnectionPool.__str__rãcCs|jS)z¸Returns if this pool is available for pool connections from it.
 
        Returns:
            bool: True if this pool is available else False.
        .. versionadded:: 8.0.20
        )r·r‰rxrxryr¤szConnectionPool.availableéÿÿÿÿ)Útime_outrpcCs.|jr*t d||¡d|_t ¡|_||_dS)zhSets this pool unavailable for a period of time (in seconds).
 
        .. versionadded:: 8.0.20
        z4ConnectionPool.set_unavailable pool: %s time_out: %sFN)r·r2r`rr¹rºr¸)rŠràrxrxryr
­sý
zConnectionPool.set_unavailablecCsd|_t ¡|_dS)zaSets this pool available for pool connections from it.
 
        .. versionadded:: 8.0.20
        TN)r·rr¹rºr‰rxrxryÚ set_available¼szConnectionPool.set_availablezTuple[int, datetime]cCs |j|jfS)zÎReturns the penalized time (timeout) and the time at the penalty.
 
        Returns:
            tuple: penalty seconds (int), timestamp at penalty (datetime object)
        .. versionadded:: 8.0.20
        )r¸rºr‰rxrxryÚget_timeout_stampÄsz ConnectionPool.get_timeout_stampcCs|jD] }| ¡qdS)zEmpty this ConnectionPool.N)r¶rarÄrxrxryr¦Ís
zConnectionPool.close)N)N)rß)rèrérêrër‹rµÚpropertyrÁrÅrùr¬rØrÝrÞrr
rárâr¦rxrxrxryrªüs *        rªc@seZdZUdZdZded<iZded<ddœdd„Zd    d    d
d œd d „Zdddœdd„Z    e
dddœdd„ƒZ dddœdd„Z e
dddœdd„ƒZ e
dddddœd d!„ƒZdddd"œd#d$„Ze
d5dd%dd"œd&d'„ƒZd6dd(dd)œd*d+„Zdd,dœd-d.„Zdddœd/d0„Ze
dd1dd2œd3d4„ƒZdS)7rúz–Manages a pool of connections for a host or hosts in routers.
 
    This class handles all the pools of Connections.
 
    .. versionadded:: 8.0.13
    NÚ_PoolsManager__instancerÚ_PoolsManager__poolsr„cCs"tjdkrt |¡t_it_tjSr§)rúräÚobjectÚ__new__rå)ÚclsrxrxryrçÞs
 zPoolsManager.__new__rnrã)rqr¾rpcCs,|j |g¡}|D]}|j|krdSqdS)zþVerifies if a pool exists with the given name.
 
        Args:
            client_id (str): The client id.
            pool_name (str): The name of the pool.
 
        Returns:
            bool: Returns `True` if the pool exists otherwise `False`.
        TF)rårrÕ)rŠrqr¾ÚpoolsrørxrxryÚ _pool_existsäs
 
 
zPoolsManager._pool_existsr r3cCs^g}g}| |¡}|D]\}}| |¡q|j | dd¡g¡D]}|j|kr@| |¡q@|S)záRetrieves a list of pools that shares the given settings.
 
        Args:
            settings (dict): the configuration of the pool.
 
        Returns:
            list: A list of pools that shares the given settings.
        rqúNo id)Ú_get_connections_settingsrsrårrÕ)rŠrZavailable_poolsZ
pool_namesÚconnections_settingsÚ router_namerrrørxrxryÚ
_get_poolsôs    
 
 zPoolsManager._get_poolsz List[Tuple[str, Dict[str, Any]]]cCsÄ| ¡}| dg¡}g}d|kr*| d¡d|krVd|krV| dd|d|ddœ¡|jdd„d    |D]T}| ¡}|d|d<|d|d<|d
|d
<| d d¡|d <| tf|Ž|f¡qj|S) aHGenerates a list of separated connection settings for each host.
 
        Gets a list of connection settings for each host or router found in the
        given settings.
 
        Args:
            settings (dict): The configuration for the connections.
 
        Returns:
            list: A list of connections settings
        rdrbrcrr)rÚweightrbrccSs|d| dd¡ fS)Nrrðr)rrrxrxryr)ršz8PoolsManager._get_connections_settings.<locals>.<lambda>)rwrrð)r.rÚpoprsrÂrz)rZ pool_settingsrdrír Zconnection_settingsrxrxryrì s4 
üÿ       þÿz&PoolsManager._get_connections_settingsr|)Ú cnx_settingsrpcCs~| |¡}| dd¡|jkr.g|j| dd¡<|D]F\}}| | dd¡|¡rPq2|j | dd¡g¡}| t|f|Ž¡q2dS)a#Creates a `ConnectionPool` instance to hold the connections.
 
        Creates a `ConnectionPool` instance to hold the connections only if
        no other pool exists with the same configuration.
 
        Args:
            cnx_settings (dict): The configuration for the connections.
        rqrëN)rìrrårêrsrª)rŠròrírîrrørxrxryÚ create_pool8s    
 zPoolsManager.create_poolzList[ConnectionPool]rª)Ú    pool_listrpcCs<|sdSt|ƒdkr|dSt|ƒd}t d|¡}||S)zGet a random router from the group with the given priority.
 
        Returns:
            Router: a random router.
 
        .. versionadded:: 8.0.20
        Nrr)rr&r')rôr(r)rxrxryÚ_get_random_poolNs       zPoolsManager._get_random_poolr–)rér)r/rpcCsZg}d}|t|ƒkrV||j}||krB|| ¡rB| ||¡n
||krLqV|d7}q|S)Nr)rrrrs)rér)r/ZsublistZ next_priorityrxrxryÚ _get_sublist`s 
 
zPoolsManager._get_sublist)rér/rpcCsbd}|D]"}| ¡r"||jkr"q,|d7}qg}|sX|t|ƒkrX| |||¡}|d7}q0| |¡S)Nrr)rrrrörõ)rŠrér/r)røZsubpoolrxrxryÚ_get_next_poolos
 
zPoolsManager._get_next_poolú Optional[int]cCs@|dkr|r|djS|D]}| ¡r|j}|Sq|djS)Nr)rr)rér/Zt_poolrxrxryÚ_get_next_priority}s 
 
zPoolsManager._get_next_priorityzOptional[bool])rÚreviverpcCsT| |¡}|D]@}| ¡rq| ¡\}}|r0|}t ¡|t|dkr| ¡qdS)N)Úseconds)rïrrârr¹rrá)rŠrrúrérørRZ timeout_stamprxrxryÚ_check_unavailable_poolsŠs
 z%PoolsManager._check_unavailable_poolsróc
s
dddœ‡fdd„ }| |¡}| dd¡}g}| |¡| ||¡}|dkrTtdƒ‚||d<| ||¡‰t ¡}ˆdk    rþz¬ˆ ¡d    krˆ|îzˆjd
ˆj    d }Wn t
j k
rÈtd ƒd‚YnXz,|  ¡r܈  ¡|jsê| ¡||ƒWnvtttfk
rlz.z | ¡Wntttfk
r8YnXW5ˆ |¡Xˆ ¡d    krÆzˆjd
ˆj    d }Wnt
j k
r„Yn>Xz.z | ¡Wntttfk
r°YnXW5ˆ |¡XqJzHz&tˆƒ}ˆ |¡| ¡||ƒWntttfk
r
YnXW5ˆ ¡d    krfz&ˆjd
ˆj    d }| ¡ˆ |¡Wntttfk
r`YnXqXYnX|W5QR£WSQRXnžˆjˆjkr¾tˆƒ}ˆ |¡| ¡||ƒ|WS|^z4ˆjd
ˆj    d }| ¡||ƒ|WW5QR£WSt
j k
rtd ƒd‚YnXW5QRXWqptttfk
rú}z¬| dˆ›d|›¡t|tƒrpˆ d¡n | ˆ|¡| |¡| ||¡‰ˆdkrâ| ||¡}||d<| ||¡‰ˆdkrâd |¡}    td|    ›dƒ|‚WY¢qpW5d}~XYqpXqptdƒ‚dS)ažGet a connection from the pool.
 
        This method returns an `PooledConnection` instance which has a reference
        to the pool that created it, and can be used as a normal Connection.
 
        When the MySQL connection is not connected, a reconnect is attempted.
 
        Raises:
            :class:`PoolError`: On errors.
 
        Returns:
            PooledConnection: A pooled connection object.
        rór|rÂcsZ| t¡ ¡ ¡dd}tdd„| d¡d d¡DƒƒdkrV| dˆj›¡ ¡dS)Nrcss|]}t|ƒVqdSr§rËrÌrxrxryrΩszOPoolsManager.get_connection.<locals>.set_mysqlx_wait_timeout.<locals>.<genexpr>rÏr\rÐrÓ)rrÕrÖrBr×rdr³)rÃrÙ©rørxryÚset_mysqlx_wait_timeout¦s&z<PoolsManager.get_connection.<locals>.set_mysqlx_wait_timeoutr/NzBUnable to connect to any of the target hosts. No pool is availablerTrÆz)Failed getting connection; pool exhaustedzpool max size has been reachedzpool: z error: r-z
  z2Unable to connect to any of the target hosts: [
  z
]rL) rïrrürùr,r÷Ú    threadingÚRLockrÈr´r¼rÉrôrùr7r®rœr¢r)rÅrarórÝr”rÁr»r.rsr~r
rûru)
rŠrrþrér/Z
error_listÚlockrÃr£rðrxrýryÚget_connection—sÌ
 
 
 ÿ 
ÿþ 
 ÿ
 
 
 
þ
 
 
 
 
 
ÿýzPoolsManager.get_connectioncCsX| |¡}|D]@}| ¡| dd¡dk    r|j | d¡¡}||kr| |¡qt|ƒS)zjCloses the connections in the pools
 
        Returns:
            int: The number of closed pools
        rqN)rïr¦rrår‡r)rŠròrérøZ client_poolsrxrxryÚ
close_pool+s
 zPoolsManager.close_poolz#Union[InterfaceError, TimeoutError])rør£rpc    Csvd}z|j}t|}Wnttfk
r.YnX|sX|j}t ¡D]\}}||krB|}qB|rh| |¡n
| d¡dS)a\Sets a pool as unavailable.
 
        The time a pool is set unavailable depends on the given error message
        or the error number.
 
        Args:
            pool (ConnectionPool): The pool to set unavailable.
            err (Exception): The raised exception raised by a connection belonging
                             to the pool.
        Ni †)Úerrnor€r•rtrðÚ_TIMEOUT_PENALTIESÚitemsr
)rør£ZpenaltyZerr_noÚerr_msgrwrjrxrxryrû;s  z!PoolsManager.set_pool_unavailable)N)N)rèrérêrëräÚ__annotations__rårçrêrïÚ staticmethodrìrórõrör÷rùrürrrûrxrxrxryrúÓs0
  ,ÿ ÿ rúc@sheZdZdZdddœdd„Zddœdd    „Zd
d d dd œdd„Zddœdd„Zeddœdd„ƒZ    e    j
dddœdd„ƒZ    ddœdd„Z dddœdd„Z ddœdd „Z d!dœd"d#„Zdd$d%œd&d'„Zd(dœd)d*„Zddd%œd+d,„Zdd$d%œd-d.„Zddœd/d0„Zddœd1d2„Zddœd3d4„ZdAd6dd%œd7d8„Zddd%œd9d:„Zddd%œd;d<„Zddœd=d>„Zddœd?d@„Zd5S)BÚSessiona*Enables interaction with a X Protocol enabled MySQL Product.
 
    The functionality includes:
 
    - Accessing available schemas.
    - Schema management operations.
    - Retrieval of connection information.
 
    Args:
        settings (dict): Connection data used to connect to the database.
    rr|r3c
CsÐ| dtj¡|_||_| d¡rÈ| d¡rÈts6tdƒ‚ztj |dd¡}Wn<tj    j
k
rˆ}ztd|d›dƒ|‚W5d}~XYnXg|jd<|D].}|jd  |j j d    d
|j|j|jd œ¡q˜d |jksà|jd d k    ròi|jd<| ¡d|kr6|dr6tƒ |¡tƒ |¡|_|jdkrLtdƒ‚nt|jƒ|_|j ¡|j d¡}|rÌz| dt|ƒ›¡ ¡WnPtk
rÊ}z0|jdkr |jn
d|›d}t||jƒ|‚W5d}~XYnXdS)NrhrbrmztMySQL host configuration requested DNS SRV. This requires the Python dnspython module. Please refer to documentationZSRVz Unable to locate any hosts for 'ú'rdT)Zomit_final_dot)rbrcrrðrjFrJÚpoolingz+Connection could not be retrieved from poolrazUSE iúDefault schema 'ú' does not exists)rr3Úuse_purerÚHAVE_DNSPYTHONr)ÚdnsÚresolverÚqueryÚ    exceptionZ DNSExceptionrsÚtargetZto_textrcrrðÚ_init_attributesrúrórÚ _connectionr,ròr”rrHrÖr+rrð)rŠrZ srv_recordsr£ZsrvraÚerrmsgrxrxryr‹hs^ÿÿþ
 
 üÿ
ÿ þ
 
 
 ÿ
 
ýzSession.__init__r„cCs|Sr§rxr‰rxrxryÚ    __enter__£szSession.__enter__úType[BaseException]Ú BaseExceptionr©Úexc_typeÚ    exc_valueÚ    tracebackrpcCs | ¡dSr§r¨©rŠrrrrxrxryÚ__exit__¦szSession.__exit__c CsÎtjdkrRdt ¡dkr d}ndt ¡dkr6d}nt ¡}dt ¡d›}n<t ¡}t ¡d    krzd
t ¡d›}nd  t    ƒdd …¡}t
  d ¡}|ddkrªd}nd}t t  ¡ƒ||t ¡dd dd„tdd…Dƒ¡|dœ}|jd |¡d|jkrÊ|jdD]¼}|jd|}t|t ƒs:td|›dƒ‚t|ƒdkrXtd|›dƒ‚| d¡rrtd|›ƒ‚t|t ƒs”td|›d|›d ƒ‚t|ƒd!kr¸td|›d"|›d#ƒ‚||jd|<q d$S)%z5Setup default and user defined connection-attributes.r¶Ú64rÚx86_64Ú32Úi386zWindows-rÚDarwinzmacOS-rÏr-ú ZGPLv2zGPL-2.0Z
Commercialzmysql-connector-pythonr\cSsg|] }t|ƒ‘qSrx)rn)r!rrxrxryr"Ñsz,Session._init_attributes.<locals>.<listcomp>é)Z_pidÚ    _platformÚ_osZ _source_hostZ _client_nameZ_client_versionZ_client_licenserJrjúAttribute name 'ú' must be a string typeé ú"' exceeds 32 characters limit sizerrzHKey names in 'session-connect-attributes' cannot start with '_', found: z    ' value 'z'  must be a string typeéú
' value: 'ú$' exceeds 1024 characters limit sizeN)rÔrÕrbÚ architectureÚ    win32_verÚmachinercÚmac_verrurRrSrdrnÚgetpidreÚ gethostnamerTrrr~r)rÚ
startswith)rŠZ platform_archZos_verZlicense_chunksZclient_licenseZdefault_attributesÚ    attr_nameÚ
attr_valuerxrxryr®s`
 
 
ò  
ÿ
ÿ ÿ ÿÿzSession._init_attributesrãcCstjS)z8bool: `True` to use pure Python Protobuf implementation.)r3rr‰rxrxryrûszSession.use_pure)rjrpcCs t|tƒstdƒ‚t |¡dS)Nz)'use_pure' option should be True or False)r~rãr-r3Z set_use_pure)rŠrjrxrxryr    s
cCs |jj ¡S)zzReturns `True` if the session is open.
 
        Returns:
            bool: Returns `True` if the session is open.
        )rr5rçr‰rxrxryrç    szSession.is_openrnrFr cCs t|j|ƒSr¯)rFrr°rxrxryr    s
z Session.sqlròcCs|jS)z~Returns the underlying connection.
 
        Returns:
            mysqlx.connection.Connection: The connection object.
        )rr‰rxrxryr    szSession.get_connectionrªcCs | d¡ ¡}dd„| ¡DƒS)z°Returns the list of schemas in the current session.
 
        Returns:
            `list`: The list of schemas in the current session.
 
        .. versionadded:: 8.0.12
        zSHOW DATABASEScSsg|] }|d‘qS)rrx)r!Úrowrxrxryr"+    sz'Session.get_schemas.<locals>.<listcomp>)rrÖrBrDrxrxryÚ get_schemas"    szSession.get_schemasr()rÕrpcCs
t||ƒS)zöRetrieves a Schema object from the current session by it's name.
 
        Args:
            name (string): The name of the Schema object to be retrieved.
 
        Returns:
            mysqlx.Schema: The Schema object with the given name.
        r'©rŠrÕrxrxryÚ
get_schema-    s    zSession.get_schemazOptional[Schema]cCsz|jj d¡}|rv| t t|ƒ¡¡ ¡ ¡}z |dd|krLt    ||ƒWSWn&t
k
rtt d|›dƒd‚YnXdS)aRetrieves a Schema object from the current session by the schema
        name configured in the connection settings.
 
        Returns:
            mysqlx.Schema: The Schema object with the given name at connect
                           time.
            None: In case the default schema was not provided with the
                  initialization data.
 
        Raises:
            :class:`mysqlx.ProgrammingError`: If the provided default schema
                                              does not exists.
        rarr rN) rrrrÚ_SELECT_SCHEMA_NAME_QUERYÚformatr/rÖrBr(rer-)rŠraÚresrxrxryÚget_default_schema8    sÿ
ÿþzSession.get_default_schemacCs|j dt t|ƒ¡d¡dS)z‹Drops the schema with the specified name.
 
        Args:
            name (string): The name of the Schema object to be retrieved.
        rTN)rrŸÚ_DROP_DATABASE_QUERYr@rHr=rxrxryÚ drop_schemaV    s
 ÿzSession.drop_schemacCs$|j dt t|ƒ¡d¡t||ƒS)z¬Creates a schema on the database and returns the corresponding
        object.
 
        Args:
            name (string): A string value indicating the schema name.
        rT)rrŸÚ_CREATE_DATABASE_QUERYr@rHr(r=rxrxryÚ create_schema`    s  ÿzSession.create_schemacCs|j ddd¡dS)z+Starts a transaction context on the server.rzSTART TRANSACTIONTN©rrŸr‰rxrxryÚstart_transactionl    szSession.start_transactioncCs|j ddd¡dS)zXCommits all the operations executed after a call to
        startTransaction().
        rZCOMMITTNrGr‰rxrxryÚcommitp    szSession.commitcCs|j ddd¡dS)zYDiscards all the operations executed after a call to
        startTransaction().
        rZROLLBACKTNrGr‰rxrxryÚrollbackv    szSession.rollbackNricCsT|dkrt ¡›}n"t|tƒr.t| ¡ƒdkr6tdƒ‚|j ddt    |ƒ›d¡|S)aCreates a transaction savepoint.
 
        If a name is not provided, one will be generated using the uuid.uuid1()
        function.
 
        Args:
            name (Optional[string]): The savepoint name.
 
        Returns:
            string: The savepoint name.
        NrúInvalid SAVEPOINT namerz
SAVEPOINT T)
ÚuuidÚuuid1r~rnrÚstripr-rrŸrHr=rxrxryÚ set_savepoint|    s   ÿzSession.set_savepointcCs@t|tƒrt| ¡ƒdkr"tdƒ‚|j ddt|ƒ›d¡dS)zRollback to a transaction savepoint with the given name.
 
        Args:
            name (string): The savepoint name.
        rrKrzROLLBACK TO SAVEPOINT TN©r~rnrrNr-rrŸrHr=rxrxryÚ rollback_to‘    s ýzSession.rollback_tocCs@t|tƒrt| ¡ƒdkr"tdƒ‚|j ddt|ƒ›d¡dS)z{Release a transaction savepoint with the given name.
 
        Args:
            name (string): The savepoint name.
        rrKrzRELEASE SAVEPOINT TNrPr=rxrxryÚrelease_savepointŸ    s ýzSession.release_savepointcCs|j ¡t|jƒ|_dS)zCloses the session.N)rr¨ròrr‰rxrxryr¦­    s
z Session.closecCs|j ¡dS)z8Closes all underliying connections as pooled connectionsN)rrar‰rxrxryÚclose_connections³    szSession.close_connections)N)rèrérêrër‹rr!rrãrÚsetterrçrrr<r>rBrDrFrHrIrJrOrQrRr¦rSrxrxrxryr
[s2 ;M   
 r
c@s¢eZdZdZd%ddddœdd„Zdd    œd
d „Zd d dddœdd„Zdddœdd„Zdddœdd„Zdddœdd„Z    dddœdd„Z
d d    œd!d"„Z dd    œd#d$„Z dS)&ÚClienta(Class defining a client, it stores a connection configuration.
 
    Args:
        connection_dict (dict): The connection information to connect to a
                                MySQL server.
        options_dict (dict): The options to configure this client.
 
    .. versionadded:: 8.0.13
    Nrršr|)Úconnection_dictÚ options_dictrpcCs’||_|dkri}g|_t ¡|_| | dd¡¡| | dd¡¡| | dd¡¡|     | dd¡¡|j
|jd<|j |jd<|j|jd    <dS)
Nr±r²r³rr´ÚenabledTr rq) rÚsessionsrLÚuuid4rqÚ_set_pool_sizerÚ_set_max_idle_timeÚ_set_queue_timeoutÚ_set_pool_enabledÚpooling_enabledr±)rŠrVrWrxrxryr‹Ã    s
  zClient.__init__r„cCs|Sr§rxr‰rxrxryrØ    szClient.__enter__rrrrcCs | ¡dSr§r¨r rxrxryr!Û    szClient.__exit__r–)Ú    pool_sizerpcCsBt|tƒst|tƒr|dks,td|›dƒ‚|dkr8tn||_dS)a“Set the size of the pool.
 
        This method sets the size of the pool but it will not resize the pool.
 
        Args:
            pool_size (int): An integer equal or greater than 0 indicating
                             the pool size.
 
        Raises:
            :class:`AttributeError`: If the pool_size value is not an integer
                                     greater or equal to 0.
        rzGPool max_size value must be an integer greater than 0, the given value ú  is not validN)r~rãr–r•Ú_CNX_POOL_MAXSIZEr±)rŠr`rxrxryr[ã    sÿþý
ÿzClient._set_pool_size)r³rpcCsTt|tƒst|tƒr|dks,td|›dƒ‚||_|dkr>tn
t|dƒ|jd<dS)a}Set the max idle time.
 
        This method sets the max idle time.
 
        Args:
            max_idle_time (int): An integer equal or greater than 0 indicating
                                 the max idle time.
 
        Raises:
            :class:`AttributeError`: If the max_idle_time value is not an
                                     integer greater or equal to 0.
        rßzYConnection max_idle_time value must be an integer greater or equal to 0, the given value rarrr³N)r~rãr–r•r³Ú_CNX_POOL_MAX_IDLE_TIMEr)rŠr³rxrxryr\ü    sÿþý
ÿÿzClient._set_max_idle_timerã)rXrpcCst|tƒstdƒ‚||_dS)aSet if the pool is enabled.
 
        This method sets if the pool is enabled.
 
        Args:
            enabled (bool): True if to enabling the pool.
 
        Raises:
            :class:`AttributeError`: If the value of enabled is not a bool type.
        z*The enabled value should be True or False.N)r~rãr•r_)rŠrXrxrxryr^
s
zClient._set_pool_enabled)r´rpcCsjt|tƒst|tƒr|dks,td|›dƒ‚||_|dkr>tn
t|dƒ|jd<d|jkrf|j|jd<dS)    a}Set the queue timeout.
 
        This method sets the queue timeout.
 
        Args:
            queue_timeout (int): An integer equal or greater than 0 indicating
                                 the queue timeout.
 
        Raises:
            :class:`AttributeError`: If the queue_timeout value is not an
                                     integer greater or equal to 0.
        rßzYConnection queue_timeout value must be an integer greater or equal to 0, the given value rarrr´riN)r~rãr–r•r´Ú_CNX_POOL_QUEUE_TIMEOUTr)rŠr´rxrxryr]'
sÿþý
ÿÿ
zClient._set_queue_timeoutr
cCst|jƒ}|j |¡|S)z~Creates a Session instance using the provided connection data.
 
        Returns:
            Session: Session object.
        )r
rrYrs©rŠÚsessionrxrxryÚ get_sessionG
s
 zClient.get_sessioncCs&tƒ |j¡|jD] }| ¡qdS)z*Closes the sessions opened by this client.N)rúrrrYrSrerxrxryr¦Q
s
z Client.close)N) rèrérêrër‹rr!r[r\r^r]rgr¦rxrxrxryrU¸    s ý 
rUz"Union[Dict[str, List[Dict]], Dict])Úpathrpc     Cs„| dd¡}d|ko.| d¡dko.| d¡dk oD| d¡oD| d¡}g}t |r^|dd…n|¡}d    }|D]Ö}i}t |¡}|r¨| d¡}t    | d
¡ƒ|d <|d7}n t
 |¡}|rÈ| d¡}d |d <t d |›ƒ}|j sêt d|›ƒ‚z|j|j |jdWn6tk
r6}ztd|›dƒ|‚W5d}~XYnX| |¡qld    |kr`t|ƒkrnnn
tddƒ‚|r|d|iS|d    S)zÜParses a list of host, port pairs.
 
    Args:
        path: String containing a list of routers or just router
 
    Returns:
        Returns a dict with parsed values of host, port and priority if
        specified.
    r'Úú,r´rú[ú]rßrr-rrz//zInvalid address: r4z Invalid URI: i¢Nrrrd)Úreplacer˜r8ÚendswithÚ    _SPLIT_RErdÚ _PRIORITY_REÚmatchÚgroupr–Ú
_ROUTER_RErrár)rrcr‘r-rsr)    rhrrrdZ address_listrÚaddressr rqr£rxrxryÚ_parse_address_listX
sD
&ÿý
 
 
 
 
$  ýrur)ÚurirpcCsîddi}t |¡}|r| ¡nd|f\}}|dkrBtd|›dƒ‚|dkrRd|d    <| d
¡d d d …\}}| d ¡d d d …\}}| d¡}||d … d¡dkr¾|dkr¾| dd¡\}|d<| d¡}|rØ|rØd|krètd|›dƒ‚|     dd¡\}    }
t
|    ƒt
|
ƒ|d<|d<|  d¡r,t
|ƒ|d<n$|  d¡rBtdƒ‚n|  t |ƒ¡d} t|dƒD]Š\} } |  dd¡ ¡}|| krtd | ›dƒ‚|tkr®t
|  d¡ƒ||<n8|  ¡}|d!krÊd||<n|d"krÞd#||<n|||<q^|S)$aqParses the connection string and returns a dictionary with the
    connection settings.
 
    Args:
        uri: mysqlx URI scheme to connect to a MySQL server/farm.
 
    Returns:
        Returns a dict with parsed values of credentials and address of the
        MySQL server/farm.
 
    Raises:
        :class:`mysqlx.InterfaceError`: If contains a invalid option.
    rarir¢)r¢ú
mysqlx+srvzScheme 'z' is not validrwTrmú@Nr-ú?ú/ú)rßrrz()r´zMalformed URI 'r r_r`)rzrMr\rez\.zWindows Pipe is not supported)r_r`rmrrrÏzInvalid option: ')Ú1Útrue)Ú0ÚfalseF)Ú_URI_SCHEME_RErqÚgroupsr)Ú    partitionÚrfindÚfindÚrsplitrNrdrr8rrurrmrGÚ    _SSL_OPTS)rvrrqÚschemeÚuserinfoÚtmprbZ    query_strÚposr_r`Zinvalid_optionsrwÚvalÚoptZval_strrxrxryÚ_parse_connection_uri
sH
 
 
 
 
 
 
 
 
 
 rr3c    
Cst| ¡ƒ t¡}|r0d |¡}td|›dƒ‚d|krR|dD]}t|dƒq@nd|krbt|ƒd|krú|d}z&tt|t    ƒrŒ| 
¡  ¡n|ƒ|d<Wn<t t fk
rÔ}ztd|d›dƒ|‚W5d    }~XYnXd
|krú|dtjtjfkrútd ƒ‚d |krd
|krtd ƒ‚d|kr2d|kr2tdƒ‚d
|kr`| d¡tjtjtjfkr`tdƒ‚d|krÚ|d}z(tt|t    ƒrŽ| 
¡  ¡n|ƒ|d<Wn>t t fk
rØ}ztd|d›dƒ|‚W5d    }~XYnXd|krT|d}z(tt|t    ƒr| 
¡  ¡n|ƒ|d<Wn>t t fk
rR}ztd|d›dƒ|‚W5d    }~XYnXd|krÖt|dt    ƒr |d  ¡  d¡}|r–| d¡|d<nd    |d<nt|dttfƒs¼tdƒ‚| d¡tjkrÖd    |d<d|krèt|ƒd|krZzFt|dt    ƒrt|dƒ|d<t|dtƒr2|ddkr6t ‚Wn t k
rXtdƒd    ‚YnXd|krºt|dtƒs|td ƒ‚| d!¡rtd"ƒ‚| d#¡r¤td$ƒ‚| d¡rØtd%ƒ‚nd|krØ| d#¡sØd|d#<d&|krêt|ƒd'|krüt|ƒd    S)(anValidates the settings to be passed to a Session object
    the port values are converted to int if specified or set to 33060
    otherwise. The priority values for each router is converted to int
    if specified.
 
    Args:
        settings: dict containing connection settings.
 
    Raises:
        :class:`mysqlx.InterfaceError`: On any configuration issue.
    z', 'zInvalid option(s): 'r rdr,rbrfzInvalid SSL Mode 'NrZzCannot verify Server without CAr\zCA Certificate not providedr[rYzClient Certificate not providedz$Must verify Server if CA is providedrgzInvalid Auth 'rkzpThe connection property 'compression' acceptable values are: 'preferred', 'required', or 'disabled'. The value 'z' is not acceptablerlz[]rjz@Invalid type of the connection property 'compression-algorithms'rjrirzEThe connection timeout value must be a positive integer (including 0)rmz(The value of 'dns-srv' must be a booleanrez<Using Unix domain sockets with DNS SRV lookup is not allowedrcz;Specifying a port number with DNS SRV lookup is not allowedzASpecifying multiple hostnames with DNS SRV look up is not allowedr]r^)ÚsetÚkeysÚ
differenceÚ
_SESS_OPTSrur)Ú_validate_hostsr&r~rnrGrNr•r‘r½Z    VERIFY_CArrOr$r%rdÚlistr×Ú_validate_connection_attributesr–Ú    TypeErrorrãÚ_validate_tls_versionsÚ_validate_tls_ciphersuites)    rZ invalid_optsZinvalid_opts_listr r¬r£rgrkZcompression_algorithmsrxrxryÚ_validate_settingsÎ
sÒ 
 ÿ (þý
ÿ (
ÿý ÿü
ÿ
ÿ
 
 ÿ
þÿý
 ÿ ÿ ÿ
 
r˜rø)rÚ default_portrpcCsîd|kr|drz6t|dƒ|d<|ddks:|ddkrDtddƒ‚WnHtk
rftddƒd‚Yn*tk
rŽtd|d›dƒd‚YnXd    |krÖ|d    rÖzt|d    ƒ|d    <Wqêtk
rÒtd
ƒd‚YqêXnd |krê|rê||d    <dS) zØValidate hosts.
 
    Args:
        settings (dict): Settings dictionary.
        default_port (int): Default connection port.
 
    Raises:
        :class:`mysqlx.InterfaceError`: If priority or port are invalid.
    rrrz1Invalid priority value, must be between 0 and 100rzInvalid priorityNzInvalid priority: rcz Invalid portrb)r–r-Ú    NameErrorr‘r))rr™rxrxryr’S s0 þ ÿþ r’c    Csâi}d|krdS|d}t|tƒrü|dkr6i|d<dS| d¡rJ| d¡sb|dkrbtd|›dƒ‚|dkrˆ|d    kr|d
|d<ni|d<dS|d d … d ¡}|D]X}|dkr¬qž| d¡}|d}t|ƒd krÒ|d nd}||krîtd|›dƒ‚|||<qžn$t|tƒr:|D]*}||}t|tƒs,t|ƒ}|||<q næt|t    ƒsP|dkrl|r`i|d<nd
|d<dSt|t
ƒrŽ|D]}d||<q|n’t|t ƒr|D]b}|dkr°qž| d¡}|d}t|ƒd krØ|d nd}||krötd|›dƒ‚|||<qžnt|t    ƒs td|›dƒ‚|rÖ|  ¡D]¦\}}t|tƒsRtd|›dƒ‚t|ƒdkrptd|›dƒ‚| d¡rŒtd|›dƒ‚t|tƒs®td|›d|›dƒ‚t|ƒdkr.td|›d|›dƒ‚q.||d<dS)z»Validate connection-attributes.
 
    Args:
        settings (dict): Settings dictionary.
 
    Raises:
        :class:`mysqlx.InterfaceError`: If attribute name or value exceeds size.
    rjNrirkrl)ÚFalserÚTruer}z]The value of 'connection-attributes' must be a boolean or a list of key-value pairs, found: 'r )r›rFrrßrjú=rzDuplicate key 'z' used in connection-attributes)rrzLconnection-attributes must be Boolean or a list of key-value pairs, found: 'r+r,r-r.rrzBKey names in connection-attributes cannot start with '_', found: 'z Attribute 'r0r/r1) r~rnr8rnr)rdrrÚreprrãrŽr“r)    rrJrWZconn_attributesÚattrZ attr_name_valr9Zattr_valr:rxrxryr”w s®    
ÿÿþ
ÿ
 
 
ÿ  
 
 
 
 
ÿ 
ÿ 
ÿ
ÿ 
ÿ ÿÿr”c    Csäg}d|krdS|d}t|tƒrš| d¡r6| d¡sFtd|›dƒ‚|dd… d    ¡}|D]:}| ¡}|d
krrq\||krŒttjd |d ƒ‚|     |¡q\n„t|t
ƒrà|s°td ƒ‚|D](}||krÒttjd |d ƒ‚|     |¡q´n>t|t ƒr|D]}|     |¡qðntdd  t ¡›d|›dƒ‚|s,td ƒ‚g}g}g}|D]:}|t krT|     |¡|tkrj|     |¡n
|     |¡q<|r²|dgkr ts tt |t ¡ƒ‚| ¡||d<n.|rÊtt |t ¡ƒ‚n|ràtt |t ¡ƒ‚dS)z¬Validate tls-versions.
 
    Args:
        settings (dict): Settings dictionary.
 
    Raises:
        :class:`mysqlx.InterfaceError`: If tls-versions name is not valid.
    r]Nrkrlz%tls-versions must be a list, found: 'r rrßrjriÚ tls_versions©r“rjzKAt least one TLS protocol version must be specified in 'tls-versions' list.z>tls-versions should be a list with one or more of versions in r¹z
. found: 'r)r~rnr8rnr)rdrNrNr@rsr“rŽrur"r rÃr*rOrÂrPrQ)    rr Ztls_versions_settingsZtls_versÚtls_verrßZuse_tls_versionsZdeprecated_tls_versionsZnot_tls_versionsrxrxryr–ç sŽ    
ÿþ
ÿÿÿ
ÿ ÿ ÿÿ
 
 
 
ÿ
ÿÿr–c CsÎg}d|krdS|d}t|tƒrŠ| d¡r6| d¡sFtd|›dƒ‚|dd… d    ¡}|sdtd
ƒ‚|D]}| ¡ ¡}|rh| |¡qhn.t|t    t
fƒr¨d d „|Dƒ}ntd |›dƒ‚|  dd¡dkrÔt dd…n|ddd…}|j dd|d}g}i}g}    t dt  |¡d…D]"}
| t|
¡|     t|
¡q|D]p} d| krf| |    krf| | ¡nJ| |kr || } | |kr”ttjd| dƒ‚| | ¡ntd| ›dƒ‚qB|sÂtd
ƒ‚||d<dS)z´Validate tls-ciphersuites.
 
    Args:
        settings (dict): Settings dictionary.
 
    Raises:
        :class:`mysqlx.InterfaceError`: If tls-ciphersuites name is not valid.
    r^Nrkrlz)tls-ciphersuites must be a list, found: 'r rrßrjz:No valid cipher suite found in the 'tls-ciphersuites' listcSsg|] }|r|‘qSrxrx)r!Útls_csrxrxryr"d sz._validate_tls_ciphersuites.<locals>.<listcomp>zItls-ciphersuites should be a list with one or more ciphersuites. Found: 'r]Tr²rrÏÚtls_ciphersuitesr¡z The value 'z.' in cipher suites is not a valid cipher suite)r~rnr8rnr)rdrNÚupperrsr“rŽrr"rÂr)rr#r×r!r•rNr@) rr¤Ztls_ciphersuites_settingsZtls_cssr£r Z newer_tls_verZtranslated_namesZiani_cipher_suites_namesZossl_cipher_suites_namesr¢rÕZtranslated_namerxrxryr—B sz    
ÿþ
ÿÿ 
ÿÿý  ÿ
 
 
ÿÿ 
ÿÿr—)rîrorpcOs˜i}|rZt|dtƒr$t|dƒ}q€t|dtƒr€|d ¡D]\}}||| dd¡<q>n&|r€| ¡D]\}}||| dd¡<qf|sŒtdƒ‚t|ƒ|S)aZParses the connection string and returns a dictionary with the
    connection settings.
 
    Args:
        *args: Variable length argument list with the connection data used
               to connect to the database. It can be a dictionary or a
               connection string.
        **kwargs: Arbitrary keyword arguments with connection data used to
                  connect to the database.
 
    Returns:
        mysqlx.Session: Session object.
 
    Raises:
        TypeError: If connection timeout is not a positive integer.
        :class:`mysqlx.InterfaceError`: If settings not provided.
    rrrrÏzSettings not provided)r~rnrrrrmr)r˜)rîrorrwr‹rxrxryÚ_get_connection_settings› sr¦cOst||Ž}t|ƒS)a°Creates a Session instance using the provided connection data.
 
    Args:
        *args: Variable length argument list with the connection data used
               to connect to a MySQL server. It can be a dictionary or a
               connection string.
        **kwargs: Arbitrary keyword arguments with connection data used to
                  connect to the database.
 
    Returns:
        mysqlx.Session: Session object.
    )r¦r
)rîrorrxrxryrg¿ s
rgzUnion[str, Dict[str, Any]])Úconnection_stringÚoptions_stringrpc    
Csdt|ttfƒstdƒ‚t|ƒ}t|ttfƒs4tdƒ‚t|tƒr|zt |¡}Wq¢tk
rx}ztdƒ|‚W5d}~XYq¢Xn&i}| ¡D]\}}|||     dd¡<qˆt|tƒs´tdƒ‚i}d|krZ| 
d¡}t|tƒsÞtdƒ‚| 
d    d
¡|d    <| 
d d ¡|d <| 
d d¡|d <| 
dd¡|d<t |ƒdkr:td|›ƒ‚t |ƒdkrZtd|  ¡›ƒ‚t ||ƒS)a8Creates a Client instance with the provided connection data and settings.
 
    Args:
        connection_string: A string or a dict type object to indicate the             connection data used to connect to a MySQL server.
 
            The string must have the following uri format::
 
                cnx_str = 'mysqlx://{user}:{pwd}@{host}:{port}'
                cnx_str = ('mysqlx://{user}:{pwd}@['
                           '    (address={host}:{port}, priority=n),'
                           '    (address={host}:{port}, priority=n), ...]'
                           '       ?[option=value]')
 
            And the dictionary::
 
                cnx_dict = {
                    'host': 'The host where the MySQL product is running',
                    'port': '(int) the port number configured for X protocol',
                    'user': 'The user name account',
                    'password': 'The password for the given user account',
                    'ssl-mode': 'The flags for ssl mode in mysqlx.SSLMode.FLAG',
                    'ssl-ca': 'The path to the ca.cert'
                    "connect-timeout": '(int) milliseconds to wait on timeout'
                }
 
        options_string: A string in the form of a document or a dictionary             type with configuration for the client.
 
            Current options include::
 
                options = {
                    'pooling': {
                        'enabled': (bool), # [True | False], True by default
                        'max_size': (int), # Maximum connections per pool
                        "max_idle_time": (int), # milliseconds that a
                            # connection will remain active while not in use.
                            # By default 0, means infinite.
                        "queue_timeout": (int), # milliseconds a request will
                            # wait for a connection to become available.
                            # By default 0, means infinite.
                    }
                }
 
    Returns:
        mysqlx.Client: Client object.
 
    .. versionadded:: 8.0.13
    z(connection_data must be a string or dictz+connection_options must be a string or dictzA'pooling' options must be given in the form of a document or dictNrÏrrr z<'pooling' options must be given in the form document or dictrXTr±r²r³rr´zUnrecognized pooling options: z!Unrecognized connection options: )r~rnrr)r¦ÚjsonÚloadsrrrmrñrrrU)    r§r¨Z settings_dictrWr£rwrjZpooling_options_dictZpooling_optionsrxrxryÚ
get_clientÐ sN5
ÿþ
ÿ
 
 
ÿ ÿr«)N)¬rëÚ
__future__rÚtypesrr»rºÚPROTOCOL_TLSv1ÚPROTOCOL_TLSv1_1ÚPROTOCOL_TLSv1_2rÄÚhasattrrÚPROTOCOL_SSLv23r    rÃÚ ImportErrorr©rÔrbr¼r&ÚrererfrÿrLrÛÚtypingr
r r r rrrrrZ dns.exceptionrZ dns.resolverrrrÚ    functoolsrZ json.decoderrÚ urllib.parserrrZauthenticationrrrÚ    constantsrr r!r"r#r$r%r&Zcrudr(Úerrorsr)r*r+r,r-r.Zhelpersr/r0r1r2Zprotobufr3r6r4r5r6r7r8rýr9r:r;r<r=rƒr>r?r@rArBrCrDrErFrGrHrIrJrKrLrhrsZmysql.connector.abstractsrNrOrPrQZmysql.connector.utilsrRZmysql.connector.versionrSrTrörìrCrEr?rÕrbrÀÚcompiler¿rcrdZ_PENALTY_SERVER_OFFLINEZ_PENALTY_MAXED_OUTZ_PENALTY_NO_ADD_INFOZ_PENALTY_CONN_TIMEOUTZ_PENALTY_WRONG_PASSWZ_PENALTY_RESTARTINGrr€roÚVERBOSErprsr€r†r‘rzr‚rƒrrrr ròrór½rªrúr
rUrurr˜r’r”r–r—r¦rgr«rxrxrxryÚ<module>s0  ýÿý
, 
  (
   4   û
ÿ
ó
 
úñ u>$_IX _!7?ÿ$p[Y$