Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions decouple.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ def strtobool(value):
raise ValueError("Invalid truth value: " + value)


def _strip_quotes(value):
if len(value) >= 2 and ((value[0] == "'" and value[-1] == "'") or (value[0] == '"' and value[-1] == '"')):
return value[1:-1]
else:
return value


class UndefinedValueError(Exception):
pass

Expand Down Expand Up @@ -84,7 +91,7 @@ def get(self, option, default=undefined, cast=undefined):

# We can't avoid __contains__ because value may be empty.
if option in os.environ:
value = os.environ[option]
value = _strip_quotes(os.environ[option])
elif option in self.repository:
value = self.repository[option]
else:
Expand Down Expand Up @@ -155,9 +162,7 @@ def __init__(self, source, encoding=DEFAULT_ENCODING):
k, v = line.split('=', 1)
k = k.strip()
v = v.strip()
if len(v) >= 2 and ((v[0] == "'" and v[-1] == "'") or (v[0] == '"' and v[-1] == '"')):
v = v[1:-1]
self.data[k] = v
self.data[k] = _strip_quotes(v)

def __contains__(self, key):
return key in os.environ or key in self.data
Expand Down