2024-08-03 07:43:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Static functions #
|
|
|
|
####################
|
|
|
|
|
|
|
|
# Imports
|
|
|
|
from tubot.static.abc import IValidatable
|
2024-08-07 16:49:55 +00:00
|
|
|
from tubot.static.exceptions import ValidationError
|
2024-08-03 07:43:09 +00:00
|
|
|
|
|
|
|
|
2024-08-03 10:49:08 +00:00
|
|
|
async def validate(obj: IValidatable, msg: str | None = None) -> bool:
|
2024-08-03 07:43:09 +00:00
|
|
|
"""
|
2024-08-03 10:49:08 +00:00
|
|
|
Throws an exception if the object has not been validated
|
2024-08-03 07:43:09 +00:00
|
|
|
|
|
|
|
:return: Object validity boolean
|
|
|
|
"""
|
|
|
|
if await obj.__validate__():
|
|
|
|
return True
|
2024-08-03 10:49:08 +00:00
|
|
|
if msg is None:
|
2024-08-07 16:49:55 +00:00
|
|
|
raise ValidationError("Object validation failed")
|
|
|
|
raise ValidationError(f"Object validation failed: {msg}")
|