![]() |
Definition of optional attributes.
Inherits From: Validator
, expected_type
google.appengine.api.validation.Optional(
validator, default=None
)
Optional values are attributes which can be set to None
or left
unset. All values in a basic Validated
class are set to None
at initialization. Failure to assign to non-optional values
will result in a validation error when calling CheckInitialized
.
Args | |
---|---|
validator
|
Optional validation condition. |
Raises | |
---|---|
AttributeDefinitionError
|
if validator is not callable. |
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.
Validate
Validate(
value, key
)
Optionally require a value.
Normal validators do not accept None
. This will accept None
on
behalf of the contained validator.
Args | |
---|---|
value
|
Value to be validated as optional. |
key
|
Name of the field being validated. |
Returns | |
---|---|
None if value is None , else results of contained validation.
|
__call__
__call__(
value, key='???'
)
Main interface to validator is call mechanism.