@@ -42,16 +42,19 @@ class Gtid(object):
42
42
43
43
SID:1-74
44
44
45
- Adding an already present transaction number (one that overlaps) will
46
- raise an exception.
47
-
48
- Adding a Gtid with a different SID will raise an exception .
45
+ Raises:
46
+ ValueError: If construction parsing from string fails
47
+ Exception: Adding an already present transaction number (one that overlaps).
48
+ Exception: Adding a Gtid with a different SID.
49
49
"""
50
50
@staticmethod
51
51
def parse_interval (interval ):
52
52
"""
53
53
We parse a human-generated string here. So our end value b
54
54
is incremented to conform to the internal representation format.
55
+
56
+ Raises:
57
+ - ValueError if GTID format is incorrect
55
58
"""
56
59
m = re .search ('^([0-9]+)(?:-([0-9]+))?$' , interval )
57
60
if not m :
@@ -62,6 +65,11 @@ def parse_interval(interval):
62
65
63
66
@staticmethod
64
67
def parse (gtid ):
68
+ """Parse a GTID from mysql textual format.
69
+
70
+ Raises:
71
+ - ValueError: if GTID format is incorrect.
72
+ """
65
73
m = re .search ('^([0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12})'
66
74
'((?::[0-9-]+)+)$' , gtid )
67
75
if not m :
@@ -79,6 +87,9 @@ def __add_interval(self, itvl):
79
87
"""
80
88
Use the internal representation format and add it
81
89
to our intervals, merging if required.
90
+
91
+ Raises:
92
+ Exception: if Malformated interval or Overlapping interval
82
93
"""
83
94
new = []
84
95
@@ -103,7 +114,9 @@ def __add_interval(self, itvl):
103
114
self .intervals = sorted (new + [itvl ])
104
115
105
116
def __sub_interval (self , itvl ):
106
- """Using the internal representation, remove an interval"""
117
+ """Using the internal representation, remove an interval
118
+
119
+ Raises: Exception if itvl malformated"""
107
120
new = []
108
121
109
122
if itvl [0 ] > itvl [1 ]:
@@ -144,8 +157,10 @@ def __init__(self, gtid, sid=None, intervals=[]):
144
157
self .__add_interval (itvl )
145
158
146
159
def __add__ (self , other ):
147
- """Include the transactions of this gtid. Raise if the
148
- attempted merge has different SID"""
160
+ """Include the transactions of this gtid.
161
+
162
+ Raises:
163
+ Exception: if the attempted merge has different SID"""
149
164
if self .sid != other .sid :
150
165
raise Exception ('Attempt to merge different SID'
151
166
'%s != %s' % (self .sid , other .sid ))
@@ -262,7 +277,23 @@ def __ge__(self, other):
262
277
263
278
264
279
class GtidSet (object ):
280
+ """Represents a set of Gtid"""
265
281
def __init__ (self , gtid_set ):
282
+ """
283
+ Construct a GtidSet initial state depends of the nature of `gtid_set` param.
284
+
285
+ params:
286
+ - gtid_set:
287
+ - None: then the GtidSet start empty
288
+ - a set of Gtid either as a their textual representation separated by comma
289
+ - A set or list of gtid
290
+ - A GTID alone.
291
+
292
+ Raises:
293
+ - ValueError: if `gtid_set` is a string separated with comma, but with malformated Gtid.
294
+ - Exception: if Gtid interval are either malformated or overlapping
295
+ """
296
+
266
297
def _to_gtid (element ):
267
298
if isinstance (element , Gtid ):
268
299
return element
@@ -287,13 +318,25 @@ def merge_gtid(self, gtid):
287
318
self .gtids = new_gtids
288
319
289
320
def __contains__ (self , other ):
321
+ """
322
+ Raises:
323
+ - NotImplementedError other is not a GtidSet neither a Gtid,
324
+ please convert it first to one of them
325
+ """
290
326
if isinstance (other , GtidSet ):
291
327
return all (other_gtid in self .gtids for other_gtid in other .gtids )
292
328
if isinstance (other , Gtid ):
293
329
return any (other in x for x in self .gtids )
294
330
raise NotImplementedError
295
331
296
332
def __add__ (self , other ):
333
+ """
334
+ Merge current instance with an other GtidSet or with a Gtid alone.
335
+
336
+ Raises:
337
+ - NotImplementedError other is not a GtidSet neither a Gtid,
338
+ please convert it first to one of them
339
+ """
297
340
if isinstance (other , Gtid ):
298
341
new = GtidSet (self .gtids )
299
342
new .merge_gtid (other )
@@ -308,6 +351,9 @@ def __add__(self, other):
308
351
raise NotImplementedError
309
352
310
353
def __str__ (self ):
354
+ """
355
+ Returns a comma separated string of gtids.
356
+ """
311
357
return ',' .join (str (x ) for x in self .gtids )
312
358
313
359
def __repr__ (self ):
0 commit comments