MCPcopy Create free account
hub / github.com/ParzivalHack/PySpector / run_pyspector

Function run_pyspector

tests/unit/test_taint_engine_extension.py:24–55  ·  view source on GitHub ↗
(code: str, *, filename: str = "app.py")

Source from the content-addressed store, hash-verified

22
23
24def run_pyspector(code: str, *, filename: str = "app.py") -> list[dict]:
25 from pyspector._rust_core import run_scan
26 from pyspector.config import get_default_rules
27
28 rules_toml = get_default_rules()
29
30 with tempfile.TemporaryDirectory() as tmpdir:
31 file_path = os.path.join(tmpdir, filename)
32 Path(file_path).write_text(_wrap_in_function(code))
33
34 import ast as _ast, json as _json
35 from pyspector.cli import AstEncoder
36
37 with warnings.catch_warnings():
38 warnings.filterwarnings("ignore")
39 try:
40 tree = _ast.parse(Path(file_path).read_text())
41 ast_json = _json.dumps(tree, cls=AstEncoder)
42 except Exception:
43 ast_json = "{}"
44
45 python_files = [{
46 "file_path": filename,
47 "content": Path(file_path).read_text(),
48 "ast_json": ast_json,
49 }]
50
51 results = run_scan(tmpdir, rules_toml, {"exclude": []}, python_files)
52
53 return [{"rule_id": r.rule_id, "file_path": r.file_path,
54 "line_number": r.line_number, "code": r.code}
55 for r in results]
56
57
58def findings_for(code, rule_id, **kw):

Callers 1

findings_forFunction · 0.70

Calls 2

get_default_rulesFunction · 0.90
_wrap_in_functionFunction · 0.85

Tested by

no test coverage detected