Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(variable sub): substitue variables from other variables #346

Merged
merged 4 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dothttp.conf.diagnostics": true,
"dothttp.conf.notebook.numofresponses": 0,
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
}
28 changes: 19 additions & 9 deletions dothttp/utils/property_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,11 @@ def get_updated_content(self, content, type="str"):
content = content.replace("{{" + text_to_replace + "}}", value)
return content

@staticmethod
def validate_n_gen(prop, cache: Dict[str, Property]):
def validate_n_gen(self, prop, cache: Dict[str, Property]):
p: Union[Property, None] = None
if "=" in prop:
key_values = prop.split("=")
if len(key_values) != 2:
prop_name = key_values[0]
raise HttpFileException(
message=f"Property `{prop_name}` should not contain multiple `=` signs"
)
key, value = key_values
# consider only first `=`
key, value = prop.split("=", 1)
# strip white space for keys
key = key.strip()

Expand All @@ -275,6 +269,22 @@ def validate_n_gen(prop, cache: Dict[str, Property]):
# like ranga=" ramprasad" --> we should replace with "
# ramprasad"
value = value[1:-1]
elif value and (value.startswith("p'") and value.endswith("'") or value.startswith('p"') and value.endswith('"')):
# lets substitute property with property
value = value[2:-1]
prop_handler = self
class PropertyResolver:
# hassle of creating class is to make it work with format_map
# instead of format which can be used with dict and can cause memory leak
def __getitem__(self, key):
if key in prop_handler.command_line_properties:
return prop_handler.command_line_properties[key]
if key in prop_handler.env_properties:
return prop_handler.env_properties[key]
if key in cache and isinstance(cache[key].value, str):
return cache[key].value
raise KeyError(key)
value = value.format_map(PropertyResolver())
match = PropertyProvider.get_random_match(value)
if match:
if key in cache:
Expand Down
Loading
Loading