From 58e8aef2c96848b37bb1860f1d56b099c3b27a2a Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Wed, 24 Aug 2022 11:36:07 -0400 Subject: [PATCH] [7] fix string casting --- VERSION | 2 +- modules/meta.py | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index d296255f..1fc8b02b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.3-develop6 +1.17.3-develop7 diff --git a/modules/meta.py b/modules/meta.py index 523f99c3..4461b207 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -165,13 +165,16 @@ class DataFile: for key, value in variables.copy().items(): variables[f"{key}_encoded"] = requests.utils.quote(str(value)) - def replace_var(input_item, search_dict): - return_item = str(input_item) - for rk, rv in search_dict.items(): - if f"<<{rk}>>" == return_item: - return_item = rv - if f"<<{rk}>>" in return_item: - return_item = return_item.replace(f"<<{rk}>>", str(rv)) + def replace_var(input_item, search_dicts): + if not isinstance(search_dicts, list): + search_dicts = [search_dicts] + return_item = input_item + for search_dict in search_dicts: + for rk, rv in search_dict.items(): + if f"<<{rk}>>" == str(return_item): + return_item = rv + if f"<<{rk}>>" in str(return_item): + return_item = str(return_item).replace(f"<<{rk}>>", str(rv)) return return_item ini_default = {} @@ -213,7 +216,7 @@ class DataFile: logger.debug(f"Conditional: {con_key}") if not isinstance(con_value, dict): raise Failed(f"{self.data_type} Error: template sub-attribute conditionals is not a dictionary") - final_key = replace_var(replace_var(con_key, variables), default) + final_key = replace_var(con_key, [variables, default]) if final_key != con_key: logger.debug(f"Variable: {final_key}") if final_key in variables: @@ -235,8 +238,8 @@ class DataFile: for var_key, var_value in condition.items(): if var_key == "value": continue - var_key = replace_var(replace_var(var_key, variables), default) - var_value = replace_var(replace_var(var_value, variables), default) + var_key = replace_var(var_key, [variables, default]) + var_value = replace_var(var_value, [variables, default]) if var_key in variables: if (isinstance(var_value, list) and variables[var_key] not in var_value) or \ (not isinstance(var_value, list) and variables[var_key] != var_value):