Skip to content

Commit 8787a2f

Browse files
committed
optimized the sort_loops in module.py and also improved readability
1 parent ad76ce5 commit 8787a2f

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

nettacker/core/module.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,21 @@ def generate_loops(self):
118118
self.module_content["payloads"] = expand_module_steps(self.module_content["payloads"])
119119

120120
def sort_loops(self):
121-
steps = []
122121
for index in range(len(self.module_content["payloads"])):
123-
for step in copy.deepcopy(self.module_content["payloads"][index]["steps"]):
124-
if "dependent_on_temp_event" not in step[0]["response"]:
125-
steps.append(step)
122+
no_dep = []
123+
dep_temp_only = []
124+
dep_normal = []
126125

127126
for step in copy.deepcopy(self.module_content["payloads"][index]["steps"]):
128-
if (
129-
"dependent_on_temp_event" in step[0]["response"]
130-
and "save_to_temp_events_only" in step[0]["response"]
131-
):
132-
steps.append(step)
127+
resp = step[0]["response"]
128+
if "dependent_on_temp_event" not in resp:
129+
no_dep.append(step)
130+
elif "save_to_temp_events_only" in resp:
131+
dep_temp_only.append(step)
132+
else:
133+
dep_normal.append(step)
133134

134-
for step in copy.deepcopy(self.module_content["payloads"][index]["steps"]):
135-
if (
136-
"dependent_on_temp_event" in step[0]["response"]
137-
and "save_to_temp_events_only" not in step[0]["response"]
138-
):
139-
steps.append(step)
140-
self.module_content["payloads"][index]["steps"] = steps
135+
self.module_content["payloads"][index]["steps"] = no_dep + dep_temp_only + dep_normal
141136

142137
def start(self):
143138
active_threads = []

0 commit comments

Comments
 (0)