View source on GitHub |
Validates that numbers fall within the correct range.
Inherits From: Validator
, expected_type
google.appengine.api.validation.Range(
minimum,
maximum,
range_type=google.appengine.ext.db.IntegerProperty.data_type
,
default=None
)
In theory this class can be emulated using Options, however error messages generated from that class will not be very intelligible. This class essentially does the same thing, but knows the intended integer range.
Also, this range class supports floats and other types that implement ordinality.
The range is inclusive, meaning 3 is considered in the range
in Range(1,3)
.
Args | |
---|---|
minimum
|
Minimum for attribute. |
maximum
|
Maximum for attribute. |
range_type
|
Type of field. Defaults to int. |
Raises | |
---|---|
AttributeDefinitionError
|
If the specified parameters are incorrect. |
Child Classes
Methods
CheckFieldInitialized
CheckFieldInitialized(
value, key, obj
)
Check for missing fields or conflicts between fields.
Default behavior performs a simple None
-check, but this can be overridden.
If the intent is to allow optional fields, then use the Optional
validator
instead.
Args | |
---|---|
value
|
Value to validate. |
key
|
Name of the field being validated. |
obj
|
The object to validate against. |
Raises | |
---|---|
ValidationError
|
When there are missing or conflicting fields. |
GetWarnings
GetWarnings(
value, key, obj
)
Return any warnings on this attribute.
Validates the value with an eye towards things that aren't fatal problems.
Args | |
---|---|
value
|
Value to validate. |
key
|
Name of the field being validated. |
obj
|
The object to validate against. |
Returns | |
---|---|
A list of tuples (context, warning) where
|
ToValue
ToValue(
value
)
Convert value
to a simplified collection or basic type.
Subclasses of Validator
should override this method when the dumped
representation of value
is not a simple <type>(value)
(e.g., a regex).
Args | |
---|---|
value
|
An object of the same type that was returned from Validate() .
|
Returns | |
---|---|
An instance of a builtin type (e.g., int, str, dict, etc). By default
it returns value unmodified.
|
Validate
Validate(
value, key
)
Validate that value is within range.
Validates against range-type then checks the range.
Args | |
---|---|
value
|
Value to validate. |
key
|
Name of the field being validated. |
Raises | |
---|---|
ValidationError
|
When value is out of range. |
__call__
__call__(
value, key='???'
)
Main interface to validator is call mechanism.