Convert internal value to machine value
335960
def i2m(self, pkt, x):
        """"""
        if x is None:
            x = 0
        elif isinstance(x, str):
            return bytes_encode(x)
        return x
507476
def value_to_python(self, value):
        
        if not isinstance(value, bytes):
            raise tldap.exceptions.ValidationError("should be bytes")
        if value is None:
            return value
        try:
            return int(value)
        except (TypeError, ValueError):
            raise tldap.exceptions.ValidationError("is invalid integer")
439032
def value(self, raw_value):
        """"""
        try:
            return base64.b64decode(bytes(raw_value, 'utf-8')).decode('utf-8')
        except binascii.Error as err:
            raise ValueError(str(err))
929925
def from_size(value):
    '''
    
    '''
    match_size = re_zfs_size.match(str(value))
    if match_size:
        v_unit = match_size.group(2).upper()[0]
        v_size = float(match_size.group(1))
        v_multiplier = math.pow(1024, zfs_size.index(v_unit) + 1)
        value = v_size * v_multiplier
        if int(value) == value:
            value = int(value)
    elif value is not None:
        value = str(value)

    return from_numeric(value)
420516
def convert(self, value):
        
        if self._type is str:
            return str(value)
        elif self._type is int:
            try:
                return int(value)
            except (UnicodeError, ValueError):
                raise WorkflowArgumentError('Cannot convert {} to int'.format(value))
        elif self._type is float:
            try:
                return float(value)
            except (UnicodeError, ValueError):
                raise WorkflowArgumentError('Cannot convert {} to float'.format(value))
        elif self._type is bool:
            if isinstance(value, bool):
                return bool(value)
            value = value.lower()
            if value in ('true', '1', 'yes', 'y'):
                return True
            elif value in ('false', '0', 'no', 'n'):
                return False
            raise WorkflowArgumentError('Cannot convert {} to bool'.format(value))
        else:
            return value
366537
def from_raw(self, rval: RawScalar, jptr: JSONPointer = "") -> ScalarValue:
        """"""
        res = self.type.from_raw(rval)
        if res is None:
            raise RawTypeError(jptr, self.type.yang_type() + " value")
        return res
634988
function parseTransitionValue(values) {
  if (typeof values === 'string') values = values.trim().split(/\s*,\s*/g);
  var ret = [];

  for (var i = 0; i < values.length; i++) {
    var value = values[i].toString();

    if (value === 'initial') {
      value = 0;
    } else if (/ms$/.test(value)) {
      value = parseFloat(value) / 1000;
    } else {
      value = parseFloat(value);
    }

    ret.push(value);
  }

  return ret;
}
905378
def to_internal_value(self, data):
        
        data = smart_text(data).strip()
        if len(data) > self.MAX_STRING_LENGTH:
            self.fail('max_string_length')

        try:
            value = decimal.Decimal(data)
        except decimal.DecimalException:
            self.fail('invalid')

        # Check for NaN. It is the only value that isn't equal to itself,
        # so we can use this to identify NaN values.
        if value != value:
            self.fail('invalid')

        # Check for infinity and negative infinity.
        if value in (decimal.Decimal('Inf'), decimal.Decimal('-Inf')):
            self.fail('invalid')

        return self.validate_precision(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),)
269283
def convert_value(self, value):
        """"""
        if isinstance(value, str):
            value = value.replace(self.separator, '')
            if self.decimal_point not in value:
                return int(value)
            else:
                return float(value.replace(self.decimal_point, '.'))
        elif self.int_to_float:
            return float(value)
        else:
            return value
140638
def to_internal_value(self, data):
        
        if not data:
            return None
        request = self._get_request()
        user = request.user
        try:
            obj = core_utils.instance_from_url(data, user=user)
            model = obj.__class__
        except ValueError:
            raise serializers.ValidationError(_('URL is invalid: %s.') % data)
        except (Resolver404, AttributeError, MultipleObjectsReturned, ObjectDoesNotExist):
            raise serializers.ValidationError(_("Can't restore object from url: %s") % data)
        if model not in self.related_models:
            raise serializers.ValidationError(_('%s object does not support such relationship.') % six.text_type(obj))
        return obj
630761
def _convert_localized_value(value: LocalizedValue) -> LocalizedIntegerValue:
        """"""

        integer_values = {}
        for lang_code, _ in settings.LANGUAGES:
            local_value = value.get(lang_code, None)
            if local_value is None or local_value.strip() == '':
                local_value = None

            try:
                integer_values[lang_code] = int(local_value)
            except (ValueError, TypeError):
                integer_values[lang_code] = None

        return LocalizedIntegerValue(integer_values)
1362333
def convert_machine_list_value(name: str, value: str) -> \
        Union[datetime.datetime, str, int]:
    '''
    '''
    if name == 'modify':
        return convert_machine_list_time_val(value)
    elif name == 'size':
        return int(value)
    else:
        return value
1173736
def convert(self, value, fromunits, tounits):
        ''''''
        if fromunits == tounits:
            return value
        if (fromunits,tounits) in self.unitmap:
            return value * self.unitmap[(fromunits,tounits)]
        if (tounits,fromunits) in self.unitmap:
            return value / self.unitmap[(tounits,fromunits)]
        raise fgFDMError("unknown unit mapping (%s,%s)" % (fromunits, tounits))
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
1299804
def to_internal_value(self, data):
        """"""
        # model = get_user_model()
        model = self.Meta.model

        if "id" in data:
            author = model.objects.get(id=data["id"])
        else:
            if "username" not in data:
                raise ValidationError("Authors must include an ID or a username.")
            username = data["username"]
            author = model.objects.get(username=username)
        return author
600003
def convert(cls, value, from_unit, to_unit):
        
        value_ms = value * cls.UNITS_IN_MILLISECONDS[from_unit]
        return value_ms / cls.UNITS_IN_MILLISECONDS[to_unit]