Skip to content

Commit 74046df

Browse files
committed
Refactor code for flake8 compliance
1 parent fb2bb6b commit 74046df

1 file changed

Lines changed: 49 additions & 42 deletions

File tree

scapy/contrib/rsvp.py

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class RSVP(Packet):
3030
The header is followed by this message's RSVP objects, which in turn
3131
chains to further RSVP_Object instances (each object's data class returns
3232
RSVP_Object from default_payload_class), forming the sequence of RSVP objects.
33-
33+
3434
It contains the following fields:
3535
- Version: 4 bits, RSVP protocol version
3636
- Flags: 4 bits, RSVP message flags
@@ -154,7 +154,8 @@ class RSVP_Object(Packet):
154154
Dissection naturally chains into the next object if more bytes remain.
155155
156156
It contains the following fields:
157-
- Length: 16 bits, total length of this object including this header, computed if None.
157+
- Length: 16 bits, total length of this object including this header,
158+
computed if None.
158159
- Class: 8 bits, RSVP object type
159160
- C_Type: 8 bits, RSVP object subtype
160161
"""
@@ -165,8 +166,8 @@ class RSVP_Object(Packet):
165166

166167
def guess_payload_class(self, payload):
167168
"""Pick the data class to dissect based on Class.
168-
169-
Falls back to RSVP_data, a generic container for any Class value
169+
170+
Falls back to RSVP_data, a generic container for any Class value
170171
that doesnt have a dedicated class yet.
171172
"""
172173
if self.Class == 0x01:
@@ -187,25 +188,26 @@ def guess_payload_class(self, payload):
187188

188189

189190
class RSVP_Data(Packet):
190-
"""Defines a generic/unknown RSVP object data structure for any Class value
191+
"""Defines a generic/unknown RSVP object data structure for any Class value
191192
that doesnt have a dedicated class implemented yet.
192-
193-
- overload_fields: Writes Class=0x01 back into the underlayer
193+
194+
- overload_fields: Writes Class=0x01 back into the underlayer
194195
RSVP_Object ONLY when this class is used to explicitly BUILD a packet
195-
(e.g. RSVP_Object()/RSVP_Data(...)) without the caller setting Class themselves.
196+
(e.g. RSVP_Object()/RSVP_Data(...)) without the caller setting Class themselves.
196197
(Note that this is just a pre-existing default Class value).
197-
198-
- Data: raw bytes, whatever remains of this object after the 4-byte RSVP_Object header.
198+
199+
- Data: raw bytes, whatever remains of this object
200+
after the 4-byte RSVP_Object header.
199201
"""
200202
name = "Data"
201203
overload_fields = {RSVP_Object: {"Class": 0x01}}
202204
fields_desc = [
203205
StrLenField(
204206
"Data",
205207
"",
206-
length_from=lambda pkt:pkt.underlayer.Length - 4
208+
length_from=lambda pkt: pkt.underlayer.Length - 4
207209
),
208-
]
210+
]
209211

