Renamed value variable in expand_value_from_context to _value to prevent common name clashes with attributes named 'value' in the context

This commit is contained in:
Fabio Manganiello 2019-01-12 22:43:01 +01:00
parent 3587fa7cb4
commit 2a52eb770b

View file

@ -112,7 +112,7 @@ class Request(Message):
@classmethod @classmethod
def expand_value_from_context(cls, value, **context): def expand_value_from_context(cls, _value, **context):
for (k, v) in context.items(): for (k, v) in context.items():
if isinstance(v, Message): if isinstance(v, Message):
v = json.loads(str(v)) v = json.loads(str(v))
@ -126,14 +126,14 @@ class Request(Message):
pass pass
parsed_value = '' parsed_value = ''
if not isinstance(value, str): if not isinstance(_value, str):
parsed_value = value parsed_value = _value
while value and isinstance(value, str): while _value and isinstance(_value, str):
m = re.match('([^\$]*)(\${\s*(.+?)\s*})(.*)', value) m = re.match('([^\$]*)(\${\s*(.+?)\s*})(.*)', _value)
if m and not m.group(1).endswith('\\'): if m and not m.group(1).endswith('\\'):
prefix = m.group(1); expr = m.group(2); prefix = m.group(1); expr = m.group(2);
inner_expr = m.group(3); value = m.group(4) inner_expr = m.group(3); _value = m.group(4)
try: try:
context_value = eval(inner_expr) context_value = eval(inner_expr)
@ -152,8 +152,8 @@ class Request(Message):
or isinstance(context_value, dict) or isinstance(context_value, dict)
else str(context_value)) else str(context_value))
else: else:
parsed_value += value parsed_value += _value
value = '' _value = ''
try: return json.loads(parsed_value) try: return json.loads(parsed_value)
except Exception as e: return parsed_value except Exception as e: return parsed_value