Convert any value into a string value.

        Args:
            value (any): The value to coerce.

        Returns:
            str: The string representation of the value.
349838
def coerce(self, value):
        
        if isinstance(value, compat.basestring):

            return value

        return str(value)
642237
def to_python(self, value: Optional[str]) -> Optional[Any]:
        
        # https://docs.djangoproject.com/en/1.8/howto/custom-model-fields/
        # log.debug("to_python: {}, {}", value, type(value))
        if isinstance(value, datetime.datetime):
            return value
        if value is None:
            return value
        if value == '':
            return None
        return iso_string_to_python_datetime(value)
955070
def to_python(self, value):
        
        if isinstance(value, dict):
            return value

        if self.blank and not value:
            return None

        if isinstance(value, string_types):
            try:
                return json.loads(value)
            except Exception as e:
                raise ValidationError(str(e))

        return value
906498
def encode(self, value):
        
        e = self.evrs.get(value, None)
        if not e:
            log.error(str(value) + " not found as EVR. Cannot encode.")
            return None
        else:
            return super(EVRType, self).encode(e.code)
383828
def to_python(self, value):
        
        if value == "":
            return None

        try:
            if isinstance(value, six.string_types):
                return self.deserializer(value)
            elif isinstance(value, bytes):
                return self.deserializer(value.decode('utf8'))
        except ValueError:
            pass
        return value
1221240
def _float_or_str(value):
    
    # remove any surrounding quotes
    value = QUOTE_REGEX.sub('', value)
    try:  # attempt `float()` conversion
        return float(value)
    except ValueError:  # just return the input
        return value
644130
def as_string(value):
    
    if six.PY2:
        buffer_types = buffer, memoryview  # noqa: F821
    else:
        buffer_types = memoryview

    if value is None:
        return u''
    elif isinstance(value, buffer_types):
        return bytes(value).decode('utf8', 'ignore')
    elif isinstance(value, bytes):
        return value.decode('utf8', 'ignore')
    else:
        return six.text_type(value)
217597
def _cast_to_type(self, value):
        
        if isinstance(value, str) or value is None:
            return value
        return str(value)
302176
def coerce(self, value):
        """"""
        if self._coerce is not None:
            value = self._coerce(value)
        return value
915235
def encode(cls, value):
        
        try:
            coerced = int(value)
            if coerced + 0 == value:
                return repr(coerced)

        except (TypeError, ValueError):
            pass

        raise InvalidValue('not an int')
749494
def coerceType(self, ftype, value):
        
        if value is None:
            return None
        if ftype == 'string':
            return str(value)
        elif ftype == 'text':
            return str(value)
        elif ftype == 'int':
            try:
                v = int(value)
                return str(v)
            except Exception:
                return None
        elif ftype == 'float':
            try:
                v = float(value)
                return str(v)
            except Exception:
                return None
        elif ftype == 'date':
            try:
                v = datetime.datetime.strptime(value, '%b %d %Y %I:%M%p')
                return v.isoformat()
            except Exception:
                return None
        return str(value)
694703
def str_to_uuid(value):
    
    if isfunction(value):
        value = value()

    return UUID(value) if isinstance(value, string_types) else value
707503
def to_bool(self, value):
        

        try:
            value = value.lower()
        except:
            pass
        try:
            value = value.encode('utf-8')
        except:
            pass
        try:
            value = int(value)
        except:
            pass
        if value in ('true', 1):
            return True
        else:
            return False
298098
def format_value(self, value):
        
        if value == '' or value is None:
            return None
        return formats.localize_input(value, self.format)
1250686
def to_python(self, value):
        
        if isinstance(value, type(re.compile(''))):
            return value
        else:
            if value is None and self.null:
                return None
            else:
                try:
                    return self.get_compiled_regex(value)
                except:
                    raise ValidationError('Invalid regex {0}'.format(value))
641093
def to_string(self, value):
        
        self.enforce_type(value)
        if isinstance(value, dict) and None in value:
            value = value.copy()
            value['null'] = value[None]
            del value[None]
        return super(Dict, self).to_string(value)
612657
def to_unicode(value):
  
  if isinstance(value, str):
    return value.decode('utf-8')

  assert isinstance(value, unicode)
  return value