Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interpolate argument to avoid resolving proxied values.
Browse files Browse the repository at this point in the history
The argument is already documented but not implemented yet.
Fixes joke2k#415
David-Wobrock committed Sep 5, 2023
1 parent fe59a81 commit dbaa23a
Showing 4 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is inspired by `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.

`v0.x.y`_ - Unreleased
-------------------------------
Added
+++++
- Added support for ``interpolate`` parameter
`#415 <https://github.com/joke2k/django-environ/pull/415>`_.

`v0.11.2`_ - 1-September-2023
-------------------------------
Fixed
2 changes: 1 addition & 1 deletion docs/tips.rst
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions environ/environ.py
Original file line number Diff line number Diff line change
@@ -189,10 +189,11 @@ class Env:
for s in ('', 's')]
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):
@@ -396,7 +397,7 @@ 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)

4 changes: 4 additions & 0 deletions tests/test_env.py
Original file line number Diff line number Diff line change
@@ -134,6 +134,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_dollar_sign(self):
assert self.env('DOLLAR_VAR') == 'SOME_VALUE$S3CR3TK3Y@HELLO'

0 comments on commit dbaa23a

Please sign in to comment.