products:pyrog:api:lastest:utils
Текст документации сгенерирован автоматически из исходного кода.
Если обнаружили ошибку, отправьте об этом сообщение на 📧почту.
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:
- tuple[bool, Exception | None] — (without description)
- bool — Validation result (True if validation passed)
- Exception — Error message if validation fails or None if validation passed
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:
- data: LangConstant | str — language constant or string
- n: int | float — a numeral for determining the plural form.
Returns:
- str — translation of language constant or source string
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:
- object — Module or Class object
- lang_code: Optional[str] — language code, for example 'en' or 'en_GB'.
products/pyrog/api/lastest/utils.txt · Последнее изменение: — 127.0.0.1