Skip to main content

OsFunctionCall

Enum OsFunctionCall 

Source
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.

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).

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

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for OsFunctionCall

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OsFunctionCall

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for OsFunctionCall

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for OsFunctionCall

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'_derivative_strum> From<&'_derivative_strum OsFunctionCall> for &'static str

Source§

fn from(x: &'_derivative_strum OsFunctionCall) -> &'static str

Converts to this type from the input type.
Source§

impl From<OsFunctionCall> for &'static str

Source§

fn from(x: OsFunctionCall) -> &'static str

Converts to this type from the input type.
Source§

impl Serialize for OsFunctionCall

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.