Given a :class:`.fields.Field` and a value, ensure that the value matches the given type, otherwise
        attempt to convert it.

        :param value: field value.
        :param field: :class:`.fields.Field` instance.
        :return: Result value.
357774
def convert_value(value, field):
        
        clz = field.field_type

        if clz is Boolean:
            if not isinstance(value, bool):
                return bool(value)

        elif clz is Date:
            if not isinstance(value, str):
                value = str(value)
            return parser.parse(value)

        elif clz is Number:
            if not isinstance(value, int):
                return int(value)

        elif clz is Object:
            if not isinstance(value, dict):
                return ast.literal_eval(value)

        elif clz is Text or clz is Symbol:
            if not isinstance(value, str):
                return str(value)

        elif clz is List or clz is MultipleAssets or clz is MultipleEntries:
            if not isinstance(value, list):
                return [value]

        # No need to convert :class:`.fields.Link` types as the expected value
        # should be of type :class:`.resources.ResourceLink` for links.

        return value
401611
def wrap(self, value):
        ''' 
        '''
        self.validate_wrap(value)
        ret = []
        for field, value in izip(self.types, value):
            ret.append(field.wrap(value))
        return ret
581441
def convert_field(self, value, conversion):
        """"""
        if isinstance(value, MissingField):
            if conversion is not None:
                value.conversion = conversion
            return value

        return super(FormatterWrapper, self).convert_field(value, conversion)
345122
def value(self, value):
        
        try:
            struct.pack('>' + conf.TYPE_CHAR, value)
        except struct.error:
            raise IllegalDataValueError

        self._value = value
30443
def check_type(self, value):
    

    if self.null and value is None:
      return
    if self.type is not None and not isinstance(value, self.type):
      msg = '{0!r} expected type {1}'
      raise TypeError(msg.format(self.full_name, self.type.__name__))
1070325
def is_valid_value(value, type):
    # type: (Any, Any) -> List
    """"""
    if isinstance(type, GraphQLNonNull):
        of_type = type.of_type
        if value is None:
            return [u'Expected "{}", found null.'.format(type)]

        return is_valid_value(value, of_type)

    if value is None:
        return _empty_list

    if isinstance(type, GraphQLList):
        item_type = type.of_type
        if not isinstance(value, string_types) and isinstance(value, Iterable):
            errors = []
            for i, item in enumerate(value):
                item_errors = is_valid_value(item, item_type)
                for error in item_errors:
                    errors.append(u"In element #{}: {}".format(i, error))

            return errors

        else:
            return is_valid_value(value, item_type)

    if isinstance(type, GraphQLInputObjectType):
        if not isinstance(value, Mapping):
            return [u'Expected "{}", found not an object.'.format(type)]

        fields = type.fields
        errors = []

        for provided_field in sorted(value.keys()):
            if provided_field not in fields:
                errors.append(u'In field "{}": Unknown field.'.format(provided_field))

        for field_name, field in fields.items():
            subfield_errors = is_valid_value(value.get(field_name), field.type)
            errors.extend(
                u'In field "{}": {}'.format(field_name, e) for e in subfield_errors
            )

        return errors

    assert isinstance(type, (GraphQLScalarType, GraphQLEnumType)), "Must be input type"

    # Scalar/Enum input checks to ensure the type can parse the value to
    # a non-null value.
    parse_result = type.parse_value(value)
    if parse_result is None:
        return [u'Expected type "{}", found {}.'.format(type, json.dumps(value))]

    return _empty_list
1182002
def type(self, value):
        
        if value not in list(defines.Types.values()):
            raise AttributeError
        self._type = value
46567
def decode(self, value):
        
        # Use the default value unless the field accepts None types
        has_null_encoder = bool(encode_decode_null in self._decoders)

        if value is None and self._default is not None and not has_null_encoder:
            value = self._default

        for decoder in self._decoders:
            try:
                return decoder(value)
            except ValueError as ex:
                pass

        raise ValueError('Value \'{}\' is invalid. {}'
                         .format(value, ex.message))
936972
def _convert_property_type(value):
        
        if value in ('true', 'True'):
            return True
        elif value in ('false', 'False'):
            return False
        elif str(value).startswith('{') and str(value).endswith('}'):
            return ast.literal_eval(value)
        else:
            try:
                return int(value)
            except ValueError:
                return value
829784
def type(self, value):
        

        self._type = None
        if value is None:
            return

        value = value.upper()
        if value in MOC_TYPES:
            self._type = value
        else:
            raise ValueError('MOC type must be one of ' + ', '.join(MOC_TYPES))
878606
def validate_value(self, value):
        
        field = self.instance.preference.setup_field()
        value = field.to_python(value)
        field.validate(value)
        field.run_validators(value)
        return value
713719
def _ValidateValue(value, type_check):
  """"""
  if inspect.isclass(type_check):
    return isinstance(value, type_check)
  if isinstance(type_check, tuple):
    return _ValidateTuple(value, type_check)
  elif callable(type_check):
    return type_check(value)
  else:
    raise TypeError("Invalid type check '%s'" % repr(type_check))
976099
def _value_decode(cls, member, value):
        
        if value is None:
            return None
        try:
            field_validator = cls.fields[member]
        except KeyError:
            return cls.valueparse.decode(value)

        return field_validator.decode(value)
506377
def constraint_from_type(cls, value):
        
        if value is None:
            return None
        value_type = type(value)
        if value_type in (str, int, bool):
            return value_type
        raise ParameterError('Parameter type cannot be %s' % value_type)
426499
def value_type(value):
    
    try:
        keys = list(value.keys())
    except AttributeError:
        return "simple"
    if keys in [["lookup"], ["re_lookup"], ["interval"]]:
        return keys[0]
    raise ValueError("Type of `value` could not be determined")
709283
def decode_field(self, field, value):
        
        for decoder in _GetFieldCodecs(field, 'decoder'):
            result = decoder(field, value)
            value = result.value
            if result.complete:
                return value
        if isinstance(field, messages.MessageField):
            field_value = self.decode_message(
                field.message_type, json.dumps(value))
        elif isinstance(field, messages.EnumField):
            value = GetCustomJsonEnumMapping(
                field.type, json_name=value) or value
            try:
                field_value = super(
                    _ProtoJsonApiTools, self).decode_field(field, value)
            except messages.DecodeError:
                if not isinstance(value, six.string_types):
                    raise
                field_value = None
        else:
            field_value = super(
                _ProtoJsonApiTools, self).decode_field(field, value)
        return field_value
475226
def validateField(cls, fieldName, value) :
        
        try :
            valValue = Collection.validateField(fieldName, value)
        except SchemaViolation as e:
            if fieldName == "_from" or fieldName == "_to" :
                return True
            else :
                raise e
        return valValue