NonManagingFileScope#

class NonManagingFileScope#

Bases: ansys.tools.variableinterop.file_scope.FileScope, ansys.tools.variableinterop.isave_context.ISaveContext, ansys.tools.variableinterop.isave_context.ILoadContext

Provides a simple file scope implementation that performs no management.

class NonManagingFileValue(to_read: os.PathLike, mime_type: str | None = None, encoding: str | None = None)#

Bases: ansys.tools.variableinterop.file_value.LocalFileValue

Implementation of a FileValue instance used by this scope.

from ansys.tools.variableinterop.non_managing_file_scope.NonManagingFileScope import NonManagingFileValue

Overview#

read_from_file

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

to_api_string_file_store

Serialize a FileValue instance in this scope to an API string.

from_api_object

Create a FileScope instance from a map of API strings.

save_file

Save a file to the save medium.

load_file

Load a file from the load medium.

flush

Flush any changes in the context to the underlying stream or file.

close

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

Import detail#

from ansys.tools.variableinterop.non_managing_file_scope import NonManagingFileScope

Method detail#

NonManagingFileScope.read_from_file(to_read: os.PathLike, mime_type: str | None, encoding: str | 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.

NonManagingFileScope.to_api_string_file_store(file_var: ansys.tools.variableinterop.file_value.FileValue) str#

Serialize a FileValue instance in this scope to an API string.

Parameters:
file_varFileValue

FileValue instance to serialize.

Returns:
str

API string representing the FileValue instance.

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

NonManagingFileScope.save_file(source: os.PathLike | str, content_id: str | None) str#

Save a file to the save medium.

It is up to the ISaveContext implementation to decide how or when to send the actual data. Some ISaveContext implementations may merely collect metadata as part of this call and send the data on flush.

Parameters:
sourceUnion[PathLike, str]

File on disk to send or include in the save.

content_idOptional[str], optional

Unique ID for the file. The default value is None, in which case an ID is automatically generated and returned. This ID can be used with an equivalent ILoadContext instance to load the contents on deserialization.

Returns:
str

ID, either the one provided or the one otherwise generated.

NonManagingFileScope.load_file(content_id: str | None) os.PathLike | None#

Load a file from the load medium.

The ILoadContext implementation decides how or when to send the actual data. Some ILoadContexts implementations may merely collect metadata as part of this call and send the data on flush.

Parameters:
content_idOptional[str]

ID generated by an equivalent ISaveContext instance to save a file into this context.

Returns:
Optional[PathLike]

Path to the loaded file.

NonManagingFileScope.flush() None#

Flush any changes in the context to the underlying stream or file.

NonManagingFileScope.close() None#

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