Skip to content

Instantly share code, notes, and snippets.

@Daviey

Daviey/- Secret

Created August 6, 2015 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daviey/6f61e86cc19e6e51ff95 to your computer and use it in GitHub Desktop.
Save Daviey/6f61e86cc19e6e51ff95 to your computer and use it in GitHub Desktop.
diff --git a/bandit/bandit.py b/bandit/bandit.py
index 1f4fdbd..c27b75a 100644
--- a/bandit/bandit.py
+++ b/bandit/bandit.py
@@ -47,7 +47,7 @@ def _init_logger(debug=False, log_format=None):
log_format_string = log_format
logging.captureWarnings(True)
- warnings.formatwarning = _warning
+ warnings.formatwarning = utils.warnings_formatter
logger = logging.getLogger()
logger.setLevel(log_level)
@@ -85,15 +85,6 @@ def _find_config():
raise utils.NoConfigFileFound(config_locations)
-def _warning(message,
- category=UserWarning,
- filename='',
- lineno=-1,
- line=''):
- '''Monkey patch for warnings.warn to suppress cruft output.'''
- return "{0}\n".format(message)
-
-
def main():
# bring our logging stuff up as early as possible
debug = ('-d' in sys.argv or '--debug' in sys.argv)
diff --git a/bandit/core/tester.py b/bandit/core/tester.py
index 91c00b4..78ebd4e 100644
--- a/bandit/core/tester.py
+++ b/bandit/core/tester.py
@@ -21,10 +21,12 @@ import six
from bandit.core import constants
from bandit.core import context as b_context
+from bandit.core import utils
class BanditTester():
+ warnings.formatwarning = utils.warnings_formatter
results = None
def __init__(self, logger, config, results, testset, debug):
diff --git a/bandit/core/utils.py b/bandit/core/utils.py
index e64a762..3077850 100644
--- a/bandit/core/utils.py
+++ b/bandit/core/utils.py
@@ -188,6 +188,15 @@ class NoConfigFileFound(Exception):
super(NoConfigFileFound, self).__init__(message)
+def warnings_formatter(message,
+ category=UserWarning,
+ filename='',
+ lineno=-1,
+ line=''):
+ '''Monkey patch for warnings.warn to suppress cruft output.'''
+ return "{0}\n".format(message)
+
+
def get_module_qualname_from_path(path):
'''Get the module's qualified name by analysis of the path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment