drepr.utils.validator#

Classes

AnyValidator(is_optional)

DictValidator(cls, is_optional, **kwargs)

ListValidator(element_type, is_optional)

PrimitiveValidator(type_name, is_optional)

SchemaValidator(is_optional)

Validator()

Exceptions

exception InputError[source]#

Bases: Exception

add_note()#

Exception.add_note(note) – add a note to the exception

args#
with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class Validator[source]#

Bases: object

static must_be_dict(val: Any, error_msg: str)[source]#
Parameters:
  • val (Any) –

  • error_msg (str) –

static must_be_list(val: Any, error_msg: str)[source]#
Parameters:
  • val (Any) –

  • error_msg (str) –

static must_be_list_str(val: Any, error_msg: str)[source]#
Parameters:
  • val (Any) –

  • error_msg (str) –

static must_be_str(val: Any, error_msg: str)[source]#
Parameters:
  • val (Any) –

  • error_msg (str) –

static must_be_int(val: Any, error_msg: str)[source]#
Parameters:
  • val (Any) –

  • error_msg (str) –

static must_be_bool(val: Any, error_msg: str)[source]#
Parameters:
  • val (Any) –

  • error_msg (str) –

static must_be_subset(parent: Set[Any], subset: Iterable[Any], setname: str, error_msg: str)[source]#
Parameters:
static must_in(val: Any, choices: Set[str], error_msg: str)[source]#
Parameters:
static must_have(odict: dict, attr: str, error_msg: str)[source]#
Parameters:
  • odict (dict) –

  • attr (str) –

  • error_msg (str) –

static must_equal(val: Any, expected_val: Any, error_msg: str)[source]#
Parameters:
  • val (Any) –

  • expected_val (Any) –

  • error_msg (str) –

class SchemaValidator(is_optional: bool)[source]#

Bases: ABC

Parameters:

is_optional (bool) –

abstract validate(value)[source]#
abstract raise_error(value)[source]#
abstract to_string()[source]#
class DictValidator(cls: str, is_optional: bool, **kwargs)[source]#

Bases: SchemaValidator

Parameters:
  • cls (str) –

  • is_optional (bool) –

REG_PT = re.compile('^int|str|float|any$')#
REG_OPTIONAL = re.compile('^optional\\((.+)\\)$')#
REG_LIST = re.compile('^list\\((.+)\\)$')#
validate(odict)[source]#
raise_error(odict)[source]#
to_string()[source]#
class AnyValidator(is_optional: bool)[source]#

Bases: SchemaValidator

Parameters:

is_optional (bool) –

validate(value)[source]#
raise_error(value)[source]#
to_string()[source]#
class PrimitiveValidator(type_name: str, is_optional: bool)[source]#

Bases: SchemaValidator

Parameters:
  • type_name (str) –

  • is_optional (bool) –

validate(value)[source]#
raise_error(odict)[source]#
to_string()[source]#
class ListValidator(element_type: SchemaValidator, is_optional: bool)[source]#

Bases: SchemaValidator

Parameters:
validate(value)[source]#
raise_error(odict)[source]#
to_string()[source]#