diff --git a/.travis.yml b/.travis.yml index b8bc58dd1..064ad1096 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,12 +31,6 @@ matrix: sudo: true - python: pypy env: TOXENV=pypy - allow_failures: - - python: 3.8-dev - env: TOXENV=py38 - dist: xenial - sudo: true - notifications: email: - lhinds@protonmail.com diff --git a/bandit/core/node_visitor.py b/bandit/core/node_visitor.py index ab7bc8054..172eebc78 100644 --- a/bandit/core/node_visitor.py +++ b/bandit/core/node_visitor.py @@ -152,6 +152,23 @@ def visit_ImportFrom(self, node): self.context['name'] = nodename.name self.update_scores(self.tester.run_tests(self.context, 'ImportFrom')) + def visit_Constant(self, node): + '''Visitor for AST Constant nodes + + call the appropriate method for the node type. + this maintains compatibility with <3.6 and 3.8+ + + This code is heavily influenced by Anthony Sottile (@asottile) here: + https://bugs.python.org/msg342486 + + :param node: The node that is being inspected + :return: - + ''' + if isinstance(node.value, str): + self.visit_Str(node) + elif isinstance(node.value, bytes): + self.visit_Bytes(node) + def visit_Str(self, node): '''Visitor for AST String nodes diff --git a/bandit/core/utils.py b/bandit/core/utils.py index 0a04b41ec..ab031abe9 100644 --- a/bandit/core/utils.py +++ b/bandit/core/utils.py @@ -14,7 +14,6 @@ # License for the specific language governing permissions and limitations # under the License. -import _ast import ast import logging import os.path @@ -46,11 +45,11 @@ def _get_attr_qual_name(node, aliases): :param aliases: Import aliases dictionary :returns: Qualified name referred to by the attribute or name. ''' - if isinstance(node, _ast.Name): + if isinstance(node, ast.Name): if node.id in aliases: return aliases[node.id] return node.id - elif isinstance(node, _ast.Attribute): + elif isinstance(node, ast.Attribute): name = '%s.%s' % (_get_attr_qual_name(node.value, aliases), node.attr) if name in aliases: return aliases[name] @@ -60,11 +59,11 @@ def _get_attr_qual_name(node, aliases): def get_call_name(node, aliases): - if isinstance(node.func, _ast.Name): + if isinstance(node.func, ast.Name): if deepgetattr(node, 'func.id') in aliases: return aliases[deepgetattr(node, 'func.id')] return deepgetattr(node, 'func.id') - elif isinstance(node.func, _ast.Attribute): + elif isinstance(node.func, ast.Attribute): return _get_attr_qual_name(node.func, aliases) else: return "" @@ -76,7 +75,7 @@ def get_func_name(node): def get_qual_attr(node, aliases): prefix = "" - if isinstance(node, _ast.Attribute): + if isinstance(node, ast.Attribute): try: val = deepgetattr(node, 'value.id') if val in aliases: