File tree 3 files changed +13
-6
lines changed
3 files changed +13
-6
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import pymysql
4
4
import struct
5
+ from distutils .version import LooseVersion
5
6
6
7
from pymysql .constants .COMMAND import COM_BINLOG_DUMP , COM_REGISTER_SLAVE
7
8
from pymysql .cursors import DictCursor
@@ -259,7 +260,7 @@ def _register_slave(self):
259
260
260
261
packet = self .report_slave .encoded (self .__server_id )
261
262
262
- if pymysql .__version__ < "0.6" :
263
+ if pymysql .__version__ < LooseVersion ( "0.6" ) :
263
264
self ._stream_connection .wfile .write (packet )
264
265
self ._stream_connection .wfile .flush ()
265
266
self ._stream_connection .read_packet ()
@@ -407,7 +408,7 @@ def __connect_to_stream(self):
407
408
# encoded_data
408
409
prelude += gtid_set .encoded ()
409
410
410
- if pymysql .__version__ < "0.6" :
411
+ if pymysql .__version__ < LooseVersion ( "0.6" ) :
411
412
self ._stream_connection .wfile .write (prelude )
412
413
self ._stream_connection .wfile .flush ()
413
414
else :
@@ -424,7 +425,7 @@ def fetchone(self):
424
425
self .__connect_to_ctl ()
425
426
426
427
try :
427
- if pymysql .__version__ < "0.6" :
428
+ if pymysql .__version__ < LooseVersion ( "0.6" ) :
428
429
pkt = self ._stream_connection .read_packet ()
429
430
else :
430
431
pkt = self ._stream_connection ._read_packet ()
Original file line number Diff line number Diff line change 6
6
import json
7
7
8
8
from pymysql .util import byte2int
9
- from pymysql .charset import charset_to_encoding
9
+ from pymysql .charset import charset_by_name
10
10
11
11
from .event import BinLogEvent
12
12
from .exceptions import TableMetadataUnavailableError
@@ -212,10 +212,16 @@ def __read_fsp(self, column):
212
212
return microsecond * (10 ** (6 - column .fsp ))
213
213
return 0
214
214
215
+ @staticmethod
216
+ def charset_to_encoding (name ):
217
+ charset = charset_by_name (name )
218
+ return charset .encoding if charset else name
219
+
215
220
def __read_string (self , size , column ):
216
221
string = self .packet .read_length_coded_pascal_string (size )
217
222
if column .character_set_name is not None :
218
- string = string .decode (charset_to_encoding (column .character_set_name ))
223
+ encoding = self .charset_to_encoding (column .character_set_name )
224
+ string = string .decode (encoding )
219
225
return string
220
226
221
227
def __read_bit (self , column ):
Original file line number Diff line number Diff line change @@ -50,5 +50,5 @@ def run(self):
50
50
"pymysqlreplication.tests" ],
51
51
cmdclass = {"test" : TestCommand },
52
52
extras_require = {'test' : tests_require },
53
- install_requires = ['pymysql' ],
53
+ install_requires = ['pymysql>=0.6 ' ],
54
54
)
You can’t perform that action at this time.
0 commit comments