Convert value if needed.
517796
def to_python(self, value):
        """"""
        if isinstance(value, DirDescriptor):
            return value
        elif isinstance(value, str):
            return DirDescriptor(value)
        elif isinstance(value, dict):
            try:
                path = value['dir']
            except KeyError:
                raise ValidationError("dictionary must contain a 'dir' element")

            if not isinstance(path, str):
                raise ValidationError("field's dir element must be a string")

            size = value.get('size', None)
            if size is not None and not isinstance(size, int):
                raise ValidationError("field's size element must be an integer")

            total_size = value.get('total_size', None)
            if total_size is not None and not isinstance(total_size, int):
                raise ValidationError("field's total_size element must be an integer")

            refs = value.get('refs', None)
            if refs is not None and not isinstance(refs, list):
                # TODO: Validate that all refs are strings.
                raise ValidationError("field's refs element must be a list of strings")

            return DirDescriptor(
                path,
                size=size,
                total_size=total_size,
                refs=refs,
            )
        elif not isinstance(value, None):
            raise ValidationError("field must be a DirDescriptor, string or a dict")
418974
def to_python(self, value):
        ''''''
        if isinstance(value, Seconds):
            return value
        if value in self.empty_values:
            return None
        return self.parse_seconds(value)
1138968
@Override
    public Object convertValue(final String valueToConvert) {
        return Integer.valueOf(ParserUtils.stripNonLongChars(valueToConvert));
    }
510823
function convertValue(value, cast) {
  var val;
  if (value === null || value === undefined) {
    return value;
  }
  val = Buffer.isBuffer(value) ? value.toString('utf8') : value;
  if (cast !== false && typeof val === 'string') {
    try {
      return JSON.parse(val);
    } catch (e) {}
  }
  return val;
}
378851
def convert_value(v):
    
    if v and isinstance(v, six.string_types):
        v = v.strip()
        if (v.startswith('{') and v.endswith('}')) or (v.startswith('[') and v.endswith(']')):
            try:
                return json.loads(v)
            except Exception as e:
                logger.error(e)

    return v
1024416
def process_result_value(self, value, dialect):
        """"""
        if value is not None:
            value = simplejson.loads(value)
        return value
1033887
def _type_convert(self, value):
        
        if value is None:
            return value

        try:
            return datetime.datetime.strptime(value, '%Y-%m-%d %H:%M:%S')
        except ValueError:
            pass

        try:
            return int(value)
        except ValueError:
            pass

        try:
            return decimal.Decimal(value)
        except decimal.InvalidOperation:
            pass

        return value
235080
def convert_value(value)
      case value
      when true  then "true"
      when false then "false"
      when Hash  then convert_value(value.values)
      when Array then value.map(&:to_s)
      else value.to_s
      end
    end
919732
def _check_conversion(key, valid_dict):
    """"""
    if key not in valid_dict and key not in valid_dict.values():
        # Only show users the nice string values
        keys = [v for v in valid_dict.keys() if isinstance(v, string_types)]
        raise ValueError('value must be one of %s, not %s' % (keys, key))
    return valid_dict[key] if key in valid_dict else key
223162
def convert_frequency(value):
    """"""
    value = value.strip()
    suffix = value[-1].lower()
    if suffix in ('k', 'm'):
        value = int(value[:-1])
        if suffix == 'k':
            value *= 1000
        elif suffix == 'm':
            value *= 1000000
        return value
    else:
        return int(value)
748004
def get_prep_value(self, value):
        """"""

        if isinstance(value, LocalizedValue):
            prep_value = LocalizedValue()
            for k, v in value.__dict__.items():
                if v is None:
                    prep_value.set(k, '')
                else:
                    # Need to convert File objects provided via a form to
                    # unicode for database insertion
                    prep_value.set(k, six.text_type(v))
            return super().get_prep_value(prep_value)
        return super().get_prep_value(value)
149648
private BigDecimal convertValue(final Object value) {
		if (value == null) {
			return null;
		} else if (value instanceof BigDecimal) {
			return (BigDecimal) value;
		}

		// Try and convert "String" value
		String dataString = value.toString();
		if (Util.empty(dataString)) {
			return null;
		}

		try {
			return new BigDecimal(dataString);
		} catch (NumberFormatException ex) {
			throw new SystemException(
					"Could not convert data of type " + value.getClass() + " with String value "
					+ dataString + " to BigDecimal", ex);
		}
	}
478283
def process_result_value(self, value: Optional[str],
                             dialect: Dialect) -> List[str]:
        """"""
        retval = self._dbstr_to_strlist(value)
        return retval
610942
def to_python(self, value):
        """"""
        if value is None or value == '':
            return value
        if isinstance(value, base.Spec):
            return value
        return base.Spec(value)
1369823
def to_si(self, values, from_unit):
        """"""
        if from_unit == 'W/m2-K':
            return values, from_unit
        else:
            return self.to_unit(values, 'W/m2-K', from_unit), 'W/m2-K'
1183047
def format_value(self, value, padding):
        """"""

        # padding = padding - 1 if value < 0 and padding > 0 else padding
        # prefix = '-' if value < 0 else ''

        if padding:
            return "{:0{pad}d}".format(value, pad=padding)

        else:
            return str(value)
1256914
def substitute_values(text, values):
    """"""
    shift, final_text, shifts = 0, text, defaultdict(int)
    for value in values:
        first = value['old_span'][0] + shift
        second = value['old_span'][1] + shift
        new_s = value['new_surface']
        final_text = final_text[0:first] + new_s + final_text[second:]
        shift += len(new_s) - len(value['old_surface'])
        for char in range(first + 1, len(final_text)):
            shifts[char] = shift

    logging.debug(u'Text after numeric conversion: "%s"', final_text)

    return final_text, shifts