Skip to content

Commit a534625

Browse files
committed
Fix flake8 issues for Scapy PR
1 parent e54e869 commit a534625

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

scapy/contrib/knx.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from scapy.packet import Packet, bind_layers, bind_bottom_up, Padding
3232
from scapy.layers.inet import UDP
3333

34-
### KNX CODES
34+
# KNX CODES
3535

3636
# KNX Standard v2.1 - 03_08_02 p20
3737
SERVICE_IDENTIFIER_CODES = {
@@ -161,7 +161,7 @@
161161
}
162162

163163

164-
### KNX SPECIFIC FIELDS
164+
# KNX SPECIFIC FIELDS
165165

166166
# KNX Standard v2.1 - 03_05_01 p.17
167167
class KNXAddressField(ShortField):
@@ -171,30 +171,27 @@ def i2repr(self, _, x):
171171
return "%d.%d.%d" % ((x >> 12) & 0xf, (x >> 8) & 0xf, (x & 0xff))
172172

173173
def any2i(self, pkt, x):
174+
# Raises ValueError in x does not have format a/b/c
174175
if type(x) is str:
175-
try:
176-
a, b, c = map(int, x.split("."))
177-
x = (a << 12) | (b << 8) | c
178-
except:
179-
raise ValueError(x)
176+
a, b, c = map(int, x.split("."))
177+
x = (a << 12) | (b << 8) | c
180178
return ShortField.any2i(self, pkt, x)
181179

180+
182181
# KNX Standard v2.1 - 03_05_01 p.18
183182
class KNXGroupField(ShortField):
184183
def i2repr(self, _, x):
185184
return "%d/%d/%d" % ((x >> 11) & 0x1f, (x >> 8) & 0x7, (x & 0xff))
186185

187186
def any2i(self, pkt, x):
187+
# Raises ValueError in x does not have format a/b/c
188188
if type(x) is str:
189-
try:
190-
a, b, c = map(int, x.split("/"))
191-
x = (a << 11) | (b << 8) | c
192-
except:
193-
raise ValueError(x)
189+
a, b, c = map(int, x.split("/"))
190+
x = (a << 11) | (b << 8) | c
194191
return ShortField.any2i(self, pkt, x)
195192

196193

197-
### KNX PLACEHOLDERS
194+
# KNX PLACEHOLDERS
198195

199196
# KNX Standard v2.1 - 03_08_02 p21
200197
class HPAI(Packet):
@@ -251,7 +248,7 @@ class DIBSuppSvcFamilies(Packet):
251248
ConditionalField(
252249
PacketListField("service_family", ServiceFamily(), ServiceFamily,
253250
length_from=lambda
254-
pkt: pkt.structure_length - 0x02),
251+
pkt: pkt.structure_length - 0x02),
255252
lambda pkt: pkt.structure_length > 0x02)
256253
]
257254

@@ -347,7 +344,7 @@ class LcEMI(Packet):
347344
lambda pkt: pkt.address_type == 0)
348345
],
349346
ShortField("destination_address", "")
350-
),
347+
),
351348
FieldLenField("npdu_length", 0x01, fmt="B", length_of="data"),
352349
# TPCI and APCI (2 byte made of 1+1+4+4+6 bits)
353350
BitEnumField("packet_type", 0, 1, {
@@ -357,7 +354,7 @@ class LcEMI(Packet):
357354
BitEnumField("sequence_type", 0, 1, {
358355
0: "unnumbered"
359356
}),
360-
BitField("sequence_number", 0, 4), # Not used when sequence_type = unnumbered
357+
BitField("sequence_number", 0, 4), # Not used when sequence_type = unnumbered
361358
ConditionalField(BitEnumField("acpi", 2, 4, KNX_ACPI_CODES),
362359
lambda pkt: pkt.packet_type == 0),
363360
ConditionalField(BitEnumField("service", 0, 2, KNX_SERVICE_CODES),
@@ -403,7 +400,7 @@ class CEMI(Packet):
403400
]
404401

405402

406-
### KNX SERVICES
403+
# KNX SERVICES
407404

408405
# KNX Standard v2.1 - 03_08_02 p28
409406
class KNXSearchRequest(Packet):
@@ -565,6 +562,7 @@ def post_build(self, p, pay):
565562
p = (len(p)).to_bytes(1, byteorder='big') + p[1:]
566563
return p + pay
567564

565+
568566
class KNXRoutingIndication(Packet):
569567
name = "ROUTING_INDICATION"
570568
fields_desc = [
@@ -576,7 +574,7 @@ def post_build(self, p, pay):
576574
return p + pay
577575

578576

579-
### KNX FRAME
577+
# KNX FRAME
580578

581579
# we made the choice to define a KNX service as a payload for a KNX Header
582580
# it could also be possible to define the body as a conditionnal PacketField
@@ -599,7 +597,7 @@ def post_build(self, p, pay):
599597
return p + pay
600598

601599

602-
### LAYERS BINDING
600+
# LAYERS BINDING
603601

604602
bind_bottom_up(UDP, KNX, dport=3671)
605603
bind_bottom_up(UDP, KNX, sport=3671)
@@ -626,7 +624,7 @@ def post_build(self, p, pay):
626624
# we could also define a new Packet class with no payload and inherit
627625
# every KNX packet from it :
628626
#
629-
#class _KNXBodyNoPayload(Packet):
627+
# class _KNXBodyNoPayload(Packet):
630628
#
631629
# def extract_padding(self, s):
632630
# return b"", None

0 commit comments

Comments
 (0)