Get environment variable or provide default.

    Args:
        var (str): environment variable to search for
        default (optional(str)): default to return
545857
def env_or_default(var, default=None):
    
    if var in os.environ:
        return os.environ[var]
    return default
219258
def get_flag(env, var, fallback, expected=True, warn=True):
    """"""
    val = env.config_var(var)
    if val is None:
        if warn:
            warnings.warn(
                "Config variable '{0}' is unset, Python ABI tag may "
                "be incorrect".format(var),
                RuntimeWarning,
                2,
            )
        return fallback()
    return val == expected
803659
def get_env_value(obj, attribute):
    
    varname = get_env_key(obj, attribute)
    var = os.environ.get(varname)
    if not var:
        raise ValueError("%s must be set in your environment." % varname)

    return var
973179
def _check_environ(variable, value):
    """"""
    if is_not_none(value):
        return value
    else:
        value = os.environ.get(variable)
        if is_none(value):
            stop(''.join([variable,
                          """ not supplied and no entry in environmental
                           variables"""]))
        else:
            return value
110024
def search_url(self, var=DEFAULT_SEARCH_ENV, default=NOTSET, engine=None):
        
        return self.search_url_config(self.url(var, default=default), engine=engine)
1194693
def resolve(self, _):
        
        if self.default_value == DUMMY_VALUE:
            if self.name in os.environ:
                return os.environ[self.name]
            else:
                raise VelException(f"Undefined environment variable: {self.name}")
        else:
            return os.environ.get(self.name, self.default_value)
104523
def config(self, name, suffix):
        ""
        var = '%s_%s' % (name, suffix)
        var = var.upper().replace('-', '_')
        if var in self._config:
            return self._config[var]
        return os.environ[var]
943833
def get_setting(self, key, default):
        
        gkey = "ensime_{}".format(key)
        return self._vim.vars.get(gkey, default)
894966
def _load_environment_vars(self):
        # type: () -> None
        
        self._config[kinds.ENV_VAR].update(
            self._normalized_keys(":env:", self._get_environ_vars())
        )
10774
def getenv(option, default=undefined, cast=undefined):
    

    # We can't avoid __contains__ because value may be empty.
    if option in os.environ:
        value = os.environ[option]
    else:
        if isinstance(default, Undefined):
            raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))

        value = default

    if isinstance(cast, Undefined):
        return value

    if cast is bool:
        value = _cast_boolean(value)
    elif cast is list:
        value = [x for x in value.split(',') if x]
    else:
        value = cast(value)

    return value
199438
def set_env_var(key: str, value: str):
        
        elib_run.run(f'appveyor SetVariable -Name {key} -Value {value}')
        AV.info('Env', f'set "{key}" -> "{value}"')
955910
def _replace_envvar(s, _):
    """"""
    e = s.split(":")
    if len(e) > 3 or len(e) == 1 or e[0] != "env":
        raise ValueError()
    elif len(e) == 2:
        # Note: this can/should raise a KeyError (according to spec).
        return os.environ[e[1]]
    else:  # len(e) == 3
        return os.environ.get(e[1], e[2])
1362606
def inject_environment_variables(self, d):
        

        if not d:
            return d
        if isinstance(d, six.string_types):
            return os.path.expandvars(d)
        for k, v in d.items():
            if isinstance(v, six.string_types):
                d[k] = os.path.expandvars(v)
            elif isinstance(v, dict):
                d[k] = self.inject_environment_variables(v)
            elif isinstance(v, list):
                d[k] = [self.inject_environment_variables(e) for e in v]

        return d
74604
def set_environment_variable(self, key, val):
        
        if self.get_environment_variable(key) in [None, val]:
            self.__dict__['environment_variables'][key] = val
        else:
            raise Contradiction("Could not set environment variable %s" % (key))
209604
def _get_exe(prog):
        ''''''
        if prog in prog_to_env_var:
            env_var = prog_to_env_var[prog]
            if env_var in os.environ:
                return os.environ[env_var]

        return prog_to_default[prog]
194911
def getenv_int(key, default=0):
    
    try:
        return int(os.environ.get(key, str(default)))
    except ValueError:
        return default
812365
public String lookupVariableDefaultValue(String variableName) {
        ConfigVariable cv = configVariables.get(variableName);
        return cv == null ? null : cv.getDefaultValue();
    }