|
1 | 1 | import ast |
2 | 2 | import itertools |
| 3 | +import logging |
3 | 4 | import os.path |
| 5 | +from pkgutil import iter_modules |
4 | 6 |
|
5 | 7 | from .alias_helper import ( |
6 | 8 | as_alias_handler, |
|
52 | 54 | remove_breaks |
53 | 55 | ) |
54 | 56 |
|
| 57 | +log = logging.getLogger(__name__) |
| 58 | +uninspectable_modules = {module.name for module in iter_modules()} # Don't warn about failing to import these |
| 59 | + |
55 | 60 |
|
56 | 61 | class StmtVisitor(ast.NodeVisitor): |
57 | 62 | def __init__(self, allow_local_directory_imports=True): |
@@ -429,9 +434,12 @@ def visit_Assign(self, node): |
429 | 434 | else: |
430 | 435 | label = LabelVisitor() |
431 | 436 | label.visit(node) |
432 | | - print('Assignment not properly handled.', |
433 | | - 'Could result in not finding a vulnerability.', |
434 | | - 'Assignment:', label.result) |
| 437 | + log.warn( |
| 438 | + 'Assignment not properly handled in %s. Could result in not finding a vulnerability.' |
| 439 | + 'Assignment: %s', |
| 440 | + getattr(self, 'filenames', ['?'])[0], |
| 441 | + self.label.result, |
| 442 | + ) |
435 | 443 | return self.append_node(AssignmentNode( |
436 | 444 | label.result, |
437 | 445 | label.result, |
@@ -1022,6 +1030,10 @@ def visit_Import(self, node): |
1022 | 1030 | name.asname, |
1023 | 1031 | retrieve_import_alias_mapping(node.names) |
1024 | 1032 | ) |
| 1033 | + for alias in node.names: |
| 1034 | + if alias.name not in uninspectable_modules: |
| 1035 | + log.warn("Cannot inspect module %s", alias.name) |
| 1036 | + uninspectable_modules.add(alias.name) # Don't repeatedly warn about this |
1025 | 1037 | return IgnoredNode() |
1026 | 1038 |
|
1027 | 1039 | def visit_ImportFrom(self, node): |
@@ -1061,4 +1073,7 @@ def visit_ImportFrom(self, node): |
1061 | 1073 | retrieve_import_alias_mapping(node.names), |
1062 | 1074 | from_from=True |
1063 | 1075 | ) |
| 1076 | + if node.module not in uninspectable_modules: |
| 1077 | + log.warn("Cannot inspect module %s", node.module) |
| 1078 | + uninspectable_modules.add(node.module) |
1064 | 1079 | return IgnoredNode() |
0 commit comments