'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.'

def Validate(self, value, key):

    if (not isinstance(value, self.expected_type)):
        if (value is None):
            raise MissingAttribute('Missing    value    is    required.')
        if self.convert:
            try:
                return self.expected_type(value)
            except ValueError as e:
                raise ValidationError(('Value    %r    for    %s    could    not    be    converted    to    type    %s.' % (value, key, self.expected_type.__name__)), e)
            except TypeError as e:
                raise ValidationError(('Value    %r    for    %s    is    not    of    the    expected    type    %s' % (value, key, self.expected_type.__name__)), e)
        else:
            raise ValidationError(('Value    %r    for    %s    is    not    of    the    expected    type    %s' % (value, key, self.expected_type.__name__)))
    else:
        return value
