Validators
psengine.helpers.helpers.Validators
¶
Common validators for pydantic models.
check_uhash_prefix
staticmethod
¶
Validate that all fields start with 'uhash:' and add it if missing.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
String or list of strings to check for uhash prefix.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str | list
|
String or list with 'uhash:' prefix ensured. |
Source code in psengine/helpers/helpers.py
convert_relative_time
staticmethod
¶
Convert relative time to datetime string if possible.
| PARAMETER | DESCRIPTION |
|---|---|
input_time
|
Relative time string, e.g., '7d', '3h'.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Datetime string in ISO 8601 format if conversion is possible. |
Source code in psengine/helpers/helpers.py
convert_str_to_list
staticmethod
¶
Convert value from str to list, strip strings, drop None/empty strings.
Non-string items in a list are passed through unchanged so enum-typed
fields (e.g. list[DomainTypes]) keep their values.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
String or list to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list | None
|
Converted list, stripped and cleaned. |
Source code in psengine/helpers/helpers.py
empty_str_to_none
staticmethod
¶
Normalise an empty string ('') to None; pass everything else through.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
A value that may be an empty string.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
None if the value is an empty string, else the value. |
Source code in psengine/helpers/helpers.py
is_rel_time_valid
staticmethod
¶
Check that a relative time like -3d is valid.
| PARAMETER | DESCRIPTION |
|---|---|
input_time
|
Relative time string, e.g., '7d', '3h'.
TYPE:
|
Source code in psengine/helpers/helpers.py
none_to_empty_list
staticmethod
¶
Coerce a null/empty API value to a list so the field is always iterable.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
A list or
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list
|
The value, or [] when it is None/empty. |