The introspection.py module#

Summary#

find_objects_script

Return the Mechanical script that searches the Outline tree.

describe_object_script

Return the Mechanical script that describes one object.

search_api_script

Return the Mechanical script that searches the API of the connected release.

preview_change_script

Return the Mechanical script that validates a property change without applying it.

apply_change_script

Return the Mechanical script that applies a previewed property change.

check_script_script

Return the Mechanical script that compiles a script and resolves its API names.

close_matches

Return the candidates closest to word, preferring a case-insensitive match.

extract_api_chains

Collect attribute chains rooted in names the script does not define itself.

store_preview

Record a valid preview and return its single-use token.

take_preview

Consume a preview token, checking that it matches this session and change.

Description#

Object discovery, property change previews, and script checks.

The Mechanical-side scripts here inspect the connected session itself, so the results always match the connected release instead of a bundled API snapshot. They run in the Mechanical scripting engine, which is IronPython 2.7 for remote sessions, so they avoid f-strings and annotations. Tool arguments reach them as a base64-encoded JSON payload, which cannot break out of the script text.

Module detail#

introspection.find_objects_script(args: dict[str, Any]) → str#

Return the Mechanical script that searches the Outline tree.

introspection.describe_object_script(args: dict[str, Any]) → str#

Return the Mechanical script that describes one object.

introspection.search_api_script(args: dict[str, Any]) → str#

Return the Mechanical script that searches the API of the connected release.

introspection.preview_change_script(args: dict[str, Any]) → str#

Return the Mechanical script that validates a property change without applying it.

introspection.apply_change_script(args: dict[str, Any]) → str#

Return the Mechanical script that applies a previewed property change.

introspection.check_script_script(args: dict[str, Any]) → str#

Return the Mechanical script that compiles a script and resolves its API names.

introspection.close_matches(word: str, candidates: list[str], limit: int = 3) → list[str]#

Return the candidates closest to word, preferring a case-insensitive match.

introspection.extract_api_chains(script: str) → tuple[list[dict[str, Any]], dict[str, Any] | None, bool]#

Collect attribute chains rooted in names the script does not define itself.

Parameters:
scriptstr

Script source.

Returns:
tuple

(chains, syntax_error, has_star_import). Each chain holds parts (for example ["Model", "Mesh", "ElementSize"]), line, and column. syntax_error is set when the script is not valid Python 3, in which case no chains are returned.

introspection.store_preview(store: dict[str, dict[str, Any]], mechanical: Any, object_id: int, property_name: str, value: Any, fingerprint: str) → str#

Record a valid preview and return its single-use token.

introspection.take_preview(store: dict[str, dict[str, Any]], token: str, mechanical: Any, object_id: int, property_name: str, value: Any) → dict[str, Any]#

Consume a preview token, checking that it matches this session and change.

Raises:
StalePreviewError

If the token is unknown, already used, expired, or from another session.

InvalidArgumentsError

If the token was issued for a different object, property, or value.

introspection.PREVIEW_TTL_SECONDS = 600#
introspection.MAX_PENDING_PREVIEWS = 100#
introspection.MAX_CHECKED_CHAINS = 300#