Skip to content

Commit 3510312

Browse files
committed
add auditwall.py
1 parent d95a11d commit 3510312

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import ast
2+
3+
4+
class AuditWallTransformer(ast.NodeTransformer):
5+
def visit_Module(self, node):
6+
last_import_index = -1
7+
for i, body_node in enumerate(node.body):
8+
if isinstance(body_node, (ast.Import, ast.ImportFrom)):
9+
last_import_index = i
10+
11+
new_import = ast.ImportFrom(module="crosshair.auditwall", names=[ast.alias(name="engage_auditwall")], level=0)
12+
function_call = ast.Expr(
13+
value=ast.Call(func=ast.Name(id="engage_auditwall", ctx=ast.Load()), args=[], keywords=[])
14+
)
15+
16+
node.body.insert(last_import_index + 1, new_import)
17+
node.body.insert(last_import_index + 2, function_call)
18+
19+
return node
20+
21+
22+
def transform_code(source_code: str) -> str:
23+
tree = ast.parse(source_code)
24+
transformer = AuditWallTransformer()
25+
new_tree = transformer.visit(tree)
26+
return ast.unparse(new_tree)

0 commit comments

Comments
 (0)