toolchest.validator

class toolchest.validator.base.BaseValidator[source]

Bases: object

static validate(validator, item_to_validate)[source]

A method to allow calling of any validator, with checking to only return True or an error, so that the validator cannot inject code into the caller.

Parameters
  • validator (func) – A function to use to validate the format of an item. This function should throw a ValueError if the pattern does not match.

  • item_to_validate (obj) – A value to validate

Returns

Returns True if pattern matches

Raises

ValueError – If the item cannot be validated with the validator, a ValueError is thrown.

toolchest.validator.simple.validate_string(str_to_validate)[source]

Validates that the value passed in is a string.

Parameters

str_to_validate (str) – A value to validate

Returns

Returns True if pattern matches

Raises

ValueError – If the passed in item is not a string, a ValueError is thrown.