def clean(self, value):
if (<EOL>self.base_type is not None and<EOL>value is not None and<EOL>not isinstance(value, self.base_type)<EOL>):<EOL><INDENT>if isinstance(self.base_type, tuple):<EOL><INDENT>allowed_types = [typ.__name__ for typ in self.base_type]<EOL>allowed_types_text = '<STR_LIT>'.join(allowed_types)<EOL><DEDENT>else:<EOL><INDENT>allowed_types_text = self.base_type.__name__<EOL><DEDENT>err_msg = '<STR_LIT>' % allowed_types_text<EOL>raise ValidationError(err_msg)<EOL><DEDENT>if not self.has_value(value):<EOL><INDENT>if self.default is not None:<EOL><INDENT>raise StopValidation(self.default)<EOL><DEDENT>if self.required:<EOL><INDENT>raise ValidationError('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>raise StopValidation(self.blank_value)<EOL><DEDENT><DEDENT>return value<EOL>
Take a dirty value and clean it.