PEP 8 fixes

Minor tweaks bringing to address PEP 8 style issues.
This commit is contained in:
Jamie Finnigan 2014-09-15 14:37:42 -07:00
parent 1afb6f8acb
commit ee6d75dc95
5 changed files with 18 additions and 15 deletions

View File

@ -221,4 +221,4 @@ class Context():
for imp in self._context['imports']:
if module in imp:
return True
return False
return False

View File

@ -123,7 +123,7 @@ class BanditTestSet():
# tests are a dictionary of functions, grouped by check type
# where the key is the function name, and the value is the
# function itself.
# eg. tests[check_type][function_name] = function
# eg. tests[check_type][fn_name] = function
self.tests = dict()
directory = self.config.get_setting('plugins_dir')
@ -155,15 +155,15 @@ class BanditTestSet():
# for every function in the module, add to the dictionary
# unless it's one of our decorators, then ignore it
function_name = cur_func[0]
if function_name not in decorators:
fn_name = cur_func[0]
if fn_name not in decorators:
try:
function = getattr(module, function_name)
function = getattr(module, fn_name)
except AttributeError as e:
self.logger.error(
"could not locate test function '%s' in "
"module '%s.%s'" %
(function_name, directory, module_name)
(fn_name, directory, module_name)
)
sys.exit(2)
else:
@ -174,13 +174,14 @@ class BanditTestSet():
if check not in self.tests:
self.tests[check] = {}
# if there is a test name collision, bail
if function_name in self.tests[check]:
self.logger.error("Duplicate function "
"definition %s in %s",
function_name, file)
if fn_name in self.tests[check]:
self.logger.error(
"Duplicate function definition "
"%s in %s", fn_name, file
)
sys.exit(2)
else:
self.tests[check][function_name] = function
self.tests[check][fn_name] = function
self._filter_tests(filter)

View File

@ -59,18 +59,17 @@ def blacklist_imports(context, config):
return level, "%s" % message
def _get_tuple_for_item(blacklist_object):
# default values
imports = None
message = ""
level = 'WARN'
# if the item we got passed isn't a dictionary, do nothing with this object;
# if the item we got passed doesn't have an import field, or the import item
# if the item we got passed isn't a dictionary, do nothing with the object;
# if the item we got passed doesn't have an import field, or the import
# isn't a string, we can't do anything with this. Return None
if(not isinstance(blacklist_object, dict)
or not 'import' in blacklist_object
or 'import' not in blacklist_object
or not type(blacklist_object['import']) == str):
return None

View File

@ -17,6 +17,7 @@
import bandit
from bandit.test_selector import *
@checks_functions
def random_lib_calls(context):
# Alerts on any usage of any random library function
@ -29,6 +30,7 @@ def random_lib_calls(context):
return(bandit.INFO, 'Use of random is not suitable for security/'
'cryptographic purposes.')
@checks_imports
def random_lib_imports(context):
# Alerts on importing the 'random' library

View File

@ -29,6 +29,7 @@ def subprocess_popen_with_shell_equals_true(context):
'identified, security issue. %s' %
context.call_args_string)
@checks_functions
def any_other_function_with_shell_equals_true(context):
# Alerts on any function call that includes a shell=True parameter