NonManagingFileScope#
- class ansys.tools.variableinterop.non_managing_file_scope.NonManagingFileScope#
Bases:
ansys.tools.variableinterop.file_scope.FileScope,ansys.tools.variableinterop.isave_context.ISaveContext,ansys.tools.variableinterop.isave_context.ILoadContextProvides a simple file scope implementation that performs no management.
This file scope allows you to create
FileValueinstances that are backed by arbitrary preexisting files on disk. It is up to the caller to ensure that the file remains in place and unchanged for the lifespan of theFileValueinstance and that the file is deleted at an appropriate time. Because of these restrictions, it is generally not recommended using this file scope except for referencing permanently installed files.This file scope also serves as a “pass-through” save context. Because the files are assumed to be managed externally such that they are permanent (or at least not deleted while in use), the save context takes no action to save them but simply passes through their current location on disk as an identifier.
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.- Parameters:
- file_var
FileValue FileValueinstance to serialize.
- file_var
- Returns:
strAPI string representing the
FileValueinstance.
- 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.
- 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.
Classes#
Implementation of a |