astropy 5.0

This can also involve converting the value from a string into the correct datatype.

The check method takes an input string which configures which check is to be used and applies that check to a supplied value.

An example input string would be: 'int_range(param1, param2)'

You would then provide something like:

>>> def int_range_check(value, min, max):
...     # turn min and max from strings to integers
...     min = int(min)
...     max = int(max)
...     # check that value is of the correct type.
...     # possible valid inputs are integers or strings
...     # that represent integers
...     if not isinstance(value, (int, long, string_type)):
...         raise VdtTypeError(value)
...     elif isinstance(value, string_type):
...         # if we are given a string
...         # attempt to convert to an integer
...         try:
...             value = int(value)
...         except ValueError:
...             raise VdtValueError(value)
...     # check the value is between our constraints
...     if not min <= value:
...          raise VdtValueTooSmallError(value)
...     if not value <= max:
...          raise VdtValueTooBigError(value)
...     return value
>>> fdict = {'int_range': int_range_check}
>>> vtr1 = Validator(fdict)
>>> vtr1.check('int_range(20, 40)', '30')
30
>>> vtr1.check('int_range(20, 40)', '60')
Traceback (most recent call last):
VdtValueTooBigError: the value "60" is too big.

The first program to utilise Validator() was Michael Foord's ConfigObj, an alternative to ConfigParser which supports lists and can validate a config file using a config schema. For more details on using Validator with ConfigObj see: https://configobj.readthedocs.org/en/latest/configobj.html

Validator is an object that allows you to register a set of 'checks'. These checks take input and test that it conforms to the check.

Examples

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /astropy/extern/configobj/validate.py#472
type: <class 'type'>
Commit: