App Engine Python SDK  v1.6.9 rev.445
The Python runtime is available as an experimental Preview feature.
Public Member Functions | Public Attributes | List of all members
google.appengine.api.validation.Type Class Reference
Inheritance diagram for google.appengine.api.validation.Type:
google.appengine.api.validation.Validator

Public Member Functions

def __init__
 
def Validate
 
- Public Member Functions inherited from google.appengine.api.validation.Validator
def __init__
 
def __call__
 
def Validate
 
def ToValue
 

Public Attributes

 expected_type
 
 convert
 
- Public Attributes inherited from google.appengine.api.validation.Validator
 default
 

Additional Inherited Members

- Static Public Attributes inherited from google.appengine.api.validation.Validator
 expected_type = object
 

Detailed Description

Verifies property is of expected type.

Can optionally convert value if it is not of the expected type.

It is possible to specify a required field of a specific type in shorthand
by merely providing the type.  This method is slightly less efficient than
providing an explicit type but is not significant unless parsing a large
amount of information:

  class Person(Validated):
    ATTRIBUTES = {'name': unicode,
                  'age': int,
                  }

However, in most instances it is best to use the type constants:

  class Person(Validated):
    ATTRIBUTES = {'name': TypeUnicode,
                  'age': TypeInt,
                  }

Constructor & Destructor Documentation

def google.appengine.api.validation.Type.__init__ (   self,
  expected_type,
  convert = True,
  default = None 
)
Initialize Type validator.

Args:
  expected_type: Type that attribute should validate against.
  convert: Cause conversion if value is not the right type.
Conversion is done by calling the constructor of the type
with the value as its first parameter.
  default: Default assignment is made during initialization and will
not pass through validation.

Member Function Documentation

def google.appengine.api.validation.Type.Validate (   self,
  value,
  key 
)
Validate that value has the correct type.

Args:
  value: Value to validate.
  key: Name of the field being validated.

Returns:
  value if value is of the correct type. value is coverted to the correct
  type if the Validator is configured to do so.

Raises:
  MissingAttribute: if value is None and the expected type is not NoneType.
  ValidationError: if value is not of the right type and the validator
is either configured not to convert or cannot convert.

The documentation for this class was generated from the following file: