'Check that value is a valid enum.'

def Validate(self, value, **_):

    if (value is None):
        return
    checked_value = value
    if isinstance(value, basestring):
        checked_value = self.enum.get(value.upper())
        if ((checked_value is None) and value.isdigit()):
            checked_value = int(value)
        if (checked_value is None):
            raise type_info.TypeValueError(('Value    %s    is    not    a    valid    enum    value    for    field    %s' % (value, self.name)))
    return EnumNamedValue(checked_value, name=self.reverse_enum.get(value))
