Skip to content

Commit 243656d

Browse files
authored
Merge pull request #597 from eli-kir/main
Optimizing version check to happen once per run
2 parents c952ced + dd5ae00 commit 243656d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pymysqlreplication/binlogstream.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
# 2006 MySQL server has gone away
5252
MYSQL_EXPECTED_ERROR_CODES = [2013, 2006]
5353

54+
PYMYSQL_VERSION_LT_06 = Version(pymysql.__version__) < Version("0.6")
55+
5456

5557
class ReportSlave(object):
5658
"""Represent the values that you may report when connecting as a slave
@@ -330,7 +332,7 @@ def _register_slave(self):
330332

331333
packet = self.report_slave.encoded(self.__server_id)
332334

333-
if Version(pymysql.__version__) < Version("0.6"):
335+
if PYMYSQL_VERSION_LT_06:
334336
self._stream_connection.wfile.write(packet)
335337
self._stream_connection.wfile.flush()
336338
self._stream_connection.read_packet()
@@ -502,7 +504,7 @@ def __connect_to_stream(self):
502504
# encoded_data
503505
prelude += gtid_set.encoded()
504506

505-
if Version(pymysql.__version__) < Version("0.6"):
507+
if PYMYSQL_VERSION_LT_06:
506508
self._stream_connection.wfile.write(prelude)
507509
self._stream_connection.wfile.flush()
508510
else:
@@ -588,7 +590,7 @@ def fetchone(self):
588590
self.__connect_to_ctl()
589591

590592
try:
591-
if Version(pymysql.__version__) < Version("0.6"):
593+
if PYMYSQL_VERSION_LT_06:
592594
pkt = self._stream_connection.read_packet()
593595
else:
594596
pkt = self._stream_connection._read_packet()

0 commit comments

Comments
 (0)