@@ -42,16 +42,19 @@ class Gtid(object):
4242
4343 SID:1-74
4444
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.
4949 """
5050 @staticmethod
5151 def parse_interval (interval ):
5252 """
5353 We parse a human-generated string here. So our end value b
5454 is incremented to conform to the internal representation format.
55+
56+ Raises:
57+ - ValueError if GTID format is incorrect
5558 """
5659 m = re .search ('^([0-9]+)(?:-([0-9]+))?$' , interval )
5760 if not m :
@@ -62,6 +65,11 @@ def parse_interval(interval):
6265
6366 @staticmethod
6467 def parse (gtid ):
68+ """Parse a GTID from mysql textual format.
69+
70+ Raises:
71+ - ValueError: if GTID format is incorrect.
72+ """
6573 m = re .search ('^([0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12})'
6674 '((?::[0-9-]+)+)$' , gtid )
6775 if not m :
@@ -79,6 +87,9 @@ def __add_interval(self, itvl):
7987 """
8088 Use the internal representation format and add it
8189 to our intervals, merging if required.
90+
91+ Raises:
92+ Exception: if Malformated interval or Overlapping interval
8293 """
8394 new = []
8495
@@ -103,7 +114,9 @@ def __add_interval(self, itvl):
103114 self .intervals = sorted (new + [itvl ])
104115
105116 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"""
107120 new = []
108121
109122 if itvl [0 ] > itvl [1 ]:
@@ -144,8 +157,10 @@ def __init__(self, gtid, sid=None, intervals=[]):
144157 self .__add_interval (itvl )
145158
146159 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"""
149164 if self .sid != other .sid :
150165 raise Exception ('Attempt to merge different SID'
151166 '%s != %s' % (self .sid , other .sid ))
@@ -262,7 +277,23 @@ def __ge__(self, other):
262277
263278
264279class GtidSet (object ):
280+ """Represents a set of Gtid"""
265281 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+
266297 def _to_gtid (element ):
267298 if isinstance (element , Gtid ):
268299 return element
@@ -287,13 +318,25 @@ def merge_gtid(self, gtid):
287318 self .gtids = new_gtids
288319
289320 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+ """
290326 if isinstance (other , GtidSet ):
291327 return all (other_gtid in self .gtids for other_gtid in other .gtids )
292328 if isinstance (other , Gtid ):
293329 return any (other in x for x in self .gtids )
294330 raise NotImplementedError
295331
296332 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+ """
297340 if isinstance (other , Gtid ):
298341 new = GtidSet (self .gtids )
299342 new .merge_gtid (other )
@@ -308,6 +351,9 @@ def __add__(self, other):
308351 raise NotImplementedError
309352
310353 def __str__ (self ):
354+ """
355+ Returns a comma separated string of gtids.
356+ """
311357 return ',' .join (str (x ) for x in self .gtids )
312358
313359 def __repr__ (self ):
0 commit comments