Cleans and returns the given value, or raises a ParameterNotValidError exception
977385
def clean(self, value):
        """"""

        if not isinstance(value, six.string_types):
            raise ParameterNotValidError

        try:
            source, value = value.split('://', 1)
        except ValueError:
            raise ParameterNotValidError

        if source == 'service':
            if '@' in value:
                value, timestamp = value.split('@', 1)

                try:
                    service_time = timestamp_to_date(int(timestamp))
                except ValueError:
                    raise ParameterNotValidError
            else:
                service_time = None

            if ':' in value:
                service_name, variable_name = value.split(':', 1)
            else:
                service_name = value
                variable_name = None

            try:
                self.service = Service.objects.get(name=service_name)
            except ObjectDoesNotExist:
                raise ParameterNotValidError("Service '{}' not found".format(service_name))

            if variable_name:
                try:
                    variable = self.service.variable_set.all().get(variable=variable_name)
                except ObjectDoesNotExist:
                    raise ParameterNotValidError("Variable '{}' not found".format(variable_name))

                if service_time is not None:
                    time_index = best_fit(variable.time_stops, service_time)
                else:
                    time_index = None

                data = self.get_grid_for_variable(variable, time_index=time_index)
                return Raster(data, variable.full_extent, 1, 0, self.is_y_increasing(variable))
            else:
                return self.dataset
        else:
            raise ParameterNotValidError('Invalid source: {}'.format(source))
678591
def wrap_value(value, include_empty=False):
    

    if value is None:
        return [None] if include_empty else []
    elif hasattr(value, '__len__') and len(value) == 0:
        return [value] if include_empty else []
    elif isinstance(value, _wrap_types):
        return [value]
    elif not hasattr(value, '__iter__'):
        return [value]

    return value if include_empty else filter_empty(value, [])
714921
def clean(self, value):
        """"""
        if (
            self.base_type is not None and
            value is not None and
            not isinstance(value, self.base_type)
        ):
            if isinstance(self.base_type, tuple):
                allowed_types = [typ.__name__ for typ in self.base_type]
                allowed_types_text = ' or '.join(allowed_types)
            else:
                allowed_types_text = self.base_type.__name__
            err_msg = 'Value must be of %s type.' % allowed_types_text
            raise ValidationError(err_msg)

        if not self.has_value(value):
            if self.default is not None:
                raise StopValidation(self.default)

            if self.required:
                raise ValidationError('This field is required.')
            else:
                raise StopValidation(self.blank_value)

        return value
743672
def str(self, value, tolerant=False, limit=1000, seen=frozenset()):
        """"""
        if value is None:
            if tolerant:
                return ""

            raise ValueError("value is None")

        if isinstance(value, (bool, numbers.Number, basestring)):
            return str(value)

        if not isinstance(value, collections.Iterable):
            if not tolerant:
                raise ValueError("unknown value type")

            try:
                name = value.name
            except AttributeError:
                try:
                    name = value.__name__
                except AttributeError:
                    try:
                        name = value.__class__.__name__
                    except AttributeError:
                        return "<?>"

            return "<%s>" % (name,)

        is_mapping = isinstance(value, collections.Mapping)

        if not seen:
            wrap = "%s"
        elif is_mapping:
            wrap = "{%s}"
        else:
            wrap = "[%s]"

        id_ = id(value)
        if id_ in seen:
            if tolerant:
                return wrap % ("...",)
            raise ValueError("recursive representation")
        seen = seen.union((id_,))

        if is_mapping:
            items = [(self.str(n, tolerant=tolerant, limit=limit, seen=seen),
                      self.str(v, tolerant=tolerant, limit=limit, seen=seen))
                     for n, v in value.items()]
            items.sort()
            items = ("%s=%s" for n, v in items)
        else:
            it = iter(value)
            items = [self.str(item, tolerant=tolerant, limit=limit, seen=seen)
                     for item in itertools.islice(
                         it,
                         len(value)
                         if isinstance(value, collections.Sized)
                         else limit)]
            items.sort()
            try:
                next(it)
            except StopIteration:
                pass
            else:
                if not tolerant:
                    raise ValueError("iterable too long")
                items.append("...")

        return wrap % (", ".join(items),)
1121130
def clean(self, value):
        """"""

        for parameter_obj in self.types:
            try:
                return parameter_obj.clean(value)
            except ParameterNotValidError:
                continue

        raise ParameterNotValidError
