Set condition conkey to value val. Convert val to str if not
        None.

        conkey: str
            A valid condition key.

        val: str, int, float, None
            Can always be None. Can be number or string depending on conkey.
358040
def set_condition(self, conkey, val):
        

        if not any([conkey.startswith(c) for c in _COND_PREFIXES]):
            raise KeyError(conkey)

        if val in NONES:
            self.conditions[conkey] = None
        else:
            self.conditions[conkey] = str(val)
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)
534555
def set_float(val):
    
    out = None
    if not val in (None, ''):
        try:
            out = float(val)
        except ValueError:
            return None
        if numpy.isnan(out):
            out = default
    return out
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
512507
def safe_int(val, default=None):
    

    try:
        val = int(val)
    except (ValueError, TypeError):
        val = default

    return val
774854
def set_val(self, key:str, val:Any, bn_groups:bool=True)->Any:
        ""
        if is_tuple(val): val = [(v1,v2) for v1,v2 in zip(*val)]
        for v,pg1,pg2 in zip(val,self.opt.param_groups[::2],self.opt.param_groups[1::2]):
            pg1[key] = v
            if bn_groups: pg2[key] = v
        return val
723614
def valid_conkey(self, conkey):
        """"""

        for prefix in _COND_PREFIXES:
            trailing = conkey.lstrip(prefix)
            if trailing == '' and conkey:  # conkey is not empty
                return True
            try:
                int(trailing)
                return True
            except ValueError:
                pass

        return False
160928
def check_precondition(self, key, value):
        '''
        
        '''
        timeout = float(value)
        curr_time = self.get_current_time()
        if curr_time > timeout:
            return True
        return False
1204106
def Set(self, key, value):
        
        if not value == None: self.prefs[key] = value
        else:                 self.prefs.pop(key)

        self.Dump()
91213
def composeWord(key, value):
    
    mapping = {True: 'yes', False: 'no'}
    # this is necesary because 1 == True, 0 == False
    if type(value) == int:
        value = str(value)
    else:
        value = mapping.get(value, str(value))
    return '={}={}'.format(key, value)
951304
def conf(self, key=None, defval=None):
        ''''''
        if key is None:
            return self._ypconf
        val = self._ypconf.conf(key)
        return defval if val is None else val
1247422
function (val, condition, options) {
      var valid = [
          'date',       'time',      'utc-millisec',
          'regex',      'color',     'style',
          'phone',      'uri',       'email',
          'ip-address', 'ipv6',      'street-adress',
          'country',    'region',    'postal-code',
          'locality',   'date-time'
      ];
      if (valid.indexOf(val) === -1) {
        throw new(Error)({name:"ArgumentError"});
      }

      return this.define("format", val, condition, options);
    }
263690
def to_int(d, key, default_to_zero=False, default=None, required=True):
    
    value = d.get(key) or default
    if (value in ["", None]) and default_to_zero:
        return 0
    if value is None:
        if required:
            raise ParseError("Unable to read %s from %s" % (key, d))
    else:
        return int(value)
768206
def _check_valid_condition(self, get_params):
        
        try:
            variable = get_params(self.variable)
        except:  # noqa e722
            variable = None
        value = self.value

        # if None, return oppositely
        if variable is None:
            return not self.default

        # convert the value to a correct type
        if isinstance(variable, bool):
            value = bool(self.value)
        elif isinstance(variable, Number):
            try:
                value = int(self.value)
            except:  # noqa e722
                try:
                    value = float(self.value)
                except:  # noqa e722
                    # could not parse
                    return not self.default

        # compare and return the result
        if self.condition == "=":
            return (variable == value) == self.default
        elif self.condition == ">":
            return (variable > value) == self.default
        elif self.condition == "<":
            return (variable < value) == self.default
911277
def []=(key, val)
      supported_option?(key) || raise(UnsupportedOptionError, key.inspect)
      values[key] = val
    end
954409
def str_to_bool(val):
    

    if isinstance(val, bool):
        return val
    elif val.lower() == 'true':
        return True
    elif val.lower() == 'false':
        return False
    else:
        raise ValueError
1218364
def safe_int(val, allow_zero=True):
    
    try:
        ret = int(val)
    except ValueError:
        print("Sorry, '%s' is not a valid integer." % val)
        return False
    if not allow_zero and ret == 0:
        print("Please enter a non-zero integer.")
        return False
    return ret