47
47
48
48
DEBUG = False
49
49
50
- _py_version = sys .version_info [:2 ]
51
-
52
-
53
- def _fast_surrogateescape (s ):
54
- return s .decode ("ascii" , "surrogateescape" )
55
-
56
-
57
- def _makefile (sock , mode ):
58
- return sock .makefile (mode )
59
-
60
-
61
50
TEXT_TYPES = {
62
51
FIELD_TYPE .BIT ,
63
52
FIELD_TYPE .BLOB ,
@@ -76,12 +65,12 @@ def _makefile(sock, mode):
76
65
MAX_PACKET_LEN = 2 ** 24 - 1
77
66
78
67
79
- def pack_int24 (n ):
68
+ def _pack_int24 (n ):
80
69
return struct .pack ("<I" , n )[:3 ]
81
70
82
71
83
72
# https://dev.mysql.com/doc/internals/en/integer.html#packet-Protocol::LengthEncodedInteger
84
- def lenenc_int (i ):
73
+ def _lenenc_int (i ):
85
74
if i < 0 :
86
75
raise ValueError (
87
76
"Encoding %d is less than 0 - no representation in LengthEncodedInteger" % i
@@ -535,7 +524,7 @@ def escape_string(self, s):
535
524
536
525
def _quote_bytes (self , s ):
537
526
if self .server_status & SERVER_STATUS .SERVER_STATUS_NO_BACKSLASH_ESCAPES :
538
- return "'%s'" % (_fast_surrogateescape ( s .replace (b"'" , b"''" )),)
527
+ return "'%s'" % (s .replace (b"'" , b"''" ). decode ( "ascii" , "surrogateescape" ),)
539
528
return converters .escape_bytes (s )
540
529
541
530
def cursor (self , cursor = None ):
@@ -638,7 +627,7 @@ def connect(self, sock=None):
638
627
sock .settimeout (None )
639
628
640
629
self ._sock = sock
641
- self ._rfile = _makefile ( sock , "rb" )
630
+ self ._rfile = sock . makefile ( "rb" )
642
631
self ._next_seq_id = 0
643
632
644
633
self ._get_server_information ()
@@ -686,7 +675,7 @@ def write_packet(self, payload):
686
675
"""
687
676
# Internal note: when you build packet manually and calls _write_bytes()
688
677
# directly, you should set self._next_seq_id properly.
689
- data = pack_int24 (len (payload )) + int2byte (self ._next_seq_id ) + payload
678
+ data = _pack_int24 (len (payload )) + int2byte (self ._next_seq_id ) + payload
690
679
if DEBUG :
691
680
dump_packet (data )
692
681
self ._write_bytes (data )
@@ -859,7 +848,7 @@ def _request_authentication(self):
859
848
self .write_packet (data_init )
860
849
861
850
self ._sock = self .ctx .wrap_socket (self ._sock , server_hostname = self .host )
862
- self ._rfile = _makefile ( self ._sock , "rb" )
851
+ self ._rfile = self ._sock . makefile ( "rb" )
863
852
self ._secure = True
864
853
865
854
data = data_init + self .user + b"\0 "
@@ -892,7 +881,7 @@ def _request_authentication(self):
892
881
authresp = b"\0 " # empty password
893
882
894
883
if self .server_capabilities & CLIENT .PLUGIN_AUTH_LENENC_CLIENT_DATA :
895
- data += lenenc_int (len (authresp )) + authresp
884
+ data += _lenenc_int (len (authresp )) + authresp
896
885
elif self .server_capabilities & CLIENT .SECURE_CONNECTION :
897
886
data += struct .pack ("B" , len (authresp )) + authresp
898
887
else : # pragma: no cover - not testing against servers without secure auth (>=5.0)
0 commit comments