-
Notifications
You must be signed in to change notification settings - Fork 684
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
Refactor build_cpe.py #9834
Refactor build_cpe.py #9834
Changes from all commits
dd8cf6b
5e986db
4249df2
0ec871f
f3c4736
8dd62f2
514120b
b782ca1
3a29721
b4233e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,6 +333,16 @@ def enum(*args): | |
return type('Enum', (), enums) | ||
|
||
|
||
def recurse_or_substitute_or_do_nothing( | ||
v, string_dict, ignored_keys=frozenset()): | ||
if isinstance(v, dict): | ||
return apply_formatting_on_dict_values(v, string_dict, ignored_keys) | ||
elif isinstance(v, str): | ||
return v.format(**string_dict) | ||
else: | ||
return v | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @evgenyz Where the frozenset should be after the refactoring to make it work as expected? Should it be in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preferably in both places, so the default argument to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say every place where |
||
|
||
def apply_formatting_on_dict_values(source_dict, string_dict, ignored_keys=frozenset()): | ||
""" | ||
Uses Python built-in string replacement. | ||
|
@@ -343,12 +353,8 @@ def apply_formatting_on_dict_values(source_dict, string_dict, ignored_keys=froze | |
new_dict = {} | ||
for k, v in source_dict.items(): | ||
if k not in ignored_keys: | ||
if isinstance(v, dict): | ||
new_dict[k] = apply_formatting_on_dict_values(v, string_dict, ignored_keys) | ||
elif isinstance(v, str): | ||
new_dict[k] = v.format(**string_dict) | ||
else: | ||
new_dict[k] = v | ||
new_dict[k] = recurse_or_substitute_or_do_nothing( | ||
v, string_dict, ignored_keys) | ||
else: | ||
new_dict[k] = v | ||
return new_dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By applying this change, the re module is no longer needed and does not need to be imported.