pub enum OsFunctionCall {
Show 32 variants
Exists(MontyPath),
IsFile(MontyPath),
IsDir(MontyPath),
IsSymlink(MontyPath),
ReadText(MontyPath),
ReadBytes(MontyPath),
Stat(MontyPath),
Iterdir(MontyPath),
Scan(ScanArgs),
Resolve(MontyPath),
Absolute(MontyPath),
WriteText(PathStringDataArgs),
AppendText(PathStringDataArgs),
WriteBytes(PathBytesDataArgs),
AppendBytes(PathBytesDataArgs),
Open(OpenCallArgs),
Mkdir(MkdirCallArgs),
Unlink(MontyPath),
Rmdir(MontyPath),
Rename(RenameCallArgs),
Getenv(GetenvArgs),
GetEnviron,
DateToday,
DateTimeNow(Option<MontyTimeZone>),
Urandom(UrandomArgs),
Time(TimeCaller),
Sleep(Duration),
SystemSleep(Duration),
AsyncSleep(Duration),
AsyncSystemSleep(Duration),
Import(String),
ImportStubs(Vec<String>),
}Expand description
Tagged dispatch value for OS-level operations.
Each variant carries the strongly-typed args/kwargs the corresponding OS
call needs. The fs/ layer matches on this enum directly (no value
introspection); host bindings get a generic (positional, keyword) view
via OsFunctionCall::to_args.
See the module docs for how to add a new variant.
Variants§
Exists(MontyPath)
Check if a path exists.
IsFile(MontyPath)
Check if path is a regular file.
IsDir(MontyPath)
Check if path is a directory.
IsSymlink(MontyPath)
Check if path is a symbolic link.
ReadText(MontyPath)
Read file contents as text.
ReadBytes(MontyPath)
Read file contents as bytes.
Stat(MontyPath)
stat() — return a stat result tuple.
Iterdir(MontyPath)
List directory contents.
Scan(ScanArgs)
Read a bounded subtree in one call, for os.scandir, os.walk,
Path.walk, Path.glob and Path.rglob (see crate::scan).
Resolve(MontyPath)
Resolve symlinks and return absolute path.
Absolute(MontyPath)
Absolute path without symlink resolution.
WriteText(PathStringDataArgs)
Write text to file (truncating).
AppendText(PathStringDataArgs)
Append text to file.
WriteBytes(PathBytesDataArgs)
Write bytes to file (truncating).
AppendBytes(PathBytesDataArgs)
Append bytes to file.
Open(OpenCallArgs)
Open a file. The host performs the open-time effect (truncate for
w/w+, create-if-missing for a/a+, existence check for r/r+)
and returns a MontyFileHandle — it never holds a live OS
handle across calls.
Mkdir(MkdirCallArgs)
Create directory (parents/exist_ok kwargs).
Unlink(MontyPath)
Remove file.
Rmdir(MontyPath)
Remove directory.
Rename(RenameCallArgs)
Rename / move (src → dst).
Getenv(GetenvArgs)
Get an environment variable value.
GetEnviron
Get the entire environment as a dictionary.
DateToday
Get today’s date from the host system (for date.today()).
DateTimeNow(Option<MontyTimeZone>)
Get the current date/time from the host system (for datetime.now(tz=...)).
Carries the timezone argument, None for a naive result.
Urandom(UrandomArgs)
Read size bytes of entropy from the host (for os.urandom(size), and
how the random module seeds an unseeded generator).
Time(TimeCaller)
Read the host clock as time.time() does: seconds since the Unix
epoch, answered with MontyObject::float. Every clock-reading time
function arrives here; TimeCaller, the call’s only argument, says which.
Sleep(Duration)
time.sleep(seconds) under SleepMode::CallHost — the host’s os
handler waits, then answers with any value (time.sleep discards it
and evaluates to None).
SystemSleep(Duration)
time.sleep(seconds) under SleepMode::System, capped at its maximum.
The host charges max_total_sleep, waits and returns None without its
os handler. The distinct name identifies the policy for the host.
AsyncSleep(Duration)
asyncio.sleep(delay) — like Sleep, except the
sandbox turns the answer into an awaitable, so a host that runs an
event loop should answer with a future (ExtFunctionResult::Future)
and resolve it when the delay elapses, letting sibling tasks run
meanwhile. The answer’s value is ignored: the sandbox keeps the
result argument itself and produces it from the await.
AsyncSystemSleep(Duration)
asyncio.sleep(delay) under SleepMode::System: the awaitable form of
SystemSleep, which a host running an event loop
answers with a future it resolves once the delay elapses.
Import(String)
Requests a missing module by top-level name. The host returns its value, an exception,
or not_found / not_handled to raise ModuleNotFoundError.
from m import a and import m.sub then load attributes from that value.
ImportStubs(Vec<String>)
Requests stubs for previously unrequested top-level imports before type-checking a feed.
The host returns a dict of dotted module paths to stub source (or None),
or not_found / not_handled for no stubs.
Implementations§
Source§impl OsFunctionCall
impl OsFunctionCall
Sourcepub fn accepts_future(name: &str) -> bool
pub fn accepts_future(name: &str) -> bool
Whether this name accepts ExtFunctionResult::Future,
letting other tasks run until the host resolves it. Only asyncio.sleep
qualifies, in either sleep mode; all other calls require an immediate answer.
Sourcepub fn name(&self) -> &'static str
pub fn name(&self) -> &'static str
Stable string name for this OS function — surfaces in
Self::on_no_handler errors, host os callbacks, and serialised
snapshots. The strum serialize string on each variant.
Sourcepub fn to_args(self) -> CallArgs
pub fn to_args(self) -> CallArgs
Projects this call’s args into the CallArgs delivered to a host
callback, with lexically normalized paths. Empty paths stay empty. The
interpreter checks NUL bytes before dispatch; hosts constructing calls
must use Self::check_path_null_bytes first. Mounts must validate
length limits on the original typed call.
Sourcepub fn is_write(&self) -> bool
pub fn is_write(&self) -> bool
Whether this call mutates filesystem state — the read-only-mount gate.
Open’s write-ness is mode-dependent (w/w+/a/a+ write; r/r+
don’t).
Sourcepub fn is_existence_check(&self) -> bool
pub fn is_existence_check(&self) -> bool
Whether this operation checks existence without reading content.
Existence checks return false for nonexistent paths rather than
raising FileNotFoundError, matching CPython’s pathlib.Path.
Sourcepub fn check_path_null_bytes(&self) -> Result<(), &'static str>
pub fn check_path_null_bytes(&self) -> Result<(), &'static str>
Checks both raw filesystem paths before normalization can hide a NUL byte.
Returns the operation-specific ValueError message; existence predicates
should return False instead of raising it.
Sourcepub fn embedded_null_message(&self, for_destination: bool) -> &'static str
pub fn embedded_null_message(&self, for_destination: bool) -> &'static str
CPython’s ValueError message for a path containing a null byte.
The wording is not uniform in CPython: it comes from whichever layer
first inspects the path, so the content operations go through open()
and say embedded null byte, while the metadata ones are named by the
syscall their os wrapper was about to make. for_destination picks
the rename argument that carried the byte.
Sourcepub fn fs_primary_path(&self) -> Option<&str>
pub fn fs_primary_path(&self) -> Option<&str>
The call’s primary path if it’s a FS operation, None otherwise.
Used for routing and error reporting.
Sourcepub fn rename_destination(&self) -> Option<&str>
pub fn rename_destination(&self) -> Option<&str>
The rename destination path, or None for every other variant — the
second routing key a mount table needs (both rename endpoints must
resolve to the same mount).
Sourcepub fn fs_paths_mut(&mut self) -> impl Iterator<Item = &mut MontyPath>
pub fn fs_paths_mut(&mut self) -> impl Iterator<Item = &mut MontyPath>
Every path this call carries, mutably: the primary path plus the rename destination. The interpreter resolves relative paths against the sandbox working directory here before the call reaches the host, so host backends only ever see absolute virtual paths.
Sourcepub fn on_no_handler(&self) -> MontyException
pub fn on_no_handler(&self) -> MontyException
Exception to raise when no handler accepted this call: PermissionError
for FS ops (with the path), ModuleNotFoundError for an import,
RuntimeError for the other non-FS ops.