Skip to content

Commit d180d65

Browse files
Merge pull request julien-duponchelle#518 from 23-OSSCA-python-mysql-replication/python2_minor_fix
python2 minor fix
2 parents 32fa176 + 213f9b8 commit d180d65

File tree

4 files changed

+31
-269
lines changed

4 files changed

+31
-269
lines changed

pymysqlreplication/bitmap.py

+18-256
Original file line numberDiff line numberDiff line change
@@ -1,261 +1,23 @@
1+
# fmt: off
12
bitCountInByte = [
2-
0,
3-
1,
4-
1,
5-
2,
6-
1,
7-
2,
8-
2,
9-
3,
10-
1,
11-
2,
12-
2,
13-
3,
14-
2,
15-
3,
16-
3,
17-
4,
18-
1,
19-
2,
20-
2,
21-
3,
22-
2,
23-
3,
24-
3,
25-
4,
26-
2,
27-
3,
28-
3,
29-
4,
30-
3,
31-
4,
32-
4,
33-
5,
34-
1,
35-
2,
36-
2,
37-
3,
38-
2,
39-
3,
40-
3,
41-
4,
42-
2,
43-
3,
44-
3,
45-
4,
46-
3,
47-
4,
48-
4,
49-
5,
50-
2,
51-
3,
52-
3,
53-
4,
54-
3,
55-
4,
56-
4,
57-
5,
58-
3,
59-
4,
60-
4,
61-
5,
62-
4,
63-
5,
64-
5,
65-
6,
66-
1,
67-
2,
68-
2,
69-
3,
70-
2,
71-
3,
72-
3,
73-
4,
74-
2,
75-
3,
76-
3,
77-
4,
78-
3,
79-
4,
80-
4,
81-
5,
82-
2,
83-
3,
84-
3,
85-
4,
86-
3,
87-
4,
88-
4,
89-
5,
90-
3,
91-
4,
92-
4,
93-
5,
94-
4,
95-
5,
96-
5,
97-
6,
98-
2,
99-
3,
100-
3,
101-
4,
102-
3,
103-
4,
104-
4,
105-
5,
106-
3,
107-
4,
108-
4,
109-
5,
110-
4,
111-
5,
112-
5,
113-
6,
114-
3,
115-
4,
116-
4,
117-
5,
118-
4,
119-
5,
120-
5,
121-
6,
122-
4,
123-
5,
124-
5,
125-
6,
126-
5,
127-
6,
128-
6,
129-
7,
130-
1,
131-
2,
132-
2,
133-
3,
134-
2,
135-
3,
136-
3,
137-
4,
138-
2,
139-
3,
140-
3,
141-
4,
142-
3,
143-
4,
144-
4,
145-
5,
146-
2,
147-
3,
148-
3,
149-
4,
150-
3,
151-
4,
152-
4,
153-
5,
154-
3,
155-
4,
156-
4,
157-
5,
158-
4,
159-
5,
160-
5,
161-
6,
162-
2,
163-
3,
164-
3,
165-
4,
166-
3,
167-
4,
168-
4,
169-
5,
170-
3,
171-
4,
172-
4,
173-
5,
174-
4,
175-
5,
176-
5,
177-
6,
178-
3,
179-
4,
180-
4,
181-
5,
182-
4,
183-
5,
184-
5,
185-
6,
186-
4,
187-
5,
188-
5,
189-
6,
190-
5,
191-
6,
192-
6,
193-
7,
194-
2,
195-
3,
196-
3,
197-
4,
198-
3,
199-
4,
200-
4,
201-
5,
202-
3,
203-
4,
204-
4,
205-
5,
206-
4,
207-
5,
208-
5,
209-
6,
210-
3,
211-
4,
212-
4,
213-
5,
214-
4,
215-
5,
216-
5,
217-
6,
218-
4,
219-
5,
220-
5,
221-
6,
222-
5,
223-
6,
224-
6,
225-
7,
226-
3,
227-
4,
228-
4,
229-
5,
230-
4,
231-
5,
232-
5,
233-
6,
234-
4,
235-
5,
236-
5,
237-
6,
238-
5,
239-
6,
240-
6,
241-
7,
242-
4,
243-
5,
244-
5,
245-
6,
246-
5,
247-
6,
248-
6,
249-
7,
250-
5,
251-
6,
252-
6,
253-
7,
254-
6,
255-
7,
256-
7,
257-
8,
3+
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
4+
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
5+
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
6+
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
7+
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
8+
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
9+
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
10+
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
11+
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
12+
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
13+
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
14+
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
15+
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
16+
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
17+
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
18+
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
25819
]
20+
# fmt: on
25921

