MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / _to_vpath

Function _to_vpath

src/sandbox_vm/tools/utils.py:22–36  ·  view source on GitHub ↗

Convert a real path under `session_root` to a vpath. Raises PermissionError if `real_path` is outside `session_root`.

(
    session_root: Union[Path, str], real_path: Union[Path, str], *, prefix: bool = False
)

Source from the content-addressed store, hash-verified

20
21
22def _to_vpath(
23 session_root: Union[Path, str], real_path: Union[Path, str], *, prefix: bool = False
24) -> str:
25 """
26 Convert a real path under `session_root` to a vpath.
27
28 Raises PermissionError if `real_path` is outside `session_root`.
29 """
30 rp = Path(real_path).resolve()
31 base = Path(session_root).resolve()
32 if not str(rp).startswith(str(base)):
33 raise PermissionError("real path not under session root")
34 rel = rp.relative_to(base)
35 v = "/" + str(rel)
36 return ("sandbox:" + v) if prefix else v
37
38
39def _from_vpath(session_root: Union[Path, str], vpath: str) -> Path:

Callers 3

_save_html_snapshotFunction · 0.90
_capture_visionFunction · 0.90
_runFunction · 0.90

Calls 1

resolveMethod · 0.80

Tested by

no test coverage detected