-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added retry decorator; Bumped version
- Loading branch information
1 parent
2bca310
commit 4733930
Showing
4 changed files
with
59 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "snek-sploit" | ||
version = "0.5.0" | ||
version = "0.6.0" | ||
description = "Python RPC client for Metasploit Framework" | ||
authors = [ | ||
"Jiří Rája <[email protected]>" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from functools import wraps, partial | ||
|
||
|
||
def retry(func=None, *, tries: int = 1, on_errors: tuple = None): | ||
""" | ||
Retry a function if an error occurs. | ||
:param func: Original function | ||
:param tries: Number of times to retry | ||
:param on_errors: On what errors to retry | ||
:return: Wrapper | ||
""" | ||
if func is None: | ||
return partial(retry, tries=tries, on_errors=on_errors) | ||
|
||
if not on_errors: | ||
on_errors = (Exception,) | ||
|
||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
for i in range(tries + 1): | ||
try: | ||
return func(*args, **kwargs) | ||
except on_errors as ex: | ||
if i == tries: | ||
raise ex | ||
|
||
return wrapper |