Текст документации сгенерирован автоматически из исходного кода.
Если обнаружили ошибку, отправьте об этом сообщение на 📧почту.
Module: utils
Provides various utilitarian functions.
Functions
validate_dict
def validate_dict(data: dict, schema: dict, mode: Literal['s', 'mka'] = 's') -> tuple[bool, Exception | None]
Validates input dictionary by scheme
Parameters:
data: dict — dictionary to be validated
schema: dict — validation schema, for example: { 'key': { 'type': data type, 'comparison' (optional): { 'keys': list of keys ([«min», «max»]), 'validator': function for validating value (lambda self, range: self >= range[0] and self ⇐ range[1]), 'error_msg': output this message if validation fails} } }
mode: Literal['s', 'mka'] — key set checking mode
«s» — strict mode, keysets must be equal.
«mka» — «missing keys are allowed» mode, <data> dict may not have a complete set of keys.
Returns:
Raises:
TypeError — If args are not a dict
RuntimeError — If set of keys are not equal or values don't match the specified conditions
ValueError — If arg <mode> is invalid
get_lang_const_translation
def get_lang_const_translation(data: LangConstant | str, n: int | float = 1) -> str
Returns translation of language constant or unmodified string
Parameters:
Returns:
retranslate_nested_langconstants
def retranslate_nested_langconstants(object, lang_code: Optional[str] = None)
Searches objects of LangConstant type and calls translate() method for each instance, also scans nested classes
Parameters: