Skip to main content

Value validation module

Project description

This is a Python module that provides an easy way to validate values in other projects. The base class provides some generic comparisons and should be overridden in order to define comparisons for other classes.

Installation

Add the source as a submodule to your project.

$ git submodule add https://github.com/andrewseaman35/py-value-validator.git $ git submodule init

Usage

By overriding the functions class, validation functions can be added by data type or to the generic function list. Any function that is specified as generic may be used by any data of any type being validated.

class ValidatorFunctions(GenericValidatorFunctions):
def _add_typed_functions(self):

self._add_function(str, “contains”, contains) self._add_function(“generic”, “is_not_none”, is_not_none)

def contains(mine, yours):

return yours in mine

def is_not_none(mine, yours=None):

return mine is not None

Create a validator with an instance of the function class.

_validator_functions = ValidatorFunctions() validator = ValueValidator(_validator_functions)

Define a list of tuples that define the validation for the given value.

validations = [(‘contains’, ‘ell’), (‘is_not_none’, None)]

Run the validations against a value and keep an eye out for a ValidationError.

try:

validator.validate(“hello, world!”, validations)

except ValidationError as validation_error:

print(“Value did not pass validation!”)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_value_validator-0.0.2.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file py_value_validator-0.0.2.tar.gz.

File metadata

File hashes

Hashes for py_value_validator-0.0.2.tar.gz
Algorithm Hash digest
SHA256 479bd13c16c7cfb3a4d0012da7953d795ab110e75806ae8ce95268a54a7a68ce
MD5 d2fcd42e7c38712fb1af40a1bdac3f4f
BLAKE2b-256 751c2deb641cd07c399065005187e79830e11b1234ae3896c81cc56cd127ef5a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page