Skip to content

Commit 296cb3c

Browse files
committed
Code Analysis: Give pass to 'volatility3'
Also moves some code into a private method with a docstring in the visitor class.
1 parent f72b717 commit 296cb3c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

test/volatility3_code_analysis.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,16 @@ def __init__(self, module: types.ModuleType) -> None:
165165
def violations(self):
166166
return self._violations
167167

168-
def enter_ImportFrom(self, node: ast.ImportFrom):
169-
if not node.module:
170-
return
171-
168+
def _check_vol3_import_from(self, node: ast.ImportFrom):
169+
"""
170+
Ensure that the only thing imported from a volatility3 module (apart
171+
from the root volatility3 module) are functions and modules. This
172+
prevents re-exporting of classes and variables from modules that use
173+
them.
174+
"""
172175
if (
173176
node.module
174-
and node.module.startswith("volatility3")
177+
and node.module.startswith("volatility3.") # Give a pass to volatility3 module
175178
and node.module != "volatility3.framework.constants._version" # make an exception for this
176179
):
177180
for name in node.names:
@@ -198,6 +201,10 @@ def enter_ImportFrom(self, node: ast.ImportFrom):
198201
)
199202
)
200203

204+
def enter_ImportFrom(self, node: ast.ImportFrom):
205+
self._check_vol3_import_from(node)
206+
207+
201208
def enter_ClassDef(self, node: ast.ClassDef) -> Any:
202209
logger.debug("Entering class %s", node.name)
203210
clazz = None

0 commit comments

Comments
 (0)