Robot Framework
robotenv.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import os
17 
18 from .encoding import system_decode as decode, system_encode as encode
19 
20 
21 def get_env_var(name, default=None):
22  try:
23  value = os.environ[encode(name)]
24  except KeyError:
25  return default
26  else:
27  return decode(value)
28 
29 
30 def set_env_var(name, value):
31  os.environ[encode(name)] = encode(value)
32 
33 
34 def del_env_var(name):
35  value = get_env_var(name)
36  if value is not None:
37  del os.environ[encode(name)]
38  return value
39 
40 
41 def get_env_vars(upper=os.sep != '/'):
42  # by default, name is upper-cased on Windows regardless interpreter
43  return dict((name if not upper else name.upper(), get_env_var(name))
44  for name in (decode(name) for name in os.environ))
def get_env_var(name, default=None)
Definition: robotenv.py:21
def set_env_var(name, value)
Definition: robotenv.py:30
def get_env_vars(upper=os.sep !='/')
Definition: robotenv.py:41
def del_env_var(name)
Definition: robotenv.py:34