Skip to content

Commit e8d0016

Browse files
author
Guillaume Valadon
committed
W504 - line break after binary operator
1 parent 0965733 commit e8d0016

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+414
-461
lines changed

scapy/arch/bpf/core.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ def get_if_raw_hwaddr(ifname):
7070
raise Scapy_Exception("Failed to execute ifconfig: (%s)" % msg)
7171

7272
# Get MAC addresses
73-
addresses = [l for l in fd.readlines() if l.find("ether") >= 0 or
74-
l.find("lladdr") >= 0 or
75-
l.find("address") >= 0]
73+
addresses = [l for l in fd.readlines()
74+
if "ether" in l or "lladdr" in l or "address" in l]
7675
if not addresses:
7776
raise Scapy_Exception("No MAC address found on %s !" % ifname)
7877

scapy/arch/windows/__init__.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,13 @@ def _check_npcap_requirement(self):
634634
if not conf.use_npcap:
635635
raise OSError("This operation requires Npcap.")
636636
if self.raw80211 is None:
637-
# This checks if npcap has Dot11 enabled and if the interface is compatible, # noqa: E501
638-
# by looking for the npcap/Parameters/Dot11Adapters key in the registry. # noqa: E501
637+
# This checks if npcap has Dot11 enabled and if the interface is
638+
# compatible, by looking for the npcap/Parameters/Dot11Adapters
639+
# key in the registry.
639640
dot11adapters = _get_npcap_dot11_adapters()
640-
self.raw80211 = (dot11adapters is not None and
641-
(("\\Device\\" + self.guid).lower() in dot11adapters.lower())) # noqa: E501
641+
self.raw80211 = dot11adapters is not None
642+
tmp_adapter = ("\\Device\\" + self.guid).lower()
643+
self.raw80211 &= tmp_adapter in dot11adapters.lower()
642644
if not self.raw80211:
643645
raise Scapy_Exception("This interface does not support raw 802.11")
644646

@@ -868,10 +870,11 @@ def _ask_user():
868870
self.load_from_powershell()
869871
return
870872
_error_msg = "Could not start the pcap service ! "
871-
warning(_error_msg +
872-
"You probably won't be able to send packets. "
873-
"Deactivating unneeded interfaces and restarting Scapy might help. " # noqa: E501
874-
"Check your winpcap and powershell installation, and access rights.") # noqa: E501
873+
_error_msg += "You probably won't be able to send packets. "
874+
_error_msg += "Deactivating unneeded interfaces and restarting "
875+
_error_msg += "Scapy might help. Check your winpcap and "
876+
_error_msg += "powershell installation, and access rights."
877+
warning(_error_msg)
875878
else:
876879
# Loading state: remove invalid interfaces
877880
self.remove_invalid_ifaces()

scapy/asn1/asn1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ def __setattr__(self, name, value):
454454
_len = 13
455455
_format = "%y%m%d%H%M%S"
456456
_nam = self.tag._asn1_obj.__name__[4:].lower()
457-
if (isinstance(value, str) and
458-
len(value) == _len and value[-1] == "Z"):
457+
if isinstance(value, str) and \
458+
len(value) == _len and value[-1] == "Z":
459459
dt = datetime.strptime(value[:-1], _format)
460460
pretty_time = dt.strftime("%b %d %H:%M:%S %Y GMT")
461461
else:

scapy/asn1fields.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ def i2m(self, pkt, x):
104104
if x is None:
105105
return b""
106106
if isinstance(x, ASN1_Object):
107-
if (self.ASN1_tag == ASN1_Class_UNIVERSAL.ANY or
108-
x.tag == ASN1_Class_UNIVERSAL.RAW or
109-
x.tag == ASN1_Class_UNIVERSAL.ERROR or
110-
self.ASN1_tag == x.tag):
107+
if self.ASN1_tag == ASN1_Class_UNIVERSAL.ANY or \
108+
x.tag == ASN1_Class_UNIVERSAL.RAW or \
109+
x.tag == ASN1_Class_UNIVERSAL.ERROR or \
110+
self.ASN1_tag == x.tag:
111111
s = x.enc(pkt.ASN1_codec)
112112
else:
113113
raise ASN1_Error("Encoding Error: got %r instead of an %r for field [%s]" % (x, self.ASN1_tag, self.name)) # noqa: E501

scapy/automaton.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,10 @@ def graph(self, **kargs):
512512
if n in self.states:
513513
s += '\t"%s" -> "%s" [ color=green ];\n' % (st.atmt_state, n) # noqa: E501
514514

515-
for c, k, v in ([("purple", k, v) for k, v in self.conditions.items()] + # noqa: E501
516-
[("red", k, v) for k, v in self.recv_conditions.items()] + # noqa: E501
517-
[("orange", k, v) for k, v in self.ioevents.items()]):
515+
purple_list = [("purple", k, v) for k, v in self.conditions.items()]
516+
red_list = [("red", k, v) for k, v in self.recv_conditions.items()]
517+
orange_list = [("orange", k, v) for k, v in self.ioevents.items()]
518+
for c, k, v in (purple_list + red_list + orange_list):
518519
for f in v:
519520
for n in f.__code__.co_names + f.__code__.co_consts:
520521
if n in self.states:
@@ -842,9 +843,9 @@ def _do_iter(self):
842843
self._run_condition(cond, *state_output)
843844