1253202
def clean(self, value):
        
        super_value = super(RichTextField, self).clean(value)

        if super_value in fields.EMPTY_VALUES:
            if self.instance:
                obj_id = self.get_instance_id(self.instance)
                if not obj_id:
                    SourceText.objects.filter(content_type=self.ct, object_id=obj_id, field=self.field_name, processor=self.processor).delete()
                else:
                    SourceText.objects.filter(content_type=self.ct, object_id=obj_id, field=self.field_name).delete()
            self.validate_rendered('')
            return ''

        text = smart_unicode(value)
        if self.instance:
            obj_id = self.get_instance_id(self.instance)
            try:
                if not obj_id:
                    src_text = SourceText(content_type=self.ct, object_id=obj_id, field=self.field_name, processor=self.processor)
                else:
                    src_text = SourceText.objects.get(content_type=self.ct, object_id=obj_id, field=self.field_name)
                assert src_text.processor == self.processor
            except SourceText.DoesNotExist:
                src_text = SourceText(content_type=self.ct, object_id=obj_id, field=self.field_name, processor=self.processor)
            src_text.content = text
            try:
                rendered = src_text.render()
            except ProcessorError, e:
                raise ValidationError(self.error_messages['syntax_error'])
        else:
            # in case of adding new model, instance is not set
            self.instance = src_text = SourceText(
                content_type=self.ct,
                field=self.field_name,
                content=text,
                processor=self.processor
            )
            try:
                rendered = src_text.render()
            except Exception, err:
                raise ValidationError(self.error_messages['syntax_error'])

        self.validate_rendered(rendered)

        if not hasattr(self.model, RICH_FIELDS_SET):
            setattr(self.model, RICH_FIELDS_SET, set())
        getattr(self.model, RICH_FIELDS_SET).add(self.field_name)

        # register the listener that saves the SourceText
        #listener = self.post_save_listener(src_text)
        signals.post_save.connect(receiver=self.post_save_listener, sender=self.model)

        # wrap the text so that we can store the src_text on it
        rendered = UnicodeWrapper(rendered)
        setattr(rendered, self.src_text_attr, src_text)

        return rendered
359866
def convert(self, value, param, ctx):
        
        value = super(PositiveInt, self).convert(value, param, ctx)
        if value < 0:
            self.fail('%s is not positive' % value, param, ctx)
        if not self.allow_zero and not value:
            self.fail('%s is not greater than 0' % value, param, ctx)
        return value
536149
def clean_int(v):
    """"""

    if v is None or not str(v).strip():
        return None

    return int(str(v).replace(',', ''))
1027937
def _clean_params(self, params):
        
        clean_params = {}
        for key, value in params.iteritems():
            if value is not None:
                clean_params[key] = value

        return clean_params
846049
def _convert_value(value):
    """"""
    try:
        return restore(ast.literal_eval(value))
    except (ValueError, SyntaxError):
        if SETTINGS.COMMAND_LINE.STRICT_PARSING:
            raise
        # use as string if nothing else worked
        return value
671355
def no_empty_value(func):
    """"""
    @wraps(func)
    def wrapper(value):
        if not value:
            raise Exception("Empty value not allowed")
        return func(value)
    return wrapper
103318
private Object processParam(TemplateParam<?, ?, ?> param, Map<String, Object> params, Template<?> template) {
		Object value = fetchParamValue(param, params, param.getFetcher());
		value = convertParamValue(value, param.getType(), param.getConverter());
		validateParamValue(value, param.getValidator());
		return value;
	}
1124722
def clean(self, py_value):
        
        try:
            import bleach
            return bleach.clean(py_value, **self.__bleachOptions)
        except ImportError:
            warnings.warn('Unable to clean string column without webhelpers installed.')
            return py_value
796251
public static void validateStringValue(String value) throws ParameterException {
		Validate.notNull(value);
		Validate.notEmpty(value);
	}
1185496
def _normalize(value):
        
        if hasattr(value, 'value'):
            value = value.value
        if value is not None:
            value = long(value)
        return value
1371312
def clean(self, value):
		

		# If the value is None and it's optional, return as is
		if value is None and self._optional:
			return None

		# If the value is not a dict
		if not isinstance(value, dict):
			raise ValueError('value')

		# Recurse and return it
		return {str(self._key.clean(k)):self._node.clean(v) for k,v in iteritems(value)}
1329213
def get_prep_value(self, value):
        ""
        value = self.get_clean_value(value)
        if self.multiple:
            if value:
                value = ",".join(value)
            else:
                value = ""
        return super(CharField, self).get_prep_value(value)