bundles / astropy 7.0.1 / astropy / extern / configobj / validate
module
astropy.extern.configobj.validate
source: /astropy/extern/configobj/validate.py :0
Members
-
_is_num_param -
_test -
_test2 -
_test3 -
<lambda> -
dottedQuadToNum -
force_list -
is_bool_list -
is_boolean -
is_float -
is_float_list -
is_int_list -
is_integer -
is_ip_addr -
is_ip_addr_list -
is_list -
is_mixed_list -
is_option -
is_string -
is_string_list -
is_tuple -
numToDottedQuad -
ValidateError -
Validator -
VdtMissingValue -
VdtParamError -
VdtTypeError -
VdtUnknownCheckError -
VdtValueError -
VdtValueTooBigError -
VdtValueTooLongError -
VdtValueTooShortError -
VdtValueTooSmallError
Summary
The Validator object is used to check that supplied values conform to a specification.
Extended Summary
The value can be supplied as a string - e.g. from a config file. In this case the check will also convert the value to the required type. This allows you to add validation as a transparent layer to access data stored as strings. The validation checks that the data is correct and converts it to the expected type.
Some standard checks are provided for basic data types. Additional checks are easy to write. They can be provided when the Validator is instantiated or added afterwards.
The standard functions work with the following basic data types :
integers
floats
booleans
strings
ip_addr
plus lists of these datatypes
Adding additional checks is done through coding simple functions.
The full set of standard checks are :
'integer': matches integer values (including negative)
Takesoptional'min'and'max'arguments
Takes optional 'min' and 'max' arguments
'float': matches float values
Has the same parameters as the integer check.
'boolean': matches boolean values -
TrueorFalseAcceptable string values for True are :
true, on, yes, 1
Acceptable string values for False are :
false, off, no, 0
Any other value raises an error.
'ip_addr': matches an Internet Protocol address, v.4, represented
by a dotted-quad string, i.e. '1.2.3.4'.
'string': matches any string.
Takes optional keyword args 'min' and 'max' to specify min and max lengths of the string.
'list': matches any list.
Takes optional keyword args 'min', and 'max' to specify min and max sizes of the list. (Always returns a list.)
'tuple': matches any tuple.
Takes optional keyword args 'min', and 'max' to specify min and max sizes of the tuple. (Always returns a tuple.)
'int_list': Matches a list of integers.
Takes the same arguments as list.
'float_list': Matches a list of floats.
Takes the same arguments as list.
'bool_list': Matches a list of boolean values.
Takes the same arguments as list.
'ip_addr_list': Matches a list of IP addresses.
Takes the same arguments as list.
'string_list': Matches a list of strings.
Takes the same arguments as list.
'mixed_list': Matches a list with different types in
specific positions. List size must match the number of arguments.
Each position can be one of : 'integer', 'float', 'ip_addr', 'string', 'boolean'
So to specify a list with two strings followed by two integers, you write the check as :
mixed_list('string', 'string', 'integer', 'integer')
'pass': This check matches everything ! It never fails
and the value is unchanged.
It is also the default if no check is specified.
'option': This check matches any from a list of options.
Youspecifythischeckwith
You specify this check with
You can supply a default value (returned if no value is supplied) using the default keyword argument.
You specify a list argument for default using a list constructor syntax in the check :
checkname(arg1, arg2, default=list('val 1', 'val 2', 'val 3'))A badly formatted set of arguments will raise a VdtParamError.
Additional content
The Validator object is used to check that supplied values conform to a specification.
The value can be supplied as a string - e.g. from a config file. In this case the check will also convert the value to the required type. This allows you to add validation as a transparent layer to access data stored as strings. The validation checks that the data is correct and converts it to the expected type.
Some standard checks are provided for basic data types. Additional checks are easy to write. They can be provided when the Validator is instantiated or added afterwards.
The standard functions work with the following basic data types :
integers
floats
booleans
strings
ip_addr
plus lists of these datatypes
Adding additional checks is done through coding simple functions.
The full set of standard checks are :
'integer': matches integer values (including negative)
Takesoptional'min'and'max'arguments
Takes optional 'min' and 'max' arguments
'float': matches float values
Has the same parameters as the integer check.
'boolean': matches boolean values -
TrueorFalseAcceptable string values for True are :
true, on, yes, 1
Acceptable string values for False are :
false, off, no, 0
Any other value raises an error.
'ip_addr': matches an Internet Protocol address, v.4, represented
by a dotted-quad string, i.e. '1.2.3.4'.
'string': matches any string.
Takes optional keyword args 'min' and 'max' to specify min and max lengths of the string.
'list': matches any list.
Takes optional keyword args 'min', and 'max' to specify min and max sizes of the list. (Always returns a list.)
'tuple': matches any tuple.
Takes optional keyword args 'min', and 'max' to specify min and max sizes of the tuple. (Always returns a tuple.)
'int_list': Matches a list of integers.
Takes the same arguments as list.
'float_list': Matches a list of floats.
Takes the same arguments as list.
'bool_list': Matches a list of boolean values.
Takes the same arguments as list.
'ip_addr_list': Matches a list of IP addresses.
Takes the same arguments as list.
'string_list': Matches a list of strings.
Takes the same arguments as list.
'mixed_list': Matches a list with different types in
specific positions. List size must match the number of arguments.
Each position can be one of : 'integer', 'float', 'ip_addr', 'string', 'boolean'
So to specify a list with two strings followed by two integers, you write the check as :
mixed_list('string', 'string', 'integer', 'integer')
'pass': This check matches everything ! It never fails
and the value is unchanged.
It is also the default if no check is specified.
'option': This check matches any from a list of options.
Youspecifythischeckwith
You specify this check with
You can supply a default value (returned if no value is supplied) using the default keyword argument.
You specify a list argument for default using a list constructor syntax in the check :
checkname(arg1, arg2, default=list('val 1', 'val 2', 'val 3'))A badly formatted set of arguments will raise a VdtParamError.
Aliases
-
astropy.config.configuration.validate