FileValue#
- class FileValue(original_path: os.PathLike | None = None, mime_type: str | None = None, encoding: str | None = None, value_id: uuid.UUID | None = None, file_size: int | None = None)#
Bases: ansys.tools.variableinterop.variable_value.IVariableValue
, abc.ABC
Provides an abstract base class for FileValue
implementations.
Overview#
Realize the file contents to a local filesystem if needed. |
|
Realizes the file contents to a local filesystem if needed. |
Determines if a file is text-based via its MIME type. |
Invoke the visitor pattern of this object using the passed-in visitor |
|
Convert the value to a formatted string. |
|
Write the fileβs contents to a new file. |
|
Read the contents of the file as a string. |
|
Convert the value to an API string using a save context. |
|
Convert this file to an API object. |
|
Get the file extension of the file, including the period. |
Variable type of the object. |
|
MIME type of the file. |
|
Name of the original file that was wrapped. |
|
Extension of the file. |
|
Encoding of the file. |
|
ID of the file. |
|
Size of the file in bytes if known. |
|
Flag indicating if this file is text-based via its MIME type. |
JSON key for API serialization representing the original file name. |
|
Open a file for reading and detect a byte order mark at the beginning. |
Import detail#
from ansys.tools.variableinterop.file_value import FileValue
Property detail#
- property FileValue.variable_type: VariableType#
Variable type of the object.
- Returns:
VariableType
Variable type of the object.
- property FileValue.original_file_name: os.PathLike | None#
Name of the original file that was wrapped.
Attribute detail#
Method detail#
- FileValue.__eq__(other)#
Return self==value.
- FileValue.__hash__()#
Return hash(self).
- FileValue.accept(visitor: ansys.tools.variableinterop.ivariable_visitor.IVariableValueVisitor[T]) T #
Invoke the visitor pattern of this object using the passed-in visitor implementation.
- Parameters:
- visitor
IVariableValueVisitor
Visitor object to call.
- visitor
- Returns:
T
Results of the visitor invocation.
- static FileValue.read_bom(filename: str) str #
Open a file for reading and detect a byte order mark at the beginning.
- async FileValue.write_file(file_name: os.PathLike) None #
Write the fileβs contents to a new file.
- Parameters:
- file_name
PathLike
Path to the file to create.
- file_name
- Returns:
- abstract async FileValue.get_reference_to_actual_content_file_async(progress_callback: Callable[[int], None] | None = None) AsyncLocalFileContentContext #
Realize the file contents to a local filesystem if needed.
The
FileValue
instance is intended to represent an immutable value. The file returned by this call may point to a cached file or even the original file. Callers must not modify the file on disk. Otherwise, undefined behaviors, including class 3 errors, may occur. If the caller needs to modify the file, consider using thewrite_file
method or copying the file before modifying it.- Parameters:
- progress_callback
Optional
[Callable
[[int
],None
]],optional
Callback that can be called to indicate progress in realizing the local copy. The default is
None
, in which case this method makes no attempt to report its progress. This method may call a provided callback with a percentage value between 0 and 100 inclusive. The provided callback may not necessarily be called at all, and calls for 0 or 100 percent are not guaranteed, even if other calls occur.
- progress_callback
- Returns:
AsyncLocalFileContentContext
Context manager that, when exited, deletes the local copy if it is a temporary file.
- abstract FileValue.get_reference_to_actual_content_file(progress_callback: Callable[[int], None] | None = None) LocalFileContentContext #
Realizes the file contents to a local filesystem if needed.
The
FileValue
instance is intended to represent an immutable value. The file returned by this call may point to a cached file or even the original file. Callers must not modify the file on disk. Otherwise, undefined behaviors, including class 3 errors, may occur. If the caller needs to modify the file, consider using thewrite_file
method or copying the file before modifying it.- Parameters:
- progress_callback
Optional
[Callable
[[int
],None
]],optional
Callback that can be called to indicate progress in realizing the local copy. The default is
None
, in which case this method makes no attempt to report its progress. This method may call a provided callback with a percentage value between 0 and 100 inclusive. The provided callback may not necessarily be called at all, and calls for 0 or 100 percent are not guaranteed, even if other calls occur.
- progress_callback
- Returns:
LocalFileContentContext
Context manager that, when exited, deletes the local copy if it is a temporary file.
- classmethod FileValue.is_text_based_static(mimetype: str) bool | None #
Determines if a file is text-based via its MIME type.
- async FileValue.get_contents(encoding: str | None = None) str #
Read the contents of the file as a string.
- FileValue.to_api_string(context: ansys.tools.variableinterop.isave_context.ISaveContext | None = None) str #
Convert the value to an API string using a save context.
- Parameters:
- context
Optional
[ISaveContext
],optional
Save context to use. The default value is
None
, in which case file values are not supported.
- context
- Returns:
str
String appropriate for use in files and APIs.
- FileValue.to_api_object(save_context: ansys.tools.variableinterop.isave_context.ISaveContext) Dict[str, str | None] #
Convert this file to an API object.
- Parameters:
- save_context
ISaveContext
Save context to use for the conversion.
- save_context
- Returns: