Code Duplication    Length = 13-13 lines in 2 locations

v0x04/utils.py 1 location

@@ 141-153 (lines=13) @@
138
    return tobytes
139
140
141
def bytes_to_mask(tobytes, size):
142
    """Return the mask in string."""
143
    int_mask = int.from_bytes(tobytes, 'big')
144
    bits = bin(int_mask)
145
    strbits = str(bits)
146
    strbits = strbits[2:]
147
    netmask = 0
148
    for i in range(size):
149
        if strbits[i] == '1':
150
            netmask += 1
151
        else:
152
            break
153
    return netmask
154

v0x04/match_fields.py 1 location

@@ 25-37 (lines=13) @@
22
    return tobytes
23
24
25
def bytes_to_mask(tobytes, size):
26
    """Return the mask in string."""
27
    int_mask = int.from_bytes(tobytes, 'big')
28
    bits = bin(int_mask)
29
    strbits = str(bits)
30
    strbits = strbits[2:]
31
    netmask = 0
32
    for i in range(size):
33
        if strbits[i] == '1':
34
            netmask += 1
35
        else:
36
            break
37
    return netmask
38
39
40
class MatchField(ABC):