code: def validate(self):
          
          for key, val in self.grammar.items():
              try:
                  setattr(self, key, val)
              except ValueError as e:
                  raise ValidationError('invalid contents: ' + e.args[0])
docs: Validate the contents of the object.
  
          This calls ``setattr`` for each of the class's grammar properties. It
          will catch ``ValueError``s raised by the grammar property's setters
          and re-raise them as :class:`ValidationError`.