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.ILoadContext
Provides a simple file scope implementation that performs no management.
This file scope allows you to create
FileValue
instances 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 theFileValue
instance 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
FileValue
object 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:
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_var
FileValue
FileValue
instance to serialize.
- file_var
- 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.
- 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. SomeISaveContext
implementations 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 equivalentILoadContext
instance to load the contents on deserialization.
- source
- 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. SomeILoadContexts
implementations 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
ISaveContext
instance to save a file into this context.
- content_id
- Returns:
Optional
[PathLike
]Path to the loaded file.
Classes#
Implementation of a |