Skip to content

Commit

Permalink
Merge pull request threat9#62 from kamyarrasta/fix/openfile
Browse files Browse the repository at this point in the history
Open file using with block
  • Loading branch information
lucyoa committed Apr 29, 2016
2 parents 5e1b785 + 90691cb commit 9974c89
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions routersploit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,26 @@ def wrapper(self, *args, **kwargs):

_, _, feed_path = self.target.partition("file://")
try:
file_handler = open(feed_path, 'r')
with open(feed_path) as file_handler:
for target in file_handler:
target = target.strip()
if not target:
continue
self.target, _, port = target.partition(':')
if port:
self.port = port
else:
self.port = original_port
print_status("Attack against: {}:{}".format(self.target,
self.port))
fn(self, *args, **kwargs)
self.target = original_target
self.port = original_port
return # Nothing to return, ran multiple times.
except IOError:
print_error("Could not read file: {}".format(self.target))
return

for target in file_handler:
target = target.strip()
if not target:
continue
self.target, _, port = target.partition(':')
if port:
self.port = port
else:
self.port = original_port
print_status("Attack against: {}:{}".format(self.target, self.port))
fn(self, *args, **kwargs)
self.target = original_target
self.port = original_port
file_handler.close()
return # Nothing to return, ran multiple times.
else:
return fn(self, *args, **kwargs)
return wrapper
Expand Down

0 comments on commit 9974c89

Please sign in to comment.