FileScope#

class FileScope#

Bases: contextlib.AbstractContextManager, abc.ABC

Provides an abstract base for file scopes.

Overview#

close

Close the FileScope instance, cleaning up any files it contains.

read_from_file

Read the contents of a file and create a new FileValue object backed by a

from_api_object

Create a FileScope instance from a map of API strings.

__exit__

Raise any exception triggered within the runtime context.

Import detail#

from ansys.tools.variableinterop.file_scope import FileScope

Method detail#

FileScope.__exit__(__exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: types.TracebackType | None) bool | None#

Raise any exception triggered within the runtime context.

abstract FileScope.close() None#

Close the FileScope instance, cleaning up any files it contains.

abstract FileScope.read_from_file(to_read: os.PathLike, mime_type: str | None = None, encoding: str | None = None) ansys.tools.variableinterop.file_value.FileValue#

Read the contents of a file and create a new FileValue object backed by a file in this scope.

Parameters:
to_readPathLike

Path to the file to read.

mime_typeOptional[str], optional

MIME type of the file. The default is None, which indicates that the file does not have a MIME type or that the type is not known.

encodingOptional[str], optional

Encoding of the file. The default is None, which indicates that the file does not have a text encoding (for example, because it is a binary file.)

Returns:
FileValue

New FileValue object with the contents of the specified file, backed by this scope.

abstract FileScope.from_api_object(api_object: Dict[str, str | None], load_context: ansys.tools.variableinterop.isave_context.ILoadContext) ansys.tools.variableinterop.file_value.FileValue#

Create a FileScope instance from a map of API strings.

Parameters:
api_objectDict[str, Optional[str]]

Map of API strings that define the scope.

load_contextILoadContext

Load context to read the file contents from.