26022

26123
# Calculate total bit counts in a bitmap

pymysqlreplication/tests/base.py

+7
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ def isMySQL8014AndMore(self):
8585
return True
8686
return version == 8.0 and version_detail >= 14
8787

88+
def isMySQL8016AndMore(self):
89+
version = float(self.getMySQLVersion().rsplit(".", 1)[0])
90+
version_detail = int(self.getMySQLVersion().rsplit(".", 1)[1])
91+
if version > 8.0:
92+
return True
93+
return version == 8.0 and version_detail >= 16
94+
8895
def isMariaDB(self):
8996
if self.__is_mariaDB is None:
9097
self.__is_mariaDB = (

pymysqlreplication/tests/benchmark.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def consume_events():
2525
only_events=[UpdateRowsEvent],
2626
only_tables=["test"],
2727
)
28-
start = time.clock()
28+
start = time.perf_counter()
2929
i = 0.0
3030
for binlogevent in stream:
3131
i += 1.0
3232
if i % 1000 == 0:
33-
print(f"{i / (time.clock()- start)} event by seconds ({i} total)")
33+
print(f"{i / (time.perf_counter()- start)} event by seconds ({i} total)")
3434

3535
stream.close()
3636

pymysqlreplication/tests/test_data_type.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import copy
2-
import platform
32
import json
43
from pymysqlreplication import BinLogStreamReader
54
import unittest
@@ -776,10 +775,7 @@ def test_encoding_latin1(self):
776775
db["charset"] = "latin1"
777776
self.connect_conn_control(db)
778777

779-
if platform.python_version_tuple()[0] == "2":
780-
string = unichr(233)
781-
else:
782-
string = "\u00e9"
778+
string = "\u00e9"
783779

784780
create_query = (
785781
"CREATE TABLE test (test CHAR(12)) CHARACTER SET latin1 COLLATE latin1_bin;"
@@ -790,10 +786,7 @@ def test_encoding_latin1(self):
790786
self.assertEqual(event.rows[0]["values"]["test"], string)
791787

792788
def test_encoding_utf8(self):
793-
if platform.python_version_tuple()[0] == "2":
794-
string = unichr(0x20AC)
795-
else:
796-
string = "\u20ac"
789+
string = "\u20ac"
797790

798791
create_query = (
799792
"CREATE TABLE test (test CHAR(12)) CHARACTER SET utf8 COLLATE utf8_bin;"
@@ -805,7 +798,7 @@ def test_encoding_utf8(self):
805798
self.assertMultiLineEqual(event.rows[0]["values"]["test"], string)
806799

807800
def test_partition_id(self):
808-
if not self.isMySQL80AndMore():
801+
if not self.isMySQL8016AndMore():
809802
self.skipTest("Not supported in this version of MySQL")
810803
create_query = "CREATE TABLE test (id INTEGER) \
811804
PARTITION BY RANGE (id) ( \
@@ -970,7 +963,7 @@ def create_and_insert_value(self, create_query, insert_query):
970963
return event
971964

972965
def test_partition_id(self):
973-
if not self.isMySQL80AndMore():
966+
if not self.isMySQL8016AndMore():
974967
self.skipTest("Not supported in this version of MySQL")
975968
create_query = "CREATE TABLE test (id INTEGER) \
976969
PARTITION BY RANGE (id) ( \

0 commit comments

Comments
 (0)