Transform val to a storable representation, returning a tuple of the flags, the length of the new value, and the new value itself.
169869
def _val_to_store_info(self, val, min_compress_len):
        
        flags = 0
        if isinstance(val, str):
            pass
        elif isinstance(val, int):
            flags |= Client._FLAG_INTEGER
            val = "%d" % val
            # force no attempt to compress this silly string.
            min_compress_len = 0
        elif isinstance(val, long):
            flags |= Client._FLAG_LONG
            val = "%d" % val
            # force no attempt to compress this silly string.
            min_compress_len = 0
        else:
            flags |= Client._FLAG_PICKLE
            file = StringIO()
            if self.picklerIsKeyword:
                pickler = self.pickler(file, protocol = self.pickleProtocol)
            else:
                pickler = self.pickler(file, self.pickleProtocol)
            if self.persistent_id:
                pickler.persistent_id = self.persistent_id
            pickler.dump(val)
            val = file.getvalue()

        lv = len(val)
        # We should try to compress if min_compress_len > 0 and we could
        # import zlib and this string is longer than our min threshold.
        if min_compress_len and _supports_compress and lv > min_compress_len:
            comp_val = compress(val)
            # Only retain the result if the compression result is smaller
            # than the original.
            if len(comp_val) < lv:
                flags |= Client._FLAG_COMPRESSED
                val = comp_val

        #  silently do not store if value length exceeds maximum
        if self.server_max_value_length != 0 and \
           len(val) > self.server_max_value_length: return(0)

        return (flags, len(val), val)
858834
def fmt_val(val, shorten=True):
    
    val = repr(val)
    max = 50
    if shorten:
        if len(val) > max:
            close = val[-1]
            val = val[0:max-4] + "..."
            if close in (">", "'", '"', ']', '}', ')'):
                val = val + close
    return val
324698
def new(cls, nsptagname, val):
        
        return OxmlElement(nsptagname, attrs={qn('w:val'): str(val)})
927585
def fromvalue(self, value, size=None, fmt='Q'):
        '''
        
        '''
        if size and value.bit_length() > size:
            raise TypeError('Value is too big for given size')
        self.frombytes(struct.pack(fmt, value))
        if size:
            if not isinstance(size, integer_types) or not size > 0:
                raise TypeError('Size must be greater than zero')
            if size > self.length():
                bitarray.extend(self, (size - self.length()) * [0])
            else:
                bitarray.__delitem__(self, slice(size, self.length()))
515192
function valueify(val) {
    return (
        val in bool ? bool[val] : (num.test(val) ? Number(val) : (val ? unescape(val) : true))
    );
}
278187
def encode(self, value):
        '''
        
        '''
        packed = pack(self.fmt, value)
        return Bits(bytes=packed)
503025
def repr_value(value):
    
    if isinstance(value, list) and len(value) > REPR_LIST_TRUNCATION:
        return "[{},...]".format(", ".join(map(repr, value[:REPR_LIST_TRUNCATION])))
    else:
        return repr(value)
1183601
def serialzeValueToTCL(self, val, do_eval=False) -> Tuple[str, str, bool]:
        
        return str(val), str(val), True
56183
def values_to_array(input_values):
    '''
    
    '''
    if type(input_values)==tuple:
        values = np.array(input_values).reshape(-1,1)
    elif type(input_values) == np.ndarray:
        values = np.atleast_2d(input_values)
    elif type(input_values)==int or type(input_values)==float or type(np.int64):
        values = np.atleast_2d(np.array(input_values))
    else:
        print('Type to transform not recognized')
    return values
1216132
def hex_from(val):
    
    if isinstance(val, integer_types):
        hex_str = '%x' % val
        if len(hex_str) % 2:
            hex_str = '0' + hex_str
        return hex_str

    return hexlify(val)
283516
def encode_value(value):
    # type: (bytes) -> bytes
    
    return struct.pack(">I{attr_len:d}s".format(attr_len=len(value)), len(value), value)
412867
def to_tuple(value, strict=True, force_int=True):
    
    if isinstance(value, int):
        seconds = value
        minutes, seconds = divmod(seconds, 60)
        hours, minutes = divmod(minutes, 60)
    elif isinstance(value, str):
        hours, minutes, seconds = _fix_tuple(
            _parse(value, strict)
        )
    elif isinstance(value, tuple):
        check_tuple(value, strict)
        hours, minutes, seconds = _fix_tuple(value)
    elif isinstance(value, timedelta):
        seconds = value.total_seconds()
        if force_int:
            seconds = int(round(seconds))
        minutes, seconds = divmod(seconds, 60)
        hours, minutes = divmod(minutes, 60)

    return (hours, minutes, seconds,)
210934
def val_mb(valstr: Union[int, str]) -> str:
    
    try:
        return "{:.3f}".format(int(valstr) / (1024 * 1024))
    except (TypeError, ValueError):
        return '?'
1052314
def map_val(dest, src, key, default=None, src_key=None):
    """"""
    if not src_key:
        src_key = key

    if src_key in src:
        dest[key] = src[src_key]
    else:
        if default is not None:
            dest[key] = default
686318
def encode_mv(vals):
    """'"""
    s = ""
    for val in vals:
        val = val.replace('$', '$$')
        if len(s) > 0:
            s += ';'
        s += '$' + val + '$'

    return s
440026
def _prepare_value(val, maxlen=50, notype=False):
    
    if val is None or val is True or val is False:
        return str(val)
    sval = repr(val)
    sval = sval.replace("\n", " ").replace("\t", " ").replace("`", "'")
    if len(sval) > maxlen:
        sval = sval[:maxlen - 4] + "..." + sval[-1]
    if notype:
        return sval
    else:
        tval = checker_for_type(type(val)).name()
        return "%s of type %s" % (sval, tval)
1345943
def _format_value(self, val):
        
        name = self.name + ":"
        if not self.multiline or "\n" not in val:
            val = u"{0} {1}".format(name.ljust(self._text_prefix_len), val)
        else:
            spacer = "\n" + " " * (self._text_prefix_len + 1)
            val = u"{0}{1}{2}".format(name, spacer, spacer.join(val.split("\n")))

        return val