MCPcopy Create free account
hub / github.com/rthalley/dnspython / Serial

Class Serial

dns/serial.py:6–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4
5
6class Serial:
7 def __init__(self, value: int, bits: int = 32):
8 self.value = value % 2**bits
9 self.bits = bits
10
11 def __repr__(self):
12 return f"dns.serial.Serial({self.value}, {self.bits})"
13
14 def __eq__(self, other):
15 if isinstance(other, int):
16 other = Serial(other, self.bits)
17 elif not isinstance(other, Serial) or other.bits != self.bits:
18 return NotImplemented
19 return self.value == other.value
20
21 def __ne__(self, other):
22 if isinstance(other, int):
23 other = Serial(other, self.bits)
24 elif not isinstance(other, Serial) or other.bits != self.bits:
25 return NotImplemented
26 return self.value != other.value
27
28 def __lt__(self, other):
29 if isinstance(other, int):
30 other = Serial(other, self.bits)
31 elif not isinstance(other, Serial) or other.bits != self.bits:
32 return NotImplemented
33 if self.value < other.value and other.value - self.value < 2 ** (self.bits - 1):
34 return True
35 elif self.value > other.value and self.value - other.value > 2 ** (
36 self.bits - 1
37 ):
38 return True
39 else:
40 return False
41
42 def __le__(self, other):
43 return self == other or self < other
44
45 def __gt__(self, other):
46 if isinstance(other, int):
47 other = Serial(other, self.bits)
48 elif not isinstance(other, Serial) or other.bits != self.bits:
49 return NotImplemented
50 if self.value < other.value and other.value - self.value > 2 ** (self.bits - 1):
51 return True
52 elif self.value > other.value and self.value - other.value < 2 ** (
53 self.bits - 1
54 ):
55 return True
56 else:
57 return False
58
59 def __ge__(self, other):
60 return self == other or self > other
61
62 def __add__(self, other):
63 v = self.value

Callers 6

__eq__Method · 0.85
__ne__Method · 0.85
__lt__Method · 0.85
__gt__Method · 0.85
__add__Method · 0.85
__sub__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…