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.LocalFileValueImplementation of a
FileValueinstance used by this scope.from ansys.tools.variableinterop.non_managing_file_scope.NonManagingFileScope import NonManagingFileValue
Overview#
Read the contents of a file and create a new |
|
Serialize a |
|
Create a |
|
Save a file to the save medium. |
|
Load a file from the load medium. |
|
Flush any changes in the context to the underlying stream or file. |
|
Close the |
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
FileValueobject backed by a file in this scope.- Parameters:
- to_read
PathLike Path to the file to read.
- mime_type
Optional[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.
- encoding
Optional[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.)
- to_read
- Returns:
FileValueNew
FileValueobject 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
FileValueinstance in this scope to an API string.
- 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
FileScopeinstance from a map of API strings.- Parameters:
- api_object
Dict[str,Optional[str]] Map of API strings that define the scope.
- load_context
ILoadContext Load context to read the file contents from.
- api_object
- NonManagingFileScope.save_file(source: os.PathLike | str, content_id: str | None) str#
Save a file to the save medium.
It is up to the
ISaveContextimplementation to decide how or when to send the actual data. SomeISaveContextimplementations may merely collect metadata as part of this call and send the data on flush.- Parameters:
- source
Union[PathLike,str] File on disk to send or include in the save.
- content_id
Optional[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 equivalentILoadContextinstance to load the contents on deserialization.
- source
- Returns:
strID, 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
ILoadContextimplementation decides how or when to send the actual data. SomeILoadContextsimplementations may merely collect metadata as part of this call and send the data on flush.- Parameters:
- content_id
Optional[str] ID generated by an equivalent
ISaveContextinstance to save a file into this context.
- content_id
- Returns:
Optional[PathLike]Path to the loaded file.