844845
# If still there and no conditions left, we are stuck!
845-
if (len(self.recv_conditions[self.state.state]) == 0 and
846-
len(self.ioevents[self.state.state]) == 0 and
847-
len(self.timeout[self.state.state]) == 1):
846+
if len(self.recv_conditions[self.state.state]) == 0 and \
847+
len(self.ioevents[self.state.state]) == 0 and \
848+
len(self.timeout[self.state.state]) == 1:
848849
raise self.Stuck("stuck in [%s]" % self.state.state,
849850
state=self.state.state, result=state_output) # noqa: E501
850851

scapy/base_classes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ def _get_values(value):
4141
return value.
4242
4343
"""
44-
if (isinstance(value, tuple) and (2 <= len(value) <= 3) and
45-
all(hasattr(i, "__int__") for i in value)):
44+
if isinstance(value, tuple) and (2 <= len(value) <= 3) and \
45+
all(hasattr(i, "__int__") for i in value):
4646
# We use values[1] + 1 as stop value for (x)range to maintain
4747
# the behavior of using tuples as field `values`
48-
return range(*((int(value[0]), int(value[1]) + 1) +
49-
tuple(int(v) for v in value[2:])))
48+
tmp_tuples = tuple(int(v) for v in value[2:])
49+
return range(*((int(value[0]), int(value[1]) + 1) + tmp_tuples))
5050
return value
5151

5252

@@ -63,7 +63,7 @@ def transf(self, element):
6363

6464
def __iter__(self):
6565
for i in self.values:
66-
if (isinstance(i, Gen) and
66+
if (isinstance(i, Gen) and # noqa: W504
6767
(self._iterpacket or not isinstance(i, BasePacket))) or (
6868
isinstance(i, (range, types.GeneratorType))):
6969
for j in i:

scapy/contrib/automotive/gm/gmlan.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ def determine_len(x):
8686
def answers(self, other):
8787
"""DEV: true if self is an answer from other"""
8888
if other.__class__ == self.__class__:
89-
return (other.service + 0x40) == self.service or \
90-
(self.service == 0x7f and
91-
(self.requestServiceId == other.service))
89+
test_1 = (other.service + 0x40) == self.service
90+
test_2 = self.service == 0x7f and \
91+
self.requestServiceId == other.service
92+
return test_1 or test_2
9293
return 0
9394

9495
def hashret(self):

scapy/contrib/automotive/someip_sd.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,18 @@ class SD(_SDPacketBase):
308308
def get_flag(self, name):
309309
name = name.upper()
310310
if (name in self.FLAGSDEF):
311-
return ((self.flags & self.FLAGSDEF[name].mask) >>
312-
self.FLAGSDEF[name].offset)
311+
masked_flags = self.flags & self.FLAGSDEF[name].mask
312+
return masked_flags >> self.FLAGSDEF[name].offset
313313
else:
314314
return None
315315

316316
def set_flag(self, name, value):
317317
name = name.upper()
318318
if (name in self.FLAGSDEF):
319-
self.flags = (self.flags &
320-
(ctypes.c_ubyte(~self.FLAGSDEF[name].mask).value)) \
321-
| ((value & 0x01) << self.FLAGSDEF[name].offset)
319+
tmp_value = ctypes.c_ubyte(~self.FLAGSDEF[name].mask).value
320+
masked_flags = self.flags & tmp_value
321+
shifted_value = (value & 0x01) << self.FLAGSDEF[name].offset
322+
self.flags = masked_flags | shifted_value
322323

323324
def set_entryArray(self, entry_list):
324325
if (isinstance(entry_list, list)):

scapy/contrib/automotive/uds.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ class UDS(Packet):
7878
def answers(self, other):
7979
"""DEV: true if self is an answer from other"""
8080
if other.__class__ == self.__class__:
81-
return (other.service + 0x40) == self.service or \
82-
(self.service == 0x7f and
83-
self.requestServiceId == other.service)
81+
test_1 = (other.service + 0x40) == self.service
82+
test_2 = self.service == 0x7f and \
83+
self.requestServiceId == other.service
84+
return test_1 or test_2
8485
return 0
8586

8687
def hashret(self):

scapy/contrib/bgp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ class BGPPathAttr(Packet):
20342034
ByteEnumField("type_code", 0, path_attributes),
20352035
ConditionalField(
20362036
ShortField("attr_ext_len", None),
2037-
lambda x: x.type_flags is not None and
2037+
lambda x: x.type_flags is not None and # noqa: W504
20382038
has_extended_length(x.type_flags)
20392039
),
20402040
ConditionalField(

0 commit comments

Comments
 (0)