def load(self, formatter=None): env_keys = self.keys + list(self.mapping.keys()) for key in [format_key(k) for k in env_keys]: env_value = os.environ.get(format_key(key)) if env_value is not None: if key in self.mapping: self[self.format(self.mapping[key], self.formatter)] = env_value else: self[self.format(key, self.formatter)] = env_value
def __init__(self, *keys, **mapping): super(Env, self).__init__() self.keys = [format_key(k) for k in keys] self.mapping = dict( (format_key(k), format_key(v)) for k, v in mapping.items())
def test_format_env_key_with_mixed_case(): assert format_key('abC 123') == 'ABC_123'
def test_format_env_key_with_trailing_spaces(): assert format_key(' abc 123 ') == 'ABC_123'
def test_format_env_key_with_upper_case(): assert format_key('ABC 123') == 'ABC_123'
def test_format_env_key_with_lower_case(): assert format_key('abc 123') == 'ABC_123'
def __init__(self, *keys, **mapping): super(Env, self).__init__() self.keys = [format_key(k) for k in keys] self.mapping = {format_key(k): format_key(v) for k, v in mapping.items()}