diff --git a/docs/tips.rst b/docs/tips.rst index 1915fac9..971a38d1 100644 --- a/docs/tips.rst +++ b/docs/tips.rst @@ -226,7 +226,7 @@ Proxy value =========== Values that being with a ``$`` may be interpolated. Pass ``interpolate=True`` to -``environ.Env()`` to enable this feature: +``environ.Env()`` to enable this feature (``True`` by default): .. code-block:: python diff --git a/environ/environ.py b/environ/environ.py index c3ae5f63..e42ac5e9 100644 --- a/environ/environ.py +++ b/environ/environ.py @@ -188,10 +188,11 @@ class Env: } CLOUDSQL = 'cloudsql' - def __init__(self, **scheme): + def __init__(self, interpolate=True, **scheme): self.smart_cast = True self.escape_proxy = False self.prefix = "" + self.interpolate = interpolate self.scheme = scheme def __call__(self, var, cast=None, default=NOTSET, parse_default=False): @@ -395,7 +396,11 @@ def get_value(self, var, cast=None, default=NOTSET, parse_default=False): # Resolve any proxied values prefix = b'$' if isinstance(value, bytes) else '$' escape = rb'\$' if isinstance(value, bytes) else r'\$' - if hasattr(value, 'startswith') and value.startswith(prefix): + if ( + self.interpolate + and hasattr(value, 'startswith') + and value.startswith(prefix) + ): value = value.lstrip(prefix) value = self.get_value(value, cast=cast, default=default) diff --git a/tests/test_env.py b/tests/test_env.py index 396c2123..e239b587 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -132,6 +132,10 @@ def test_bool_true(self, value, variable): def test_proxied_value(self): assert self.env('PROXIED_VAR') == 'bar' + def test_not_interpolated_proxied_value(self): + env = Env(interpolate=False) + assert env('PROXIED_VAR') == '$STR_VAR' + def test_escaped_dollar_sign(self): self.env.escape_proxy = True assert self.env('ESCAPED_VAR') == '$baz'