validators
konigle.validators
¶
Custom Pydantic validators for the Konigle SDK.
This module provides reusable validators for common field validation patterns used across different models in the SDK.
validate_country_code(v)
¶
Validate ISO 3166-1 alpha-2 country code format.
| PARAMETER | DESCRIPTION |
|---|---|
v
|
The country code to validate
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[str]
|
The validated country code in uppercase |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If country code is not 2 characters or contains |
validate_editorjs_content(v)
¶
Validate EditorJS block content format using Pydantic models.
| PARAMETER | DESCRIPTION |
|---|---|
v
|
The EditorJS content to validate
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[Dict[str, Any]]
|
The validated EditorJS content, or None if input was None |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If content format is invalid or contains unsupported |
validate_handle(v)
¶
Validate handle format for URLs.
Handles must contain only alphanumeric characters, hyphens, and underscores. Returns the handle in lowercase.
| PARAMETER | DESCRIPTION |
|---|---|
v
|
The handle value to validate
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[str]
|
The validated handle in lowercase, or None if input was None |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If handle contains invalid characters |
validate_image(v)
¶
Ensure we're uploading an image file.
| PARAMETER | DESCRIPTION |
|---|---|
v
|
Image file to upload. Can be file path, bytes, BytesIO, BinaryIO,
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If file is not an image |
| RETURNS | DESCRIPTION |
|---|---|
|
same as input |
validate_language_code(v)
¶
Validate ISO 639-1 language code format.
| PARAMETER | DESCRIPTION |
|---|---|
v
|
The language code to validate
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[str]
|
The validated language code in lowercase |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If language code is not 2 characters or contains |
validate_optional_email(v)
¶
Validate optional email field that can be None or empty string.
Treats empty strings as None, and validates non-empty strings as email addresses using EmailStr validation.
| PARAMETER | DESCRIPTION |
|---|---|
v
|
The email value to validate (can be None, empty string, or
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[str]
|
None if input was None or empty string, otherwise the validated |
Optional[str]
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If value is not a valid email address format |
validate_page_content_file(v)
¶
Ensure we're uploading a valid content file for page.
| PARAMETER | DESCRIPTION |
|---|---|
v
|
Content file to upload. Can be file path, bytes, BytesIO,
TYPE:
|
Returns: same as input
validate_price(v=None)
¶
Validate that a price is non-negative if provided.
| PARAMETER | DESCRIPTION |
|---|---|
v
|
The price value to validate
TYPE:
|
Returns: The validated price value, or None if input was None Raises: ValueError: If price is negative
validate_required_handle(v)
¶
Validate required handle format for URLs.
Same as validate_handle but for required fields.
| PARAMETER | DESCRIPTION |
|---|---|
v
|
The handle value to validate
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The validated handle in lowercase |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If handle contains invalid characters |