Replace six.iteritems() with .items()
1.As mentioned in [1], we should avoid using six.iteritems to achieve iterators. We can use dict.items instead, as it will return iterators in PY3 as well. And dict.items/keys will more readable. 2.In py2, the performance about list should be negligible, see the link [2]. [1] https://wiki.openstack.org/wiki/Python3 [2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html Change-Id: I5340fa3d71b6fba76e8fcf75f9f30432329023d2
This commit is contained in:
parent
ba5735c801
commit
693f57faae
|
@ -19,7 +19,6 @@ import logging
|
|||
import os
|
||||
import sys
|
||||
|
||||
import six
|
||||
import yaml
|
||||
|
||||
from bandit.core import extension_loader
|
||||
|
@ -158,8 +157,8 @@ def main():
|
|||
test_list = [tpl.format(t.plugin._test_id, t.name)
|
||||
for t in extension_loader.MANAGER.plugins]
|
||||
|
||||
others = [tpl.format(k, v['name']) for k, v in six.iteritems(
|
||||
extension_loader.MANAGER.blacklist_by_id)]
|
||||
others = [tpl.format(k, v['name']) for k, v in (
|
||||
extension_loader.MANAGER.blacklist_by_id.items())]
|
||||
test_list.extend(others)
|
||||
test_list.sort()
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ import logging
|
|||
import os
|
||||
import sys
|
||||
|
||||
import six
|
||||
|
||||
import bandit
|
||||
from bandit.core import config as b_config
|
||||
|
@ -247,9 +246,9 @@ def main():
|
|||
parser.set_defaults(ignore_nosec=False)
|
||||
|
||||
plugin_info = ["%s\t%s" % (a[0], a[1].name) for a in
|
||||
six.iteritems(extension_mgr.plugins_by_id)]
|
||||
extension_mgr.plugins_by_id.items()]
|
||||
blacklist_info = []
|
||||
for a in six.iteritems(extension_mgr.blacklist):
|
||||
for a in extension_mgr.blacklist.items():
|
||||
for b in a[1]:
|
||||
blacklist_info.append('%s\t%s' % (b['id'], b['name']))
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
import logging
|
||||
|
||||
import six
|
||||
import yaml
|
||||
|
||||
from bandit.core import constants
|
||||
|
@ -132,7 +131,7 @@ class BanditConfig(object):
|
|||
extman = extension_loader.MANAGER
|
||||
|
||||
updated_profiles = {}
|
||||
for name, profile in six.iteritems(self.get_option('profiles') or {}):
|
||||
for name, profile in (self.get_option('profiles') or {}).items():
|
||||
# NOTE(tkelsey): can't use default of get() because value is
|
||||
# sometimes explicity 'None', for example when the list if given in
|
||||
# yaml but not populated with any values.
|
||||
|
@ -151,7 +150,7 @@ class BanditConfig(object):
|
|||
bad_calls = self.get_option('blacklist_calls') or {}
|
||||
bad_calls = bad_calls.get('bad_name_sets', {})
|
||||
for item in bad_calls:
|
||||
for key, val in six.iteritems(item):
|
||||
for key, val in item.items():
|
||||
val['name'] = key
|
||||
val['message'] = val['message'].replace('{func}', '{name}')
|
||||
bad_calls_list.append(val)
|
||||
|
@ -159,7 +158,7 @@ class BanditConfig(object):
|
|||
bad_imports = self.get_option('blacklist_imports') or {}
|
||||
bad_imports = bad_imports.get('bad_import_sets', {})
|
||||
for item in bad_imports:
|
||||
for key, val in six.iteritems(item):
|
||||
for key, val in item.items():
|
||||
val['name'] = key
|
||||
val['message'] = val['message'].replace('{module}', '{name}')
|
||||
val['qualnames'] = val['imports']
|
||||
|
@ -179,7 +178,7 @@ class BanditConfig(object):
|
|||
data.remove(name)
|
||||
data.add('B001')
|
||||
|
||||
for name, profile in six.iteritems(profiles):
|
||||
for name, profile in profiles.items():
|
||||
blacklist = {}
|
||||
include = profile['include']
|
||||
exclude = profile['exclude']
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
import importlib
|
||||
import logging
|
||||
|
||||
import six
|
||||
|
||||
from bandit.core import blacklisting
|
||||
from bandit.core import extension_loader
|
||||
|
@ -46,7 +45,7 @@ class BanditTestSet(object):
|
|||
exc = set(profile.get('exclude', []))
|
||||
|
||||
all_blacklist_tests = set()
|
||||
for _node, tests in six.iteritems(extman.blacklist):
|
||||
for _node, tests in extman.blacklist.items():
|
||||
all_blacklist_tests.update(t['id'] for t in tests)
|
||||
|
||||
# this block is purely for backwards compatibility, the rules are as
|
||||
|
@ -83,7 +82,7 @@ class BanditTestSet(object):
|
|||
blacklist = profile.get('blacklist')
|
||||
if not blacklist: # not overridden by legacy data
|
||||
blacklist = {}
|
||||
for node, tests in six.iteritems(extman.blacklist):
|
||||
for node, tests in extman.blacklist.items():
|
||||
values = [t for t in tests if t['id'] in filtering]
|
||||
if values:
|
||||
blacklist[node] = values
|
||||
|
|
|
@ -16,7 +16,6 @@ import collections
|
|||
import tempfile
|
||||
from xml.etree import cElementTree as ET
|
||||
|
||||
import six
|
||||
import testtools
|
||||
|
||||
import bandit
|
||||
|
@ -54,12 +53,12 @@ class XmlFormatterTests(testtools.TestCase):
|
|||
if children:
|
||||
dd = collections.defaultdict(list)
|
||||
for dc in map(self._xml_to_dict, children):
|
||||
for k, v in six.iteritems(dc):
|
||||
for k, v in dc.items():
|
||||
dd[k].append(v)
|
||||
d = {t.tag: {k: v[0] if len(v) == 1 else v
|
||||
for k, v in six.iteritems(dd)}}
|
||||
for k, v in dd.items()}}
|
||||
if t.attrib:
|
||||
d[t.tag].update(('@' + k, v) for k, v in six.iteritems(t.attrib))
|
||||
d[t.tag].update(('@' + k, v) for k, v in t.attrib.items())
|
||||
if t.text:
|
||||
text = t.text.strip()
|
||||
if children or t.attrib:
|
||||
|
|
Loading…
Reference in New Issue