210212
def default_payload_class(self, payload):
211213
"""Get the default payload class.
@@ -230,7 +232,7 @@ class RSVP_SESSION(Packet):
230232
ShortField("reserved", 0),
231233
ShortField("tunnel_id", 0),
232234
IPField("ext_tunnel_id", "0.0.0.0")]
233-
235+
234236
def default_payload_class(self, payload):
235237
"""Get the default payload class.
236238
Chains to another RSVP_Object if more bytes remain.
@@ -241,11 +243,12 @@ def default_payload_class(self, payload):
241243
class RSVP_HOP(Packet):
242244
"""RSVP_HOP object data structure, RFC 2205 section A.2.
243245
244-
Identifies the IP address and the Logical Interface Handle (LIH)
245-
of the interface this message was sent from.
246-
246+
Identifies the IP address and the Logical Interface Handle (LIH)
247+
of the interface this message was sent from.
248+
247249
- neighbor: 32 bits, IP address of the interface this message was sent from.
248-
- inface: 32 bits, Logical Interface Handle (LIH) of the interface this message was sent from.
250+
- inface: 32 bits, Logical Interface Handle (LIH)
251+
of the interface this message was sent from.
249252
"""
250253
name = "HOP"
251254
overload_fields = {RSVP_Object: {"Class": 0x03}}
@@ -262,7 +265,8 @@ def default_payload_class(self, payload):
262265
class RSVP_Time(Packet):
263266
"""TIME_VALUES object RFC 2205 section A.4.
264267
Carries the refresh period a sender will use to resend PATH/RESV messages,
265-
which the receiver can use to determine when to tear down the reservation if no further messages are received.
268+
which the receiver can use to determine when to tear down
269+
the reservation if no further messages are received.
266270
267271
- refresh: 32 bits, refresh period in milliseconds.
268272
"""
@@ -293,18 +297,19 @@ class RSVP_SenderTSPEC(Packet):
293297
"""
294298
name = "Sender_TSPEC"
295299
overload_fields = {RSVP_Object: {"Class": 0x0c}}
296-
fields_desc = [ByteField("Msg_Format", 0),
297-
ByteField("reserve", 0),
298-
ShortField("Data_Length", 4),
299-
ByteField("Srv_hdr", 1),
300-
ByteField("reserve2", 0),
301-
ShortField("Srv_Length", 4),
302-
StrLenField(
303-
"Tokens",
304-
"",
305-
length_from=lambda pkt:pkt.underlayer.Length - 12
306-
),
307-
]
300+
fields_desc = [
301+
ByteField("Msg_Format", 0),
302+
ByteField("reserve", 0),
303+
ShortField("Data_Length", 4),
304+
ByteField("Srv_hdr", 1),
305+
ByteField("reserve2", 0),
306+
ShortField("Srv_Length", 4),
307+
StrLenField(
308+
"Tokens",
309+
"",
310+
length_from=lambda pkt: pkt.underlayer.Length - 12
311+
),
312+
]
308313

309314
def default_payload_class(self, payload):
310315
"""Get the default payload class.
@@ -338,7 +343,7 @@ def default_payload_class(self, payload):
338343
class RSVP_SessionAttrb(Packet):
339344
"""SESSION_ATTRIBUTE object RFC 3209 section 4.7.
340345
341-
Carries session data, mainly used for setup/recovery
346+
Carries session data, mainly used for setup/recovery
342347
priority and human readable session name.
343348
344349
- Setup_priority: 8 bits, setup priority for this session(can cause preemption).
@@ -349,16 +354,17 @@ class RSVP_SessionAttrb(Packet):
349354
"""
350355
name = "Session_Attribute"
351356
overload_fields = {RSVP_Object: {"Class": 0xCF}}
352-
fields_desc = [ByteField("Setup_priority", 1),
353-
ByteField("Hold_priority", 1),
354-
ByteField("flags", 1),
355-
FieldLenField("Name_length", None, length_of="Name"),
356-
StrLenField(
357-
"Name",
358-
"",
359-
length_from=lambda pkt:pkt.Name_length
360-
),
361-
]
357+
fields_desc = [
358+
ByteField("Setup_priority", 1),
359+
ByteField("Hold_priority", 1),
360+
ByteField("flags", 1),
361+
FieldLenField("Name_length", None, length_of="Name"),
362+
StrLenField(
363+
"Name",
364+
"",
365+
length_from=lambda pkt: pkt.Name_length
366+
),
367+
]
362368

363369
def default_payload_class(self, payload):
364370
"""Get the default payload class.
@@ -367,6 +373,7 @@ def default_payload_class(self, payload):
367373
return RSVP_Object
368374

369375

370-
# Decode IP packets with protocol number 46 as RSVP packets, and RSVP packets as RSVP_Object packets.
376+
# Decode IP packets with protocol number 46 as RSVP packets,
377+
# and RSVP packets as RSVP_Object packets.
371378
bind_layers(IP, RSVP, {"proto": 46})
372379
bind_layers(RSVP, RSVP_Object)

0 commit comments

Comments
 (0)