Validator input
Model for file validation.
ValidatorInput
Bases: BaseModel
File object used for validation.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
File name (basename). |
extension |
str
|
File extension without leading dot, lowercased (e.g., 'pdf'). |
size |
int
|
File size in bytes. |
file |
BinaryIO
|
Open binary file handle for content-based validations. |
content_type |
str | None
|
Optional content type (MIME), if known. |
__enter__()
Enter the runtime context related to this object.
Returns:
| Name | Type | Description |
|---|---|---|
ValidatorInput |
ValidatorInput
|
The ValidatorInput instance itself. |
__exit__(exc_type, exc_val, exc_tb)
Exit the runtime context and close the file handle if owned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type |
type[BaseException] | None
|
The exception type, if any. |
required |
exc_val |
BaseException | None
|
The exception value, if any. |
required |
exc_tb |
TracebackType | None
|
The traceback, if any. |
required |
close()
Close the underlying file handle if owned by this object.
This method is idempotent and will not raise an error if the file is already closed.
from_path(path)
classmethod
Create a ValidatorInput from a local path (opens in rb mode).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
The file path to create ValidatorInput from. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ValidatorInput |
ValidatorInput
|
A ValidatorInput instance. |