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

Public Member Functions

def __init__
 
def GetValidator
 
def __setitem__
 
def setdefault
 
def update
 
def Set
 
def ToDict
 
- Public Member Functions inherited from google.appengine.api.validation.ValidatedBase
def GetValidator
 
def SetMultiple
 
def Set
 
def CheckInitialized
 
def ToDict
 
def ToYAML
 

Static Public Attributes

 KEY_VALIDATOR = None
 
 VALUE_VALIDATOR = None
 

Detailed Description

Base class for validated dictionaries.

You can control the keys and values that are allowed in the dictionary
by setting KEY_VALIDATOR and VALUE_VALIDATOR to subclasses of Validator (or
things that can be interpreted as validators, see AsValidator).

For example if you wanted only capitalized keys that map to integers
you could do:

  class CapitalizedIntegerDict(ValidatedDict):
    KEY_VALIDATOR = Regex('[A-Z].*')
    VALUE_VALIDATOR = int  # this gets interpreted to Type(int)

The following code would result in an error:

  my_dict = CapitalizedIntegerDict()
  my_dict['lowercase'] = 5  # Throws a validation exception

You can freely nest Validated and ValidatedDict inside each other so:

  class MasterObject(Validated):
    ATTRIBUTES = {'paramdict': CapitalizedIntegerDict}

Could be used to parse the following yaml:
  paramdict:
    ArbitraryKey: 323
    AnotherArbitraryKey: 9931

Constructor & Destructor Documentation

def google.appengine.api.validation.ValidatedDict.__init__ (   self,
  kwds 
)
Construct a validated dict by interpreting the key and value validators.

Args:
  **kwds: keyword arguments will be validated and put into the dict.

Member Function Documentation

def google.appengine.api.validation.ValidatedDict.__setitem__ (   self,
  key,
  value 
)
Set an item.

Only attributes accepted by GetValidator and values that validate
with the validator returned from GetValidator are allowed to be set
in this dictionary.

Args:
  key: Name of item to set.
  value: Items new value.

Raises:
  ValidationError: when trying to assign to a value that does not exist.
def google.appengine.api.validation.ValidatedDict.GetValidator (   self,
  key 
)
Check the key for validity and return a corresponding value validator.

Args:
  key: The key that will correspond to the validator we are returning.
def google.appengine.api.validation.ValidatedDict.Set (   self,
  key,
  value 
)
Set a single value on Validated instance.

This method checks that a given key and value are valid and if so
puts the item into this dictionary.

Args:
  key: The name of the attributes
  value: The value to set

Raises:
  ValidationError: when no validated attribute exists on class.
def google.appengine.api.validation.ValidatedDict.setdefault (   self,
  key,
  value = None 
)
Trap setdefaultss to ensure all key/value pairs are valid.

See the documentation for setdefault on dict for usage details.

Raises:
  ValidationError: if the specified key is illegal or the
  value invalid.
def google.appengine.api.validation.ValidatedDict.ToDict (   self)
Convert ValidatedBase object to a dictionary.

Recursively traverses all of its elements and converts everything to
simplified collections.

Subclasses should override this method.

Returns:
  A dictionary mapping all attributes to simple values or collections.
def google.appengine.api.validation.ValidatedDict.update (   self,
  other,
  kwds 
)
Trap updates to ensure all key/value pairs are valid.

See the documentation for update on dict for usage details.

Raises:
  ValidationError: if any of the specified keys are illegal or
values invalid.

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