Skip to content

Refactor super() usage in classes #433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions pymysqlreplication/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class GtidEvent(BinLogEvent):
"""GTID change in binlog event
"""
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(GtidEvent, self).__init__(from_packet, event_size, table_map,
super().__init__(from_packet, event_size, table_map,
ctl_connection, **kwargs)

self.commit_flag = struct.unpack("!B", self.packet.read(1))[0] == 1
Expand Down Expand Up @@ -97,7 +97,7 @@ class MariadbGtidEvent(BinLogEvent):
"""
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):

super(MariadbGtidEvent, self).__init__(from_packet, event_size, table_map, ctl_connection, **kwargs)
super().__init__(from_packet, event_size, table_map, ctl_connection, **kwargs)

self.server_id = self.packet.server_id
self.gtid_seq_no = self.packet.read_uint64()
Expand All @@ -106,7 +106,7 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
self.gtid = "%d-%d-%d" % (self.domain_id, self.server_id, self.gtid_seq_no)

def _dump(self):
super(MariadbGtidEvent, self)._dump()
super()._dump()
print("Flags:", self.flags)
print('GTID:', self.gtid)

Expand All @@ -121,11 +121,11 @@ class MariadbAnnotateRowsEvent(BinLogEvent):
sql_statement: The SQL statement
"""
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(MariadbAnnotateRowsEvent, self).__init__(from_packet, event_size, table_map, ctl_connection, **kwargs)
super().__init__(from_packet, event_size, table_map, ctl_connection, **kwargs)
self.sql_statement = self.packet.read(event_size)

def _dump(self):
super(MariadbAnnotateRowsEvent, self)._dump()
super()._dump()
print("SQL statement :", self.sql_statement)


Expand All @@ -137,7 +137,7 @@ class RotateEvent(BinLogEvent):
next_binlog: Name of next binlog file
"""
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(RotateEvent, self).__init__(from_packet, event_size, table_map,
super().__init__(from_packet, event_size, table_map,
ctl_connection, **kwargs)
self.position = struct.unpack('<Q', self.packet.read(8))[0]
self.next_binlog = self.packet.read(event_size - 8).decode()
Expand All @@ -158,7 +158,7 @@ class XAPrepareEvent(BinLogEvent):
xid: serialized XID representation of XA transaction
"""
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(XAPrepareEvent, self).__init__(from_packet, event_size, table_map,
super().__init__(from_packet, event_size, table_map,
ctl_connection, **kwargs)

# one_phase is True: XA COMMIT ... ONE PHASE
Expand All @@ -182,7 +182,7 @@ def _dump(self):

class FormatDescriptionEvent(BinLogEvent):
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(FormatDescriptionEvent, self).__init__(from_packet, event_size, table_map,
super().__init__(from_packet, event_size, table_map,
ctl_connection, **kwargs)
self.binlog_version = struct.unpack('<H', self.packet.read(2))
self.mysql_version_str = self.packet.read(50).rstrip(b'\0').decode()
Expand All @@ -206,12 +206,12 @@ class XidEvent(BinLogEvent):
"""

def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(XidEvent, self).__init__(from_packet, event_size, table_map,
super().__init__(from_packet, event_size, table_map,
ctl_connection, **kwargs)
self.xid = struct.unpack('<Q', self.packet.read(8))[0]

def _dump(self):
super(XidEvent, self)._dump()
super()._dump()
print("Transaction ID: %d" % (self.xid))


Expand All @@ -236,21 +236,21 @@ class HeartbeatLogEvent(BinLogEvent):
"""

def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(HeartbeatLogEvent, self).__init__(from_packet, event_size,
super().__init__(from_packet, event_size,
table_map, ctl_connection,
**kwargs)
self.ident = self.packet.read(event_size).decode()

def _dump(self):
super(HeartbeatLogEvent, self)._dump()
super()._dump()
print("Current binlog: %s" % (self.ident))


class QueryEvent(BinLogEvent):
'''This event is trigger when a query is run of the database.
Only replicated queries are logged.'''
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(QueryEvent, self).__init__(from_packet, event_size, table_map,
super().__init__(from_packet, event_size, table_map,
ctl_connection, **kwargs)

# Post-header
Expand All @@ -276,7 +276,7 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
#string[EOF] query

def _dump(self):
super(QueryEvent, self)._dump()
super()._dump()
print("Schema: %s" % (self.schema))
print("Execution time: %d" % (self.execution_time))
print("Query: %s" % (self.query))
Expand Down Expand Up @@ -376,15 +376,15 @@ class BeginLoadQueryEvent(BinLogEvent):
block-data
"""
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(BeginLoadQueryEvent, self).__init__(from_packet, event_size, table_map,
super().__init__(from_packet, event_size, table_map,
ctl_connection, **kwargs)

# Payload
self.file_id = self.packet.read_uint32()
self.block_data = self.packet.read(event_size - 4)

def _dump(self):
super(BeginLoadQueryEvent, self)._dump()
super()._dump()
print("File id: %d" % (self.file_id))
print("Block data: %s" % (self.block_data))

Expand All @@ -405,7 +405,7 @@ class ExecuteLoadQueryEvent(BinLogEvent):
dup_handling_flags
"""
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(ExecuteLoadQueryEvent, self).__init__(from_packet, event_size, table_map,
super().__init__(from_packet, event_size, table_map,
ctl_connection, **kwargs)

# Post-header
Expand Down Expand Up @@ -442,15 +442,15 @@ class IntvarEvent(BinLogEvent):
value
"""
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(IntvarEvent, self).__init__(from_packet, event_size, table_map,
super().__init__(from_packet, event_size, table_map,
ctl_connection, **kwargs)

# Payload
self.type = self.packet.read_uint8()
self.value = self.packet.read_uint32()

def _dump(self):
super(IntvarEvent, self)._dump()
super()._dump()
print("type: %d" % (self.type))
print("Value: %d" % (self.value))

Expand All @@ -467,7 +467,7 @@ class RandEvent(BinLogEvent):
"""

def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(RandEvent, self).__init__(from_packet, event_size, table_map,
super().__init__(from_packet, event_size, table_map,
ctl_connection, **kwargs)
# Payload
self._seed1 = self.packet.read_uint64()
Expand All @@ -484,7 +484,7 @@ def seed2(self):
return self._seed2

def _dump(self):
super(RandEvent, self)._dump()
super()._dump()
print("seed1: %d" % (self.seed1))
print("seed2: %d" % (self.seed2))

Expand All @@ -505,7 +505,7 @@ class MariadbStartEncryptionEvent(BinLogEvent):
"""

def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(MariadbStartEncryptionEvent, self).__init__(from_packet, event_size, table_map, ctl_connection, **kwargs)
super().__init__(from_packet, event_size, table_map, ctl_connection, **kwargs)

self.schema = self.packet.read_uint8()
self.key_version = self.packet.read_uint32()
Expand All @@ -519,6 +519,6 @@ def _dump(self):

class NotImplementedEvent(BinLogEvent):
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(NotImplementedEvent, self).__init__(
super().__init__(
from_packet, event_size, table_map, ctl_connection, **kwargs)
self.packet.advance(event_size)
20 changes: 10 additions & 10 deletions pymysqlreplication/row_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class RowsEvent(BinLogEvent):
def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(RowsEvent, self).__init__(from_packet, event_size, table_map,
super().__init__(from_packet, event_size, table_map,
ctl_connection, **kwargs)
self.__rows = None
self.__only_tables = kwargs["only_tables"]
Expand Down Expand Up @@ -449,7 +449,7 @@ def __read_binary_slice(self, binary, start, size, data_length):
return binary & mask

def _dump(self):
super(RowsEvent, self)._dump()
super()._dump()
print("Table: %s.%s" % (self.schema, self.table))
print("Affected columns: %d" % self.number_of_columns)
print("Changed rows: %d" % (len(self.rows)))
Expand Down Expand Up @@ -477,7 +477,7 @@ class DeleteRowsEvent(RowsEvent):
"""

def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(DeleteRowsEvent, self).__init__(from_packet, event_size,
super().__init__(from_packet, event_size,
table_map, ctl_connection, **kwargs)
if self._processed:
self.columns_present_bitmap = self.packet.read(
Expand All @@ -490,7 +490,7 @@ def _fetch_one_row(self):
return row

def _dump(self):
super(DeleteRowsEvent, self)._dump()
super()._dump()
print("Values:")
for row in self.rows:
print("--")
Expand All @@ -505,7 +505,7 @@ class WriteRowsEvent(RowsEvent):
"""

def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(WriteRowsEvent, self).__init__(from_packet, event_size,
super().__init__(from_packet, event_size,
table_map, ctl_connection, **kwargs)
if self._processed:
self.columns_present_bitmap = self.packet.read(
Expand All @@ -518,7 +518,7 @@ def _fetch_one_row(self):
return row

def _dump(self):
super(WriteRowsEvent, self)._dump()
super()._dump()
print("Values:")
for row in self.rows:
print("--")
Expand All @@ -538,7 +538,7 @@ class UpdateRowsEvent(RowsEvent):
"""

def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(UpdateRowsEvent, self).__init__(from_packet, event_size,
super().__init__(from_packet, event_size,
table_map, ctl_connection, **kwargs)
if self._processed:
#Body
Expand All @@ -556,7 +556,7 @@ def _fetch_one_row(self):
return row

def _dump(self):
super(UpdateRowsEvent, self)._dump()
super()._dump()
print("Affected columns: %d" % self.number_of_columns)
print("Values:")
for row in self.rows:
Expand All @@ -574,7 +574,7 @@ class TableMapEvent(BinLogEvent):
"""

def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs):
super(TableMapEvent, self).__init__(from_packet, event_size,
super().__init__(from_packet, event_size,
table_map, ctl_connection, **kwargs)
self.__only_tables = kwargs["only_tables"]
self.__ignored_tables = kwargs["ignored_tables"]
Expand Down Expand Up @@ -669,7 +669,7 @@ def get_table(self):
return self.table_obj

def _dump(self):
super(TableMapEvent, self)._dump()
super()._dump()
print("Table id: %d" % (self.table_id))
print("Schema: %s" % (self.schema))
print("Table: %s" % (self.table))
Expand Down
10 changes: 5 additions & 5 deletions pymysqlreplication/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ def test_alter_column(self):
class TestCTLConnectionSettings(base.PyMySQLReplicationTestCase):

def setUp(self):
super(TestCTLConnectionSettings, self).setUp()
super().setUp()
self.stream.close()
ctl_db = copy.copy(self.database)
ctl_db["db"] = None
Expand All @@ -788,7 +788,7 @@ def setUp(self):
)

def tearDown(self):
super(TestCTLConnectionSettings, self).tearDown()
super().tearDown()
self.ctl_conn_control.close()

def test_separate_ctl_settings_table_metadata_unavailable(self):
Expand Down Expand Up @@ -823,7 +823,7 @@ def test_separate_ctl_settings_no_error(self):

class TestGtidBinLogStreamReader(base.PyMySQLReplicationTestCase):
def setUp(self):
super(TestGtidBinLogStreamReader, self).setUp()
super().setUp()
if not self.supportsGTID:
raise unittest.SkipTest("database does not support GTID, skipping GTID tests")

Expand Down Expand Up @@ -1075,7 +1075,7 @@ def test_start_encryption_event(self):

class TestStatementConnectionSetting(base.PyMySQLReplicationTestCase):
def setUp(self):
super(TestStatementConnectionSetting, self).setUp()
super().setUp()
self.stream.close()
self.stream = BinLogStreamReader(
self.database,
Expand All @@ -1102,7 +1102,7 @@ def test_rand_event(self):
def tearDown(self):
self.execute("SET @@binlog_format='ROW'")
self.assertEqual(self.bin_log_format(), "ROW")
super(TestStatementConnectionSetting, self).tearDown()
super().tearDown()


if __name__ == "__main__":
Expand Down