Utils Module
Utility functions for textxtract package.
Classes:
Name | Description |
---|---|
FileInfo |
File information data class. |
Functions:
Name | Description |
---|---|
create_temp_file |
Create a temporary file from bytes and return its path with security validation. |
get_file_info |
Get file information for logging and debugging. |
safe_unlink |
Safely delete a file if it exists, optionally logging errors. |
validate_file_extension |
Check if the file has an allowed extension. |
validate_file_size |
Validate file size doesn't exceed limits. |
validate_filename |
Validate filename for security issues. |
Attributes:
Name | Type | Description |
---|---|---|
DEFAULT_MAX_FILE_SIZE |
|
|
DEFAULT_MAX_TEMP_FILES |
|
Attributes
Classes
FileInfo
dataclass
Functions
create_temp_file
Create a temporary file from bytes and return its path with security validation.
Source code in textxtract/core/utils.py
get_file_info
Get file information for logging and debugging.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Union[Path, str, bytes]
|
File path or file bytes |
required |
|
Optional[str]
|
Required if source is bytes, optional for file paths |
None
|
Returns:
Name | Type | Description |
---|---|---|
FileInfo |
FileInfo
|
Data class with file information |
Source code in textxtract/core/utils.py
safe_unlink
Safely delete a file if it exists, optionally logging errors.
Source code in textxtract/core/utils.py
validate_file_extension
validate_file_size
Validate file size doesn't exceed limits.
Source code in textxtract/core/utils.py
validate_filename
Validate filename for security